-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexample-envelope-to-ppid.html
234 lines (184 loc) · 9.11 KB
/
example-envelope-to-ppid.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>ATS - Envelope to PPID 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" />
<script async defer src="https://ats-wrapper.privacymanager.io/ats-modules/73e3e8e3-19f2-4e11-8446-73106b3c7853/ats.js"></script>'
<script src="https://cdn.rawgit.com/h2non/jsHashes/master/hashes.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>
<!-- Publisher integration overview for ATS with AdSlot (direct) -->
<script>
// Step 1: Collect the email (like on a login event), and then hash it.
// Here's an example of how you might hash your identifiers.
// LiveRamp recommends providing all 3 types below.
function getHashedIdentifierTuple(rawIdentifier) {
// And yes, please do additional sanitization/input checking prior..
let hashedIDTuple = {};
if (typeof (rawIdentifier) != "undefined" && rawIdentifier.length > 0) {
hashedIDTuple = {
md5: new Hashes.MD5().hex(rawIdentifier),
sha1: new Hashes.SHA1().hex(rawIdentifier),
sha256: new Hashes.SHA256().hex(rawIdentifier)
}
}
return hashedIDTuple;
}
// Step 2: Use the ATS.js method for "setAdditionalData" to provide email hashes.
// This will trigger a request to our identity API service for a RampID envelope.
function setHashedIdentifiersForATSDirect(identifierMD5, identifierSHA1, identifierSHA256) {
atsenvelopemodule.setAdditionalData({
'type': 'emailHashes',
'id': [identifierMD5, identifierSHA1, identifierSHA256]
});
}
// Step 3: From the envelope obtained in step 2, feed that into our transcoding API endpoint
// This (can) be added to our main library if there is sufficient enough demand for it
async function fetchPPIDFromEnvelope(envelope) {
// Note: PID 13597 describes a partner's encoding format - like for example, Adslot
let result = await fetch(`https://api.rlcdn.com/api/identity/idl?pid=13597&it=19&iv=${envelope}`)
let ppid = await result.json();
return ppid.idl;
}
// After this, you're good to go! The PPID can be set in the downstream ad request.
</script>
</head>
<body>
<div class="container">
<h1>Hello, ATS! (direct mode)</h1>
<p>This example allows you to provide an identifier directly to ATS, and then transcode the envelope to a "PPID"
to be used within GAM</p>
<p>This approach can work with any mode of ATS.js (and even calling the API!)</p>
<form id="example-form">
<div>
<p>MD5: <span id="md5hashedInput">md5</span></p>
<p>SHA1: <span id="sha1hashedInput">sha1</span></p>
<p>SHA256: <span id="sha256hashedInput">sha256</span></p>
</div>
<label for="email">Your Email</label>
<input type="text" id="emailInput" required>
<button id="directSubmit" onclick="onclick_doDirectATSCall()">Do ATS Call</button>
</form>
<div>
<h3>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>
<p>PPID Available: <span id="ppidValue"></span></p>
<button onclick="transcodeEnvelope()">Obtain PPID</button>
<p>After you have a PPID, you can set it in your downstream ad request!</p>
</div>
<!-- This is just debug information -->
<div>
<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>
// This section contains the code that powers the examples.
let emailInputRef;
async function transcodeEnvelope() {
let envDisplay = document.getElementById("atsEnvelopeValue");
let ppidDisplay = document.getElementById("ppidValue");
let displayVal = "";
if (typeof (ats) != 'undefined') {
console.log("fetching idl for envelope", envDisplay.textContent);
var env = JSON.parse(envDisplay.textContent);
var ppid = await fetchPPIDFromEnvelope(env.envelope);
if (typeof (ppid) != 'undefined') {
displayVal = ppid;
} else {
displayVal = "failed"
}
} else {
displayVal = "failed"
}
ppidDisplay.textContent = displayVal;
}
async function checkForEnvelope() {
let 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;
}
// Example invocation call, we'll call this with our UI
function setATSDirectForIdentifier(cleartextEmail) {
let
tuple = getHashedIdentifierTuple(cleartextEmail); setHashedIdentifiersForATSDirect(tuple.md5,
tuple.sha1, tuple.sha256);
} document.addEventListener('DOMContentLoaded', () => {
console.log("Doc loaded");
emailInputRef = document.getElementById('emailInput');
emailInputRef.addEventListener('input', doLiveHashUIUpdate);
// Prevent submit button from redirecting
document.getElementById("directSubmit").addEventListener("click",
(e) => e.preventDefault());
});
// TODO: get rid of this hacky way.
setTimeout(() => {
var isEnabled = checkATSStatus();
if (isEnabled) {
let envInfoTableRef = document.getElementById("envelope-module-info");
envModuleInfo = getATSEnvelopeModuleInfo();
renderModuleInfoObjToTable(envModuleInfo, envInfoTableRef);
}
}, 1000);
let md5InputSpanRef = document.getElementById('md5hashedInput');
let sha1InputSpanRef = document.getElementById('sha1hashedInput');
let sha256InputSpanRef = document.getElementById('sha256hashedInput');
// Live update the UI for the sake of our example
function doLiveHashUIUpdate(event) {
var tuple = getHashedIdentifierTuple(emailInputRef.value);
md5InputSpanRef.textContent = tuple.md5;
sha1InputSpanRef.textContent = tuple.sha1;
sha256InputSpanRef.textContent = tuple.sha256;
}
function onclick_doDirectATSCall() {
setATSDirectForIdentifier(emailInputRef.value);
}
function checkATSStatus() {
let atsEnabled = document.getElementById('atsEnabled');
if (typeof (ats) == 'undefined') {
atsEnabled.textContent = "Not loaded"
return false
} else {
atsEnabled.textContent = "Loaded"
return true;
}
}
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>