-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
295 lines (216 loc) · 8.45 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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<!DOCTYPE html>
<html lang="en">
<head>
<title>ATS Form Submit Detect Example</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta name="description" content="" />
<link rel="stylesheet" type="text/css" href="css/style.css" />
<link rel="preload" href="https://launchpad.privacymanager.io/latest/launchpad.bundle.js" as="script" />
<script async defer src="https://launchpad-wrapper.privacymanager.io/77bb4cba-c1b7-41a3-ae8e-19a450905953/launchpad-liveramp.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
</head>
<body>
<div class="container">
<h1>Hello, ATS!</h1>
<p>This example shows a basic form that will provide an envelope on form submit.</p>
<form id="example-form">
<label for="email">Your Email</label>
<input type="text" id="email" required>
<button type="submit">Submit</button>
</form>
<form id="example-form">
<label for="pdata">Test p-data</label>
<input type="text" id="pdata" required>
<button type="submit">Submit</button>
</form>
<div>
<h3>General ATS info</h1>
<p>ATS Enabled: <span id="atsEnabled"></span></p>
<p>Envelope Available: <span id="atsEnvelopeValue"></span></p>
<button onclick="checkForEnvelope()">Check for Envelope</button>
<button onclick="triggerCST(pdata)">Fire CST</button>
</div>
<div>
<h3>Detection module info</h1>
<table>
<thead>
<tr>
<th>Name</th>
<th>Value</th>
</tr>
</thead>
<tbody id="detection-module-info"">
<!-- Dynamically generated -->
</tbody>
</table>
<h3>Envelope module info</h1>
<table>
<thead>
<tr>
<th>Name</th>
<th>Value</th>
</tr>
</thead>
<tbody id="envelope-module-info"">
<!-- Dynamically generated -->
</tbody>
</table>
</div>
</div>
<script>
async function triggerCST(pdata) {
/*
Set variables and enter your IDs.
If you do not have a pid or pixelID, contact your LiveRamp representative.
*/
var env;
var envString;
var consentString;
var pid = // <YOUR PID HERE>;
consentString = await fetchCMPConsent();
/*
Attempt to fetch Envelope from storage.
If this fails, attempt to fetch envelope from Cookie.
If this also fails, set envelope value to "noEnvelope"
*/
try {
// Retrieve the envelope from ATS
env = await ats.retrieveEnvelope();
envString = JSON.parse(env).envelope;
} catch (error) {
envString = await doEnvelopeAPIFallback(pid, consentString);
}
}
// Attempt to fetch consent from the CMP
async function fetchCMPConsent() {
var cString;
try {
await __tcfapi('getTCData', 2, (data, success) => {
if (success) { //&& utils.getTCFV2Consent(data.tcString)) {
cString = "&ct=4&cv=" + data.tcString
}
})
} catch (error) {
cString = ""
}
return cString;
}
// Perform a fallback lookup using the cookie (if it exists) on the current page
async function doEnvelopeAPIFallback(pid, consentString) {
var envString;
try {
var response = await fetch("https://api.rlcdn.com/api/identity/envelope?pid=" +
pid + consentString, {
credentials: 'include'
});
envString = await response.json();
envString = envString.envelope;
} catch (error) {
envString = "noEnvelope";
}
return envString;
}
function createCSTPixelForPData(pdata, envString, pid) {
var pdataParsed;
var tag
/*
pdata should be comma separated pairs of key/value
Ex: "key1=value1, key2=value2"
URL encode the pdata field
*/
if (pdata == null) {
pdataParsed = ""
} else {
pdataParsed = encodeURIComponent(pdata + "%2C");
}
tag = document.createElement("script");
tag.src = "https://di.rlcdn.com/api/segment?pid=" + pid + "&it=19&iv=" + envString
"pdata=" + pdataParsed;
return tag;
}
async function checkForEnvelope() {
const envDisplay = document.getElementById("atsEnvelopeValue");
let displayVal = "";
if (typeof(ats) != 'undefined') {
var env = await ats.retrieveEnvelope();
if (typeof(env) != 'undefined') {
displayVal = env;
} else {
displayVal = "no envelope"
}
} else {
displayVal = "ats not defined"
}
envDisplay.textContent = displayVal;
}
// TODO: implement some poller
function beginEnvelopePoller() {
}
document.addEventListener('DOMContentLoaded', () => {
console.log("Doc loaded");
const form = document.getElementById('example-form');
form.addEventListener('submit', doSubmit);
// TODO: get rid of this hacky way.
setTimeout(() => {
var isEnabled = checkATSStatus();
if (isEnabled) {
let envInfoTableRef = document.getElementById("envelope-module-info");
let detectInfoTableRef = document.getElementById("detection-module-info");
envModuleInfo = getATSEnvelopeModuleInfo();
detectModuleInfo = getATSDetectionModuleInfo();
renderModuleInfoObjToTable(envModuleInfo, envInfoTableRef);
renderModuleInfoObjToTable(detectModuleInfo, detectInfoTableRef);
}
}, 1000);
});
function doSubmit(event) {
console.log(`Form Submitted! Time stamp: ${event.timeStamp}`);
event.preventDefault();
}
function checkATSStatus() {
let atsEnabled = document.getElementById('atsEnabled');
if (typeof (ats) == 'undefined') {
atsEnabled.textContent = "Not loaded"
return false
} else {
atsEnabled.textContent = "Loaded"
return true;
}
}
// Amend this to add more elements we care about
function getATSDetectionModuleInfo() {
let moduleInfoKVP = {};
let detectInfo = ats.outputCurrentConfiguration().DETECTION_MODULE_INFO;
let detectConfig = detectInfo.DETECTION_MODULE_CONFIG;
moduleInfoKVP["ATS Trigger Element"] = detectConfig.triggerElements.join(",");
let triggerElements = ats.outputCurrentConfiguration().DETECTION_MODULE_INFO.DETECTION_MODULE_CONFIG.triggerElements;
// TODO: do more
return moduleInfoKVP;
}
function getATSEnvelopeModuleInfo() {
let moduleInfoKVP = {};
let envInfo = ats.outputCurrentConfiguration().ENVELOPE_MODULE_INFO;
let envConfig = envInfo.ENVELOPE_MODULE_CONFIG;
// Populate the object here with a readable unique key and the value
moduleInfoKVP["PID"] = envConfig.placementID;
// TODO: do more
return moduleInfoKVP;
}
function renderModuleInfoObjToTable(infoObj, tableRef) {
var keyCollection = Object.keys(infoObj);
for (var i = 0; i < keyCollection.length; ++i){
let tRow = document.createElement("tr");
let tKey = document.createElement("td");
tKey.textContent = keyCollection[i];
let tData = document.createElement("td");
tData.textContent = infoObj[keyCollection];
tRow.appendChild(tKey);
tRow.appendChild(tData);
tableRef.appendChild(tRow);
}
}
</script>
</body>
</html>