-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample-pbjs-ats.html
299 lines (240 loc) · 10.7 KB
/
example-pbjs-ats.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
296
297
298
299
<!DOCTYPE html>
<html lang="en">
<head>
<title>ATS v2 with Prebid 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" />
<!-- In some cases (usually for only US based publishers), you won't need to use our launchpad tag manager if you only plan on leveraging our ATS.js offering -->
<script async defer
src="https://ats-wrapper.privacymanager.io/ats-modules/73e3e8e3-19f2-4e11-8446-73106b3c7853/ats.js"></script>
<!-- Included a basic version of prebid with just the LiveRamp envelope module (identityLink) + ATS Analytics -->
<script async src="https://www.googletagservices.com/tag/js/gpt.js"></script>
<!-- <script async src="https://cdn.jsdelivr.net/npm/prebid.js@latest/dist/not-for-prod/prebid.js"></script> -->
<script async src="https://cdn.jsdelivr.net/npm/[email protected]/dist/not-for-prod/prebid.js"></script>
<!-- We RECOMMEND using a publicly auditable hashing implementation so you know what you're getting into! -->
<script src="https://cdn.rawgit.com/h2non/jsHashes/master/hashes.js"></script>
<!-- To make things look dapper.. -->
<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>
<script>
function setPBJSConfigForLiveRampATS() {
console.log("Set pbjs config:");
if (typeof (pbjs) != 'undefined') {
pbjs.setConfig({
userSync: {
userIds: [{
name: "identityLink",
params: {
pid: '13669', // Set your real ATS Placement ID here
},
storage: {
type: "cookie",
name: "idl_env", // "idl_env" is the required storage name
expires: 1, // Identity envelope can last for 15 days
refreshInSeconds: 1
}
}],
syncDelay: 4000 // X seconds after the first auction
}
});
}
}
function refreshPBJSUserId() {
console.log("Refreshing...")
pbjs.refreshUserIds();
}
</script>
</head>
<body>
<div class="container">
<h1>Hello, ATSv2 (in Prebid) </h1>
<p>This example shows how an envelope is passed to Prebid.</p>
<p>Friendly note: You'll need to remember to set the config after prebid (pbjs) is loaded! </p>
<form id="example-form">
<button id="directSubmit" onclick="onclick_doDirectATSCall()">Do ATS Direct Call</button>
</form>
<div>
<h3>General info</h1>
<p>ATS Enabled: <span id="atsEnabled"></span></p>
<p>Envelope Available: <span id="atsEnvelopeValue"></span></p>
<button onclick="checkForEnvelope()">Fetch a Test Envelope</button>
<button onclick="refreshPBJSUserId()">Refresh PBJS User Ids</button>
</div>
<h5>Test Ad</h5>
<div id='div-1'>
</div>
<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>
<!-- Prebid Provided example implementation -->
<script>
try {
var slot1;
var sizes = [[300, 250]];
var PREBID_TIMEOUT = 1000;
var FAILSAFE_TIMEOUT = 3000;
var adUnits = [{
code: '/19968336/header-bid-tag-1',
mediaTypes: {
banner: {
sizes: sizes
}
},
bids: [{
bidder: 'appnexus',
params: {
placementId: 13144370
}
}]
}];
function refreshBid() {
pbjs.que.push(function() {
pbjs.requestBids({
timeout: PREBID_TIMEOUT,
adUnitCodes: ['/19968336/header-bid-tag-1'],
bidsBackHandler: function() {
pbjs.setTargetingForGPTAsync(['/19968336/header-bid-tag-1']);
googletag.pubads().refresh([slot1]);
}
});
});
}
// ======== DO NOT EDIT BELOW THIS LINE =========== //
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
googletag.cmd.push(function () {
googletag.pubads().disableInitialLoad();
});
var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];
pbjs.que.push(function () {
pbjs.enableAnalytics([{
provider: "atsAnalytics",
options: { pid: "13669" }}]);
pbjs.addAdUnits(adUnits);
pbjs.requestBids({
bidsBackHandler: initAdserver,
timeout: PREBID_TIMEOUT
});
});
function initAdserver() {
if (pbjs.initAdserverSet) return;
pbjs.initAdserverSet = true;
googletag.cmd.push(function () {
pbjs.setTargetingForGPTAsync && pbjs.setTargetingForGPTAsync();
googletag.pubads().refresh();
});
}
// in case PBJS doesn't load
setTimeout(function () {
initAdserver();
}, FAILSAFE_TIMEOUT);
googletag.cmd.push(function () {
slot1 = googletag.defineSlot('/19968336/header-bid-tag-1', sizes, 'div-1')
.addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
} catch (e) {
console.log(" Failed in this block with: ", e)
}
</script>
<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;
} function getHashedIdentifierTuple(rawIdentifier) {
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;
}
// Here's an example of using "setAdditionalData" - this will in turn 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]
});
console.log("Set hashed identifiers")
}
// Example invocation call, we'll call this with our UI
function setATSDirectForIdentifier(cleartextEmail) {
let tuple = getHashedIdentifierTuple(cleartextEmail);
setHashedIdentifiersForATSDirect(tuple.md5, tuple.sha1, tuple.sha256);
}
function onclick_doDirectATSCall() {
setATSDirectForIdentifier("[email protected]");
}
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>
<!-- My own script to set PBJS config (hacky, 1000 after) -->
<script>
document.addEventListener('DOMContentLoaded', () => {
console.log("Document loaded");
// Prevent submit button from redirecting
document.getElementById("directSubmit").addEventListener("click",
(e) => e.preventDefault());
setTimeout(() => {
console.log("Delayed for 1 second:")
setPBJSConfigForLiveRampATS();
googletag.cmd.push(() => googletag.display('div-1'));
if (checkATSStatus()) {
let envInfoTableRef = document.getElementById("envelope-module-info");
envModuleInfo = getATSEnvelopeModuleInfo();
renderModuleInfoObjToTable(envModuleInfo, envInfoTableRef);
}
}, 1000);
});
</script>
</body>
</html>