-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
218 lines (157 loc) · 6.83 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
<!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" />
<!-- Load this as close to the top of the document as possible -->
<!-- <script async defer src="https://launchpad-wrapper.privacymanager.io/0ac9abb3-e561-4f79-9385-9bb06f8aa49a/launchpad-liveramp.js"></script> -->
<!-- We have some pretty nifty ATS event listeners. -->
<script>
// ATS envelope module is ready to be used.
window.addEventListener("envelopeModuleReady", () => {
console.log("ATS Event Listener: envelopeModuleReady")
});
// An ATS envelope has been located!
window.addEventListener("lrEnvelopePresent", () => {
console.log("ATS Event Listener: lrEnvelopePresent")
});
// ATS detection module is ready to be used.
window.addEventListener("detectionModuleReady", () => {
console.log("ATS Event Listener: detectionModuleReady")
});
</script>
<!-- For local testing if you happen to be using localhost. Your envelope requests will fail if you run this on any other site. -->
<script src="https://ats-wrapper.privacymanager.io/ats-modules/2bc4da3a-b0ae-49bb-8dbe-eb3d05ecbd38/ats.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>
<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>
</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 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>