forked from aoimatsuba/showcar-tracking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
372 lines (330 loc) · 15.1 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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
<script data-pagespeed-no-defer>
(function () {
'use strict';
if (/disable-cmp=true/.test(document.cookie) || location.href.indexOf('disable-cmp=true') > -1) {
return false;
}
ensureVisitorId();
setCmpCookiesIfProvidedAsQueryStrings();
// TCF stub
// prettier-ignore
!function(){if("function"!=typeof window.__tcfapi||window.__tcfapi&&"function"!=typeof window.__tcfapi.start){var t,a=[],e=window,i=e.document,c=e.__tcfapi?e.__tcfapi.start:function(){};if(!e.__tcfapi&&function t(){var a=!!e.frames.__tcfapiLocator;if(!a){if(i.body){var c=i.createElement("iframe");c.style.cssText="display:none",c.name="__tcfapiLocator",i.body.appendChild(c)}else setTimeout(t,5)}return!a}()||e.__tcfapi&&!e.__tcfapi.start){var f=e.__tcfapi?e.__tcfapi():[];a.push.apply(a,f),e.__tcfapi=function(...e){var i=[...e];if(!e.length)return a;if("setGdprApplies"===i[0])i.length>3&&2===parseInt(i[1],10)&&"boolean"==typeof i[3]&&(t=i[3],"function"==typeof i[2]&&i[2]("set",!0));else if("ping"===i[0]){var c={gdprApplies:t,cmpLoaded:!1,apiVersion:"2.0"};"function"==typeof i[2]&&i[2](c,!0)}else a.push(i)},e.__tcfapi.commandQueue=a,e.__tcfapi.start=c,e.addEventListener("message",function(t){var a="string"==typeof t.data,i={};try{i=a?JSON.parse(t.data):t.data}catch(c){}var f=i.__tcfapiCall;f&&e.__tcfapi(f.command,f.version,function(e,i){if(t.source){var c={__tcfapiReturn:{returnValue:e,success:i,callId:f.callId,command:f.command}};a&&(c=JSON.stringify(c)),t.source.postMessage(c,"*")}},f.parameter)},!1)}}}();
loadAs24Cmp().then(() => {
if (window.__as24CmpEnabled) {
deletePersonalizationCookiesIfNeeded();
return;
}
var tld = window.location.hostname.split('.').pop();
setCmpLanguage(tld, window.location.pathname);
hideCmpIfNeeded();
trackCmpEvents();
loadCmpWithoutAbTest();
deletePersonalizationCookiesIfNeeded()
}).catch(_ => {
var tld = window.location.hostname.split('.').pop();
setCmpLanguage(tld, window.location.pathname);
hideCmpIfNeeded();
trackCmpEvents();
loadCmpWithoutAbTest();
deletePersonalizationCookiesIfNeeded();
});
/** In case we don't have a visitor id we set one. */
function ensureVisitorId() {
if (!/as24Visitor/.test(document.cookie)) {
var domain = window.location.hostname.replace('www.', '').replace('local.', '');
document.cookie = 'as24Visitor=' + uuidv4() + ';path=/;max-age=31536000;domain=' + domain;
}
}
/** Apps have their own CMP. For webviews they provide the consent string through query strings. */
function setCmpCookiesIfProvidedAsQueryStrings() {
var urlParams = new URLSearchParams(window.location.search);
var euconsentv2 = urlParams.get('euconsent-v2');
var cconsentv2 = urlParams.get('cconsent-v2');
var gdprAuditId = urlParams.get('gdpr-auditId');
var addtlConsent = urlParams.get('addtl_consent');
var gdprLastInteraction = (Date.now() / 1000).toFixed(3);
var domain = 'domain=' + document.location.hostname.replace('www.', '').replace('local.', '');
var path = 'path=/';
var maxAge = 'max-age=31536000';
var sameSite = 'samesite=Lax';
if (euconsentv2 && cconsentv2 && gdprAuditId && addtlConsent) {
document.cookie = ['euconsent-v2=' + euconsentv2, path, maxAge, domain, sameSite].join(';');
document.cookie = ['cconsent-v2=' + cconsentv2, path, maxAge, domain, sameSite].join(';');
document.cookie = ['gdpr-auditId=' + gdprAuditId, path, maxAge, domain, sameSite].join(';');
document.cookie = ['addtl_consent=' + addtlConsent, path, maxAge, domain, sameSite].join(';');
document.cookie = ['gdpr-last-interaction=' + gdprLastInteraction, path, maxAge, domain, sameSite].join(
';'
);
// We need to delete consent params from the URL
// so that they don't corrupt GA tracking and other tools.
urlParams.delete('euconsent-v2');
urlParams.delete('cconsent-v2');
urlParams.delete('gdpr-auditId');
urlParams.delete('addtl_consent');
urlParams.delete('gdpr-last-interaction');
history.replaceState(null, '', `?${urlParams.toString()}`);
}
}
/**
We take the language from the domain and path and set it for the CMP.
For non-core countries we always set it to 'en'.
@param {string} tld - The top level domain
@param {string} pathname - The full page path
*/
function setCmpLanguage(tld, pathname) {
function guessLanguage() {
switch (tld) {
case 'at':
return 'de';
case 'be':
return pathname.indexOf('/fr/') === 0 ? 'fr' : 'nl';
case 'lu':
return 'fr';
case 'de':
case 'it':
case 'nl':
case 'fr':
case 'es':
case 'pl':
case 'ro':
case 'bg':
case 'cz':
case 'hr':
case 'se':
case 'hu':
case 'ru':
case 'tr':
return tld;
default:
return 'en';
}
}
__tcfapi('changeLanguage', null, noOp, guessLanguage());
}
function trackCmpEvents() {
function trackInGA(event) {
window.dataLayer = window.dataLayer || [];
if (
dataLayer.filter(function (x) {
return x.event === 'data_ready';
}).length === 0
) {
setTimeout(function () {
trackInGA(event);
}, 100);
return;
}
window.dataLayer.push({
event: 'event_trigger',
event_category: 'CMP',
event_action: event,
});
}
var trackedCmpEvents = [
'acceptAllButtonClicked',
'exitButtonClicked',
'saveAndExitButtonClicked',
'consentToolShouldBeShown',
'denyAllButtonClicked',
'consentManagerDisplayed',
'consentManagerClosed',
'consentNoticeDisplayed',
'consentNoticeClosed',
];
trackedCmpEvents.forEach(function (event) {
window.__tcfapi(
'addEventListener',
2,
function () {
trackInGA(event);
},
event
);
});
}
function loadAs24Cmp() {
return new Promise(resolve => {
var script = document.createElement('script');
var ref = document.getElementsByTagName('script')[0];
ref.parentNode.insertBefore(script, ref);
var culture = getCulture(window.location.hostname, window.location.pathname);
script.type = 'module';
script.onload = resolve;
script.src = 'https://www.autoscout24.com/assets/as24-cmp/consent-banner/' + culture + '.js';
});
}
function getCulture(hostname, path) {
const tld = hostname.split('.').pop();
switch (tld) {
case 'de':
return 'de-DE';
case 'at':
return 'de-AT';
case 'it':
return 'it-IT';
case 'es':
return 'es-ES';
case 'fr':
return 'fr-FR';
case 'nl':
return 'nl-NL';
case 'lu':
return 'fr-LU';
case 'com':
return 'en-GB';
case 'bg':
return 'bg-BG';
case 'hu':
return 'hu-HU';
case 'pl':
return 'pl-PL';
case 'ro':
return 'ro-RO';
case 'hr':
return 'hr-HR';
case 'cz':
return 'cs-CZ';
case 'ua':
return 'uk-UA';
case 'se':
return 'sv-SE';
case 'ru':
return 'ru-RU';
case 'tr':
return 'tr-TR';
case 'be':
return path.startsWith('/nl/') ? 'nl-BE' : 'fr-BE';
case 'localhost':
case 'tech':
default:
return 'en-GB';
}
}
function loadLiveRampScript(uid) {
var script = document.createElement('script');
var ref = document.getElementsByTagName('script')[0];
ref.parentNode.insertBefore(script, ref);
script.src = 'https://gdpr-wrapper.privacymanager.io/gdpr/' + uid + '/gdpr-liveramp.js';
}
function hideCmpIfNeeded() {
var isOnPrivacyPage = document.querySelector('as24-tracking[pageid="au-company-privacy"]');
var containsSuppressCmpAttribute = document.querySelector('body[data-suppress-cmp="true"]') !== null;
var isOnDealerInfoPages = /^\/(haendler|nl\/verkopers|(fr\/)?professional|autobedrijven|garages|profesionales|concessionari|((fr|nl)\/)?dealerinfo\/admin)/.test(
window.location.pathname
);
var isEntryLogoutPage = /^\/(entry)/.test(window.location.pathname);
var shouldHideCmp =
isEntryLogoutPage || // on entry logout page
window.location.hostname === 'accounts.autoscout24.com' || // on Identity pages
isOnPrivacyPage || // on privacy pages
isOnDealerInfoPages ||
containsSuppressCmpAttribute || // explicit suppress directive
window.self !== window.top; // inside an iframe
var suppressDialogue = function () {
__tcfapi('toggleConsentTool', 2, function () {}, false);
};
if (shouldHideCmp) {
__tcfapi('addEventListener', 2, suppressDialogue);
if (isOnPrivacyPage) {
window.addEventListener('load', function () {
__tcfapi('removeEventListener', 2, suppressDialogue);
});
}
}
}
function noOp() {}
function loadCmpWithoutAbTest() {
var tldToLiveRampMap = {
at: '3e24114e-f793-4eba-8c0f-735086de7eb6',
be: '55b58bfe-4c4d-4943-bbf3-11ec3eedc57b',
de: 'a7e8fb93-5f1f-4375-b321-8e998143ae61',
es: '4411e5b3-1b15-4c38-8b0b-a1bd0a7c1c15',
fr: 'cd417891-edbe-4abd-9417-c6a2791634e4',
it: 'b36f31e9-ba65-47f5-b151-66c307c999d9',
lu: 'd32b30c5-1df5-4e45-825e-1f0d7ce19b08',
nl: '7a9273aa-bc97-4542-bed2-4ee53960a5ae',
com: '94a59b49-b7ea-4e1c-93c9-95a65811342b',
bg: 'c91d7583-8f6b-4377-9930-d2f4121c077e',
cz: 'af726efc-d085-4dcd-b1b2-d70bec664c9b',
ru: '1f94bd98-a90c-42b8-b0f6-dd27eab93973',
pl: 'f45e019f-1401-499f-a329-19c20067273d',
hu: '47d0ac99-7029-4dae-91ac-15dd5793eded',
hr: '04a29971-bbd1-4577-a5fb-07e85b4933d3',
ro: 'c4949c4e-b1b9-4434-919d-c766202554e5',
se: '5aeab49d-a921-494f-9b8a-84001adbab72',
tr: 'd54e7f74-947c-49b3-9eb8-248cbad044fb',
ua: '730298e4-c5c4-463b-a86c-ead192d21c6f',
};
var tld = window.location.hostname.split('.').pop();
var liverampTcf2Id = tldToLiveRampMap[tld];
loadLiveRampScript(liverampTcf2Id);
}
function deletePersonalizationCookiesIfNeeded() {
var personalizationCookies = [
'last-search-feed',
'last-seen-classified-guid',
'last-5-seen-classifieds'
];
onCmpDataLoadOrConsentChange(function () {
window.__tcfapi('getFullTCData', 2, (tcData) => {
var isPersonalizationCookieAllowed = tcData.purpose.legitimateInterests['25'] && tcData.purpose.consents['26']
if(!isPersonalizationCookieAllowed) {
personalizationCookies.forEach(function(cookie) {
deleteCookie(cookie)
})
}
});
})
}
function onCmpDataLoadOrConsentChange(callback) {
window.__tcfapi(
'addEventListener',
2,
function (partialTcData, success) {
if (
success &&
(partialTcData.eventStatus === 'tcloaded' || partialTcData.eventStatus === 'useractioncomplete')
) callback();
}
);
}
/**
Reads cookie value
@param {string} cookieName
@return {string}
*/
function getCookieValue(cookieName) {
var x = document.cookie.match('(^|;)\\s*' + cookieName + '\\s*=\\s*([^;]+)');
return x ? x.pop() : '';
}
/**
Delete cookie value
@param {string} cookieName
@return {void}
*/
function deleteCookie(cookieName) {
var date = new Date()
var ONE_DAY_IN_MS = 24 * 60 * 60 * 1000
var domain = window.location.hostname.replace('www.', '').replace('local.', '');
date.setTime(date.getTime() + -1 * ONE_DAY_IN_MS) // Set it expire in -1 days
document.cookie =
cookieName +
'=; expires=' +
date.toUTCString() +
'; domain=' +
domain +
'; path=/'
}
/** Generates a UUID v4
@return {string}
*/
function uuidv4() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = (Math.random() * 16) | 0,
v = c == 'x' ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
}
})();
</script>
<script src="@@ASSET_PATH/index.min.js" defer data-pagespeed-no-defer></script>