forked from InteractiveAdvertisingBureau/CCPA-reference-code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
259 lines (248 loc) · 9.78 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
}
/* Split window */
.split {
height: 100%;
width: 20%;
position: fixed;
z-index: 1;
top: 0;
overflow-x: hidden;
padding-top: 20px;
}
.left {
left: 0;
width: 80%;
background-color: #d7dbd8;
}
.right {
right: 0;
background-color: #6275e0;
}
.centered {
position: absolute;
top: 40%;
left: 50%;
transform: translate(-50%, -50%);
text-align: left;
}
.centered img {
width: 150px;
}
/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 10%; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
/* Modal Content */
.modal-content {
background-color: #fefefe;
margin: auto;
padding: 20px;
border: 1px solid #888;
width: 40%;
}
/* The Close Button */
.close {
color: #aaaaaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
.button {
border-style: groove;
text-align: center;
text-decoration: none;
padding: 5px 15px;
justify-content: center;
cursor: default;
}
</style>
<meta charset="UTF-8">
<title>IAB Tech Lab U.S. Privacy API Reference Implementation</title>
<script src="./uspapi.js"></script>
</head>
<body>
<p id="demo"></p>
<script>
// global const
const EXDAYS = 30;
const USPSTR_NN = "1NN";
const USPSTR_YN = "1YN";
const USPSTR_YY = "1YY";
const USPSTR_YYN = "1YYN";
const USPSTR_NYN = "1NYN";
const USPSTR_NA = "1---";
const YES = 'Y';
const NO = 'N';
</script>
<!-- implementation for the content split frame -->
<div class="split left">
<div class="centered">
<h3>Nova diei</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<br>
<hr>
<br>
<p><center>
<a href="javascript:showModal();">Do not sell my data</a>
<a href="../your.html">License Agreement</a>
<br>
<br>
<p><font size=2>IAB Tech Lab U.S. Privacy API Reference Implementation</font></p>
</p>
</div>
</div>
<div class="split right">
<div class="centered img" id="split2">
<script>
/* dummy execAdTag function, for illustration only */
function execAdTag() {
let img = document.createElement("IMG");
img.src="https://cdn.pixabay.com/photo/2019/02/19/19/45/thumbs-up-4007573_960_720.png";
document.getElementById("split2").appendChild(img);
}
window.__uspapi("getUSPData", 1, function(consent, success) {
if ( success
&& consent.uspString.toUpperCase() !== USPSTR_YYN
&& consent.uspString.toUpperCase() !== USPSTR_NYN) {
if (consent.uspString.toUpperCase()[2] === YES)
document.getElementById("split2").innerHTML = "I am cool with the ad but don't use my data for other purposes.";
execAdTag();
} else {
/* string is null we decided to still show the ad */
if (!consent.uspString)
execAdTag();
else
document.getElementById("split2").innerHTML = "No user data permission.";
}
});
</script>
</div>
</div>
<!-- implementation of sub dialog -->
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close">×</span>
<h3>Do Not Sell My Data</h3>
<p>"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
<p>
</p><input type="checkbox" id="DontSell">Do not sell my data
<p>
<input type="checkbox" id="IamAgent">I am an agent
<p align="center">
<botton id="ok" class="button">OK</botton>
</p>
</div>
</div>
<script>
// check for debug string in url param
let debug = false;
if (window.location.search.toLowerCase().search("debug=1") !== -1) {
debug = true;
}
// set lspact
let lspact = YES;
if (window.location.search.toLowerCase().search("lspact=0") !== -1) {
lspact = NO;
}
// setCookie helper function - quick hack to sets a cookie
function setCookie(cvalue = USPSTR_DEFAULT) {
let d = new Date();
d.setTime(d.getTime() + (EXDAYS*24*60*60*1000));
let expires = "expires="+ d.toUTCString();
secstr = debug ? "" : ";secure";
document.cookie = "usprivacy" + "="
+ cvalue + ";"
+ expires
+ ";path=/"
+ ";SameSite=Lax" + secstr;
}
// this section handles our "Do Not Sell" modal
let modal = document.getElementById("myModal");
let optoutstr = USPSTR_NN + lspact;
let DontSell = false;
let IsAgent = false;
// get the cookie value
window.__uspapi("getUSPData", 1, function(consent, success) {
if (success) {
optoutstr = consent.uspString.toUpperCase();
lspact = optoutstr[3];
}
});
// Check for previously store IsAgent value (localstorage)
if ((str1 = localStorage.getItem("IsAgent")) !== null) {
IsAgent = str1 == 'true' ? true : false;
}
// show the modal
function showModal () {
optoutstr = optoutstr.charAt(0) + 'Y' + (optoutstr.charAt(2) === '-' ? 'N' : optoutstr.charAt(2)); // notice shown
document.getElementById("DontSell").checked = DontSell = optoutstr[2] === 'Y' ? true : false;
document.getElementById("IamAgent").checked = IsAgent;
let modal = document.getElementById("myModal");
modal.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
let span = document.getElementsByClassName("close")[0];
span.onclick = function() {
// document.getElementById("IamAgent").checked = IsAgent = false;
modal.style.display = "none";
}
// When the user clicks the ok button
document.getElementById("ok").onclick = function() {
if (DontSell)
optoutstr = USPSTR_YY;
else if (IsAgent)
optoutstr = USPSTR_NN;
else
optoutstr = USPSTR_YN;
setCookie(optoutstr + lspact);
localStorage.setItem("IsAgent", IsAgent);
modal.style.display = "none";
window.location.reload(); // for the demo refresh the page, the left bar changes based on user selection
}
// when the user clicks the do not sell check box, set the cookie var
document.getElementById("DontSell").onclick = function() {
if (IsAgent === false && document.getElementById("DontSell").checked)
DontSell = true;
else if (IsAgent === true)
document.getElementById("DontSell").checked = DontSell = false;
else
DontSell = false;
}
// when the user clicks the do not sell check box, set the agent flag
document.getElementById("IamAgent").onclick = function() {
if ((IsAgent = document.getElementById("IamAgent").checked) === true) {
document.getElementById("DontSell").checked = DontSell = false;
}
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target === modal) {
modal.style.display = "none";
}
}
</script>
</body>
</html>