@blotoutio/edgetag-sdk-js 0.6.9 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +206 -156
- package/index.esm.js +206 -156
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -41,132 +41,6 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
const tagStorage = 'edgeTag';
|
|
45
|
-
const consentKey = 'consent';
|
|
46
|
-
const keyPrefix = `_worker`;
|
|
47
|
-
|
|
48
|
-
const initKey = `${keyPrefix}Store`;
|
|
49
|
-
const getCookieValue = (key) => {
|
|
50
|
-
if (!document || !document.cookie) {
|
|
51
|
-
return '';
|
|
52
|
-
}
|
|
53
|
-
const name = `${key}=`;
|
|
54
|
-
const decodedCookie = decodeURIComponent(document.cookie);
|
|
55
|
-
const ca = decodedCookie.split(';');
|
|
56
|
-
for (let i = 0; i < ca.length; i++) {
|
|
57
|
-
let c = ca[i];
|
|
58
|
-
while (c.charAt(0) === ' ') {
|
|
59
|
-
c = c.substring(1);
|
|
60
|
-
}
|
|
61
|
-
if (c.indexOf(name) === 0) {
|
|
62
|
-
return c.substring(name.length, c.length);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return '';
|
|
66
|
-
};
|
|
67
|
-
const saveDataPerKey = (persistType, provider, value, key) => {
|
|
68
|
-
const storage = getData$1(persistType);
|
|
69
|
-
if (!storage['data']) {
|
|
70
|
-
storage['data'] = {};
|
|
71
|
-
}
|
|
72
|
-
if (!storage['data'][provider]) {
|
|
73
|
-
storage['data'][provider] = {};
|
|
74
|
-
}
|
|
75
|
-
storage['data'][provider][key] = value;
|
|
76
|
-
saveData(persistType, storage);
|
|
77
|
-
};
|
|
78
|
-
const savePerKey = (persistType, provider, value, key) => {
|
|
79
|
-
const storage = getData$1(persistType);
|
|
80
|
-
if (!storage[provider]) {
|
|
81
|
-
storage[provider] = {};
|
|
82
|
-
}
|
|
83
|
-
storage[provider][key] = value;
|
|
84
|
-
saveData(persistType, storage);
|
|
85
|
-
};
|
|
86
|
-
const getDataPerKey = (persistType, provider, key) => {
|
|
87
|
-
const storage = getData$1(persistType);
|
|
88
|
-
if (!storage[provider]) {
|
|
89
|
-
return undefined;
|
|
90
|
-
}
|
|
91
|
-
return storage[provider][key];
|
|
92
|
-
};
|
|
93
|
-
const saveData = (persistType, value, key = initKey) => {
|
|
94
|
-
if (persistType === 'session') {
|
|
95
|
-
saveSession(value, key);
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
saveLocal(value, key);
|
|
99
|
-
};
|
|
100
|
-
const getData$1 = (persistType, key = initKey) => {
|
|
101
|
-
if (persistType === 'session') {
|
|
102
|
-
return getSession(key);
|
|
103
|
-
}
|
|
104
|
-
return getLocal(key);
|
|
105
|
-
};
|
|
106
|
-
const saveKV = (data) => {
|
|
107
|
-
let currentSession = getData$1('session');
|
|
108
|
-
if (!currentSession) {
|
|
109
|
-
currentSession = {};
|
|
110
|
-
}
|
|
111
|
-
if (!currentSession['kv']) {
|
|
112
|
-
currentSession['kv'] = {};
|
|
113
|
-
}
|
|
114
|
-
currentSession['kv'] = Object.assign(Object.assign({}, currentSession['kv']), data);
|
|
115
|
-
saveData('session', currentSession);
|
|
116
|
-
};
|
|
117
|
-
const saveLocal = (value, key) => {
|
|
118
|
-
try {
|
|
119
|
-
if (!localStorage) {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
localStorage.setItem(key, JSON.stringify(value));
|
|
123
|
-
}
|
|
124
|
-
catch (_a) {
|
|
125
|
-
console.log('Local storage not supported');
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
const getLocal = (key) => {
|
|
129
|
-
try {
|
|
130
|
-
if (!localStorage) {
|
|
131
|
-
return {};
|
|
132
|
-
}
|
|
133
|
-
const data = localStorage.getItem(key);
|
|
134
|
-
if (!data) {
|
|
135
|
-
return {};
|
|
136
|
-
}
|
|
137
|
-
return JSON.parse(data) || {};
|
|
138
|
-
}
|
|
139
|
-
catch (_a) {
|
|
140
|
-
return {};
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
const saveSession = (value, key) => {
|
|
144
|
-
try {
|
|
145
|
-
if (!sessionStorage) {
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
sessionStorage.setItem(key, JSON.stringify(value));
|
|
149
|
-
}
|
|
150
|
-
catch (_a) {
|
|
151
|
-
console.log('Session storage not supported');
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
const getSession = (key) => {
|
|
155
|
-
try {
|
|
156
|
-
if (!sessionStorage) {
|
|
157
|
-
return {};
|
|
158
|
-
}
|
|
159
|
-
const data = sessionStorage.getItem(key);
|
|
160
|
-
if (!data) {
|
|
161
|
-
return {};
|
|
162
|
-
}
|
|
163
|
-
return JSON.parse(data) || {};
|
|
164
|
-
}
|
|
165
|
-
catch (_a) {
|
|
166
|
-
return {};
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
|
|
170
44
|
let endpointUrl = '';
|
|
171
45
|
const generateUrl = (path) => {
|
|
172
46
|
const endpoint = getUrl();
|
|
@@ -227,13 +101,18 @@ const setPreferences = (preferences) => {
|
|
|
227
101
|
}
|
|
228
102
|
providersPackages[provider.name] = provider;
|
|
229
103
|
});
|
|
230
|
-
|
|
231
|
-
window.edgetagProviders
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
104
|
+
try {
|
|
105
|
+
if (window && Array.isArray(window.edgetagProviders)) {
|
|
106
|
+
window.edgetagProviders.forEach((provider) => {
|
|
107
|
+
if (!provider.name) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
providersPackages[provider.name] = provider;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
catch (_b) {
|
|
115
|
+
// do nothing
|
|
237
116
|
}
|
|
238
117
|
setUrl(preferences.edgeURL);
|
|
239
118
|
return true;
|
|
@@ -250,16 +129,21 @@ const setAllowedProviders = (providers) => {
|
|
|
250
129
|
};
|
|
251
130
|
|
|
252
131
|
const getUserAgent = () => {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
132
|
+
try {
|
|
133
|
+
const nav = navigator;
|
|
134
|
+
let ua = nav.userAgent;
|
|
135
|
+
ua += nav.brave ? `${ua} Brave` : '';
|
|
136
|
+
return ua;
|
|
137
|
+
}
|
|
138
|
+
catch (_a) {
|
|
139
|
+
return '';
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
const isProviderIncluded = (providers, providerValue) => {
|
|
143
|
+
return (providerValue || (providers['all'] === true && providerValue === undefined));
|
|
257
144
|
};
|
|
258
145
|
const allowTag = (providers) => {
|
|
259
|
-
|
|
260
|
-
return false;
|
|
261
|
-
}
|
|
262
|
-
const consent = getDataPerKey('local', tagStorage, consentKey);
|
|
146
|
+
const consent = getConsent();
|
|
263
147
|
if (isConsentDisabled()) {
|
|
264
148
|
return true;
|
|
265
149
|
}
|
|
@@ -274,19 +158,15 @@ const allowTag = (providers) => {
|
|
|
274
158
|
}
|
|
275
159
|
const allProviders = getAllowedProviders();
|
|
276
160
|
for (const provider of allProviders) {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
(providers['all'] === false && tagProviderSetting === true)) {
|
|
281
|
-
if (consent[provider]) {
|
|
282
|
-
return true;
|
|
283
|
-
}
|
|
161
|
+
if (isProviderIncluded(providers, !!providers[provider]) &&
|
|
162
|
+
consent[provider]) {
|
|
163
|
+
return true;
|
|
284
164
|
}
|
|
285
165
|
}
|
|
286
166
|
return false;
|
|
287
167
|
};
|
|
288
168
|
const allowProviders = (providers) => {
|
|
289
|
-
if (!providers || Object.keys(providers).length === 0) {
|
|
169
|
+
if (!providers || Object.keys(providers).length === 0 || providers['all']) {
|
|
290
170
|
return true;
|
|
291
171
|
}
|
|
292
172
|
const allowedProvider = getAllowedProviders();
|
|
@@ -326,7 +206,7 @@ const allowProviderWithConsent = (providers, providerId) => {
|
|
|
326
206
|
return false;
|
|
327
207
|
}
|
|
328
208
|
}
|
|
329
|
-
const consent =
|
|
209
|
+
const consent = getConsent();
|
|
330
210
|
if (isConsentDisabled()) {
|
|
331
211
|
return true;
|
|
332
212
|
}
|
|
@@ -339,6 +219,148 @@ const allowProviderWithConsent = (providers, providerId) => {
|
|
|
339
219
|
return consent[providerId];
|
|
340
220
|
};
|
|
341
221
|
|
|
222
|
+
const tagStorage = 'edgeTag';
|
|
223
|
+
const consentKey = 'consent';
|
|
224
|
+
const keyPrefix = `_worker`;
|
|
225
|
+
|
|
226
|
+
const initKey = `${keyPrefix}Store`;
|
|
227
|
+
const getCookieValue = (key) => {
|
|
228
|
+
try {
|
|
229
|
+
if (!document || !document.cookie) {
|
|
230
|
+
return '';
|
|
231
|
+
}
|
|
232
|
+
const name = `${key}=`;
|
|
233
|
+
const decodedCookie = decodeURIComponent(document.cookie);
|
|
234
|
+
const ca = decodedCookie.split(';');
|
|
235
|
+
for (let i = 0; i < ca.length; i++) {
|
|
236
|
+
let c = ca[i];
|
|
237
|
+
while (c.charAt(0) === ' ') {
|
|
238
|
+
c = c.substring(1);
|
|
239
|
+
}
|
|
240
|
+
if (c.indexOf(name) === 0) {
|
|
241
|
+
return c.substring(name.length, c.length);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return '';
|
|
245
|
+
}
|
|
246
|
+
catch (_a) {
|
|
247
|
+
return '';
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
const saveDataPerKey = (persistType, provider, value, key) => {
|
|
251
|
+
const storage = getData$1(persistType);
|
|
252
|
+
if (!storage['data']) {
|
|
253
|
+
storage['data'] = {};
|
|
254
|
+
}
|
|
255
|
+
if (!storage['data'][provider]) {
|
|
256
|
+
storage['data'][provider] = {};
|
|
257
|
+
}
|
|
258
|
+
storage['data'][provider][key] = value;
|
|
259
|
+
saveData(persistType, storage);
|
|
260
|
+
};
|
|
261
|
+
const savePerKey = (persistType, provider, value, key) => {
|
|
262
|
+
const storage = getData$1(persistType);
|
|
263
|
+
if (!storage[provider]) {
|
|
264
|
+
storage[provider] = {};
|
|
265
|
+
}
|
|
266
|
+
storage[provider][key] = value;
|
|
267
|
+
saveData(persistType, storage);
|
|
268
|
+
};
|
|
269
|
+
const getDataPerKey = (persistType, provider, key) => {
|
|
270
|
+
const storage = getData$1(persistType);
|
|
271
|
+
if (!storage[provider]) {
|
|
272
|
+
return undefined;
|
|
273
|
+
}
|
|
274
|
+
return storage[provider][key];
|
|
275
|
+
};
|
|
276
|
+
const saveData = (persistType, value, key = initKey) => {
|
|
277
|
+
if (persistType === 'session') {
|
|
278
|
+
saveSession(value, key);
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
saveLocal(value, key);
|
|
282
|
+
};
|
|
283
|
+
const getData$1 = (persistType, key = initKey) => {
|
|
284
|
+
if (persistType === 'session') {
|
|
285
|
+
return getSession(key);
|
|
286
|
+
}
|
|
287
|
+
return getLocal(key);
|
|
288
|
+
};
|
|
289
|
+
const saveKV = (data) => {
|
|
290
|
+
let currentSession = getData$1('session');
|
|
291
|
+
if (!currentSession) {
|
|
292
|
+
currentSession = {};
|
|
293
|
+
}
|
|
294
|
+
if (!currentSession['kv']) {
|
|
295
|
+
currentSession['kv'] = {};
|
|
296
|
+
}
|
|
297
|
+
currentSession['kv'] = Object.assign(Object.assign({}, currentSession['kv']), data);
|
|
298
|
+
saveData('session', currentSession);
|
|
299
|
+
};
|
|
300
|
+
const saveLocal = (value, key) => {
|
|
301
|
+
try {
|
|
302
|
+
if (!localStorage) {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
localStorage.setItem(key, JSON.stringify(value));
|
|
306
|
+
}
|
|
307
|
+
catch (_a) {
|
|
308
|
+
console.log('Local storage not supported');
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
const getLocal = (key) => {
|
|
312
|
+
try {
|
|
313
|
+
if (!localStorage) {
|
|
314
|
+
return {};
|
|
315
|
+
}
|
|
316
|
+
const data = localStorage.getItem(key);
|
|
317
|
+
if (!data) {
|
|
318
|
+
return {};
|
|
319
|
+
}
|
|
320
|
+
return JSON.parse(data) || {};
|
|
321
|
+
}
|
|
322
|
+
catch (_a) {
|
|
323
|
+
return {};
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
const saveSession = (value, key) => {
|
|
327
|
+
try {
|
|
328
|
+
if (!sessionStorage) {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
sessionStorage.setItem(key, JSON.stringify(value));
|
|
332
|
+
}
|
|
333
|
+
catch (_a) {
|
|
334
|
+
console.log('Session storage not supported');
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
const getSession = (key) => {
|
|
338
|
+
try {
|
|
339
|
+
if (!sessionStorage) {
|
|
340
|
+
return {};
|
|
341
|
+
}
|
|
342
|
+
const data = sessionStorage.getItem(key);
|
|
343
|
+
if (!data) {
|
|
344
|
+
return {};
|
|
345
|
+
}
|
|
346
|
+
return JSON.parse(data) || {};
|
|
347
|
+
}
|
|
348
|
+
catch (_a) {
|
|
349
|
+
return {};
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
let initUserId = '';
|
|
354
|
+
const handleGetUserId = () => {
|
|
355
|
+
if (initUserId) {
|
|
356
|
+
return initUserId;
|
|
357
|
+
}
|
|
358
|
+
return getCookieValue('tag_user_id');
|
|
359
|
+
};
|
|
360
|
+
const setUserId = (userId) => {
|
|
361
|
+
initUserId = userId;
|
|
362
|
+
};
|
|
363
|
+
|
|
342
364
|
const beacon = (url, payload) => {
|
|
343
365
|
let blob;
|
|
344
366
|
if (payload) {
|
|
@@ -352,6 +374,7 @@ const ajax = (method, url, payload) => __awaiter(void 0, void 0, void 0, functio
|
|
|
352
374
|
headers: {
|
|
353
375
|
'Content-type': 'application/json; charset=utf-8',
|
|
354
376
|
Accept: 'application/json; charset=utf-8',
|
|
377
|
+
EdgeTagUserId: handleGetUserId(),
|
|
355
378
|
},
|
|
356
379
|
body: JSON.stringify(payload),
|
|
357
380
|
credentials: 'include',
|
|
@@ -370,7 +393,14 @@ const ajax = (method, url, payload) => __awaiter(void 0, void 0, void 0, functio
|
|
|
370
393
|
});
|
|
371
394
|
});
|
|
372
395
|
const getStandardPayload = (payload) => {
|
|
373
|
-
|
|
396
|
+
let pageUrl;
|
|
397
|
+
try {
|
|
398
|
+
pageUrl = window.location.href;
|
|
399
|
+
}
|
|
400
|
+
catch (_a) {
|
|
401
|
+
pageUrl = '';
|
|
402
|
+
}
|
|
403
|
+
const data = Object.assign({ pageUrl, userAgent: getUserAgent() }, (payload || {}));
|
|
374
404
|
let storage = {};
|
|
375
405
|
const session = getData$1('session');
|
|
376
406
|
if (session) {
|
|
@@ -412,7 +442,9 @@ function getRequest(url, options) {
|
|
|
412
442
|
const info = (data) => {
|
|
413
443
|
};
|
|
414
444
|
|
|
445
|
+
let memoryConsent;
|
|
415
446
|
const saveConsent = (consent) => {
|
|
447
|
+
setConsent(consent);
|
|
416
448
|
savePerKey('local', tagStorage, consent, consentKey);
|
|
417
449
|
};
|
|
418
450
|
const handleConsent = (consent) => {
|
|
@@ -422,6 +454,16 @@ const handleConsent = (consent) => {
|
|
|
422
454
|
saveConsent(consent);
|
|
423
455
|
postRequest(getConsentURL(), payload).catch(info);
|
|
424
456
|
};
|
|
457
|
+
const setConsent = (newConsent) => {
|
|
458
|
+
memoryConsent = newConsent;
|
|
459
|
+
};
|
|
460
|
+
const getConsent = () => {
|
|
461
|
+
const storageConsent = getDataPerKey('local', tagStorage, consentKey);
|
|
462
|
+
if (storageConsent) {
|
|
463
|
+
return storageConsent;
|
|
464
|
+
}
|
|
465
|
+
return memoryConsent;
|
|
466
|
+
};
|
|
425
467
|
|
|
426
468
|
const generateEventId = (name) => {
|
|
427
469
|
let time = Date.now().toString();
|
|
@@ -435,10 +477,6 @@ const generateEventId = (name) => {
|
|
|
435
477
|
return `${btoa(name)}-${uuid.v4()}-${time}`;
|
|
436
478
|
};
|
|
437
479
|
|
|
438
|
-
const handleGetUserId = () => {
|
|
439
|
-
return getCookieValue('tag_user_id');
|
|
440
|
-
};
|
|
441
|
-
|
|
442
480
|
const manifestVariables = {};
|
|
443
481
|
const addProviderVariable = (name, variables) => {
|
|
444
482
|
manifestVariables[name] = variables;
|
|
@@ -457,6 +495,7 @@ const processStubs = () => {
|
|
|
457
495
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
458
496
|
// @ts-ignore
|
|
459
497
|
stubs.forEach((stub) => api[stub.name](...(stub.arguments || [])));
|
|
498
|
+
stubs = [];
|
|
460
499
|
}
|
|
461
500
|
catch (e) {
|
|
462
501
|
console.error(e);
|
|
@@ -465,6 +504,7 @@ const processStubs = () => {
|
|
|
465
504
|
|
|
466
505
|
const sendTag = ({ eventName, eventId, data, providerData, providers, options, }) => {
|
|
467
506
|
if (!allowProviders(providers)) {
|
|
507
|
+
console.log('Provider is not allowed.');
|
|
468
508
|
return;
|
|
469
509
|
}
|
|
470
510
|
const payload = {
|
|
@@ -487,6 +527,10 @@ const handleTag = (eventName, data = {}, providers, options) => {
|
|
|
487
527
|
});
|
|
488
528
|
return;
|
|
489
529
|
}
|
|
530
|
+
if (!allowProviders(providers)) {
|
|
531
|
+
console.log('Provider is not allowed.');
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
490
534
|
if (!allowTag(providers)) {
|
|
491
535
|
console.log('No consent');
|
|
492
536
|
return;
|
|
@@ -551,7 +595,12 @@ const saveDataToEdge = (key, value, provider) => {
|
|
|
551
595
|
handleData({ [`${provider}::${key}`]: value });
|
|
552
596
|
};
|
|
553
597
|
const handleCaptureQuery = (provider, key, persistType) => {
|
|
554
|
-
|
|
598
|
+
try {
|
|
599
|
+
if (!window) {
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
catch (_a) {
|
|
555
604
|
return;
|
|
556
605
|
}
|
|
557
606
|
const params = new URLSearchParams(window.location.search);
|
|
@@ -653,6 +702,7 @@ const handleInit = (preferences) => {
|
|
|
653
702
|
saveConsent({ all: true });
|
|
654
703
|
}
|
|
655
704
|
if (preferences.userId) {
|
|
705
|
+
setUserId(preferences.userId);
|
|
656
706
|
url.searchParams.set('userId', preferences.userId);
|
|
657
707
|
}
|
|
658
708
|
getRequest(url.href)
|
package/index.esm.js
CHANGED
|
@@ -37,132 +37,6 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
const tagStorage = 'edgeTag';
|
|
41
|
-
const consentKey = 'consent';
|
|
42
|
-
const keyPrefix = `_worker`;
|
|
43
|
-
|
|
44
|
-
const initKey = `${keyPrefix}Store`;
|
|
45
|
-
const getCookieValue = (key) => {
|
|
46
|
-
if (!document || !document.cookie) {
|
|
47
|
-
return '';
|
|
48
|
-
}
|
|
49
|
-
const name = `${key}=`;
|
|
50
|
-
const decodedCookie = decodeURIComponent(document.cookie);
|
|
51
|
-
const ca = decodedCookie.split(';');
|
|
52
|
-
for (let i = 0; i < ca.length; i++) {
|
|
53
|
-
let c = ca[i];
|
|
54
|
-
while (c.charAt(0) === ' ') {
|
|
55
|
-
c = c.substring(1);
|
|
56
|
-
}
|
|
57
|
-
if (c.indexOf(name) === 0) {
|
|
58
|
-
return c.substring(name.length, c.length);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return '';
|
|
62
|
-
};
|
|
63
|
-
const saveDataPerKey = (persistType, provider, value, key) => {
|
|
64
|
-
const storage = getData$1(persistType);
|
|
65
|
-
if (!storage['data']) {
|
|
66
|
-
storage['data'] = {};
|
|
67
|
-
}
|
|
68
|
-
if (!storage['data'][provider]) {
|
|
69
|
-
storage['data'][provider] = {};
|
|
70
|
-
}
|
|
71
|
-
storage['data'][provider][key] = value;
|
|
72
|
-
saveData(persistType, storage);
|
|
73
|
-
};
|
|
74
|
-
const savePerKey = (persistType, provider, value, key) => {
|
|
75
|
-
const storage = getData$1(persistType);
|
|
76
|
-
if (!storage[provider]) {
|
|
77
|
-
storage[provider] = {};
|
|
78
|
-
}
|
|
79
|
-
storage[provider][key] = value;
|
|
80
|
-
saveData(persistType, storage);
|
|
81
|
-
};
|
|
82
|
-
const getDataPerKey = (persistType, provider, key) => {
|
|
83
|
-
const storage = getData$1(persistType);
|
|
84
|
-
if (!storage[provider]) {
|
|
85
|
-
return undefined;
|
|
86
|
-
}
|
|
87
|
-
return storage[provider][key];
|
|
88
|
-
};
|
|
89
|
-
const saveData = (persistType, value, key = initKey) => {
|
|
90
|
-
if (persistType === 'session') {
|
|
91
|
-
saveSession(value, key);
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
saveLocal(value, key);
|
|
95
|
-
};
|
|
96
|
-
const getData$1 = (persistType, key = initKey) => {
|
|
97
|
-
if (persistType === 'session') {
|
|
98
|
-
return getSession(key);
|
|
99
|
-
}
|
|
100
|
-
return getLocal(key);
|
|
101
|
-
};
|
|
102
|
-
const saveKV = (data) => {
|
|
103
|
-
let currentSession = getData$1('session');
|
|
104
|
-
if (!currentSession) {
|
|
105
|
-
currentSession = {};
|
|
106
|
-
}
|
|
107
|
-
if (!currentSession['kv']) {
|
|
108
|
-
currentSession['kv'] = {};
|
|
109
|
-
}
|
|
110
|
-
currentSession['kv'] = Object.assign(Object.assign({}, currentSession['kv']), data);
|
|
111
|
-
saveData('session', currentSession);
|
|
112
|
-
};
|
|
113
|
-
const saveLocal = (value, key) => {
|
|
114
|
-
try {
|
|
115
|
-
if (!localStorage) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
localStorage.setItem(key, JSON.stringify(value));
|
|
119
|
-
}
|
|
120
|
-
catch (_a) {
|
|
121
|
-
console.log('Local storage not supported');
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
const getLocal = (key) => {
|
|
125
|
-
try {
|
|
126
|
-
if (!localStorage) {
|
|
127
|
-
return {};
|
|
128
|
-
}
|
|
129
|
-
const data = localStorage.getItem(key);
|
|
130
|
-
if (!data) {
|
|
131
|
-
return {};
|
|
132
|
-
}
|
|
133
|
-
return JSON.parse(data) || {};
|
|
134
|
-
}
|
|
135
|
-
catch (_a) {
|
|
136
|
-
return {};
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
const saveSession = (value, key) => {
|
|
140
|
-
try {
|
|
141
|
-
if (!sessionStorage) {
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
sessionStorage.setItem(key, JSON.stringify(value));
|
|
145
|
-
}
|
|
146
|
-
catch (_a) {
|
|
147
|
-
console.log('Session storage not supported');
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
const getSession = (key) => {
|
|
151
|
-
try {
|
|
152
|
-
if (!sessionStorage) {
|
|
153
|
-
return {};
|
|
154
|
-
}
|
|
155
|
-
const data = sessionStorage.getItem(key);
|
|
156
|
-
if (!data) {
|
|
157
|
-
return {};
|
|
158
|
-
}
|
|
159
|
-
return JSON.parse(data) || {};
|
|
160
|
-
}
|
|
161
|
-
catch (_a) {
|
|
162
|
-
return {};
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
|
|
166
40
|
let endpointUrl = '';
|
|
167
41
|
const generateUrl = (path) => {
|
|
168
42
|
const endpoint = getUrl();
|
|
@@ -223,13 +97,18 @@ const setPreferences = (preferences) => {
|
|
|
223
97
|
}
|
|
224
98
|
providersPackages[provider.name] = provider;
|
|
225
99
|
});
|
|
226
|
-
|
|
227
|
-
window.edgetagProviders
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
100
|
+
try {
|
|
101
|
+
if (window && Array.isArray(window.edgetagProviders)) {
|
|
102
|
+
window.edgetagProviders.forEach((provider) => {
|
|
103
|
+
if (!provider.name) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
providersPackages[provider.name] = provider;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
catch (_b) {
|
|
111
|
+
// do nothing
|
|
233
112
|
}
|
|
234
113
|
setUrl(preferences.edgeURL);
|
|
235
114
|
return true;
|
|
@@ -246,16 +125,21 @@ const setAllowedProviders = (providers) => {
|
|
|
246
125
|
};
|
|
247
126
|
|
|
248
127
|
const getUserAgent = () => {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
128
|
+
try {
|
|
129
|
+
const nav = navigator;
|
|
130
|
+
let ua = nav.userAgent;
|
|
131
|
+
ua += nav.brave ? `${ua} Brave` : '';
|
|
132
|
+
return ua;
|
|
133
|
+
}
|
|
134
|
+
catch (_a) {
|
|
135
|
+
return '';
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
const isProviderIncluded = (providers, providerValue) => {
|
|
139
|
+
return (providerValue || (providers['all'] === true && providerValue === undefined));
|
|
253
140
|
};
|
|
254
141
|
const allowTag = (providers) => {
|
|
255
|
-
|
|
256
|
-
return false;
|
|
257
|
-
}
|
|
258
|
-
const consent = getDataPerKey('local', tagStorage, consentKey);
|
|
142
|
+
const consent = getConsent();
|
|
259
143
|
if (isConsentDisabled()) {
|
|
260
144
|
return true;
|
|
261
145
|
}
|
|
@@ -270,19 +154,15 @@ const allowTag = (providers) => {
|
|
|
270
154
|
}
|
|
271
155
|
const allProviders = getAllowedProviders();
|
|
272
156
|
for (const provider of allProviders) {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
(providers['all'] === false && tagProviderSetting === true)) {
|
|
277
|
-
if (consent[provider]) {
|
|
278
|
-
return true;
|
|
279
|
-
}
|
|
157
|
+
if (isProviderIncluded(providers, !!providers[provider]) &&
|
|
158
|
+
consent[provider]) {
|
|
159
|
+
return true;
|
|
280
160
|
}
|
|
281
161
|
}
|
|
282
162
|
return false;
|
|
283
163
|
};
|
|
284
164
|
const allowProviders = (providers) => {
|
|
285
|
-
if (!providers || Object.keys(providers).length === 0) {
|
|
165
|
+
if (!providers || Object.keys(providers).length === 0 || providers['all']) {
|
|
286
166
|
return true;
|
|
287
167
|
}
|
|
288
168
|
const allowedProvider = getAllowedProviders();
|
|
@@ -322,7 +202,7 @@ const allowProviderWithConsent = (providers, providerId) => {
|
|
|
322
202
|
return false;
|
|
323
203
|
}
|
|
324
204
|
}
|
|
325
|
-
const consent =
|
|
205
|
+
const consent = getConsent();
|
|
326
206
|
if (isConsentDisabled()) {
|
|
327
207
|
return true;
|
|
328
208
|
}
|
|
@@ -335,6 +215,148 @@ const allowProviderWithConsent = (providers, providerId) => {
|
|
|
335
215
|
return consent[providerId];
|
|
336
216
|
};
|
|
337
217
|
|
|
218
|
+
const tagStorage = 'edgeTag';
|
|
219
|
+
const consentKey = 'consent';
|
|
220
|
+
const keyPrefix = `_worker`;
|
|
221
|
+
|
|
222
|
+
const initKey = `${keyPrefix}Store`;
|
|
223
|
+
const getCookieValue = (key) => {
|
|
224
|
+
try {
|
|
225
|
+
if (!document || !document.cookie) {
|
|
226
|
+
return '';
|
|
227
|
+
}
|
|
228
|
+
const name = `${key}=`;
|
|
229
|
+
const decodedCookie = decodeURIComponent(document.cookie);
|
|
230
|
+
const ca = decodedCookie.split(';');
|
|
231
|
+
for (let i = 0; i < ca.length; i++) {
|
|
232
|
+
let c = ca[i];
|
|
233
|
+
while (c.charAt(0) === ' ') {
|
|
234
|
+
c = c.substring(1);
|
|
235
|
+
}
|
|
236
|
+
if (c.indexOf(name) === 0) {
|
|
237
|
+
return c.substring(name.length, c.length);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return '';
|
|
241
|
+
}
|
|
242
|
+
catch (_a) {
|
|
243
|
+
return '';
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
const saveDataPerKey = (persistType, provider, value, key) => {
|
|
247
|
+
const storage = getData$1(persistType);
|
|
248
|
+
if (!storage['data']) {
|
|
249
|
+
storage['data'] = {};
|
|
250
|
+
}
|
|
251
|
+
if (!storage['data'][provider]) {
|
|
252
|
+
storage['data'][provider] = {};
|
|
253
|
+
}
|
|
254
|
+
storage['data'][provider][key] = value;
|
|
255
|
+
saveData(persistType, storage);
|
|
256
|
+
};
|
|
257
|
+
const savePerKey = (persistType, provider, value, key) => {
|
|
258
|
+
const storage = getData$1(persistType);
|
|
259
|
+
if (!storage[provider]) {
|
|
260
|
+
storage[provider] = {};
|
|
261
|
+
}
|
|
262
|
+
storage[provider][key] = value;
|
|
263
|
+
saveData(persistType, storage);
|
|
264
|
+
};
|
|
265
|
+
const getDataPerKey = (persistType, provider, key) => {
|
|
266
|
+
const storage = getData$1(persistType);
|
|
267
|
+
if (!storage[provider]) {
|
|
268
|
+
return undefined;
|
|
269
|
+
}
|
|
270
|
+
return storage[provider][key];
|
|
271
|
+
};
|
|
272
|
+
const saveData = (persistType, value, key = initKey) => {
|
|
273
|
+
if (persistType === 'session') {
|
|
274
|
+
saveSession(value, key);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
saveLocal(value, key);
|
|
278
|
+
};
|
|
279
|
+
const getData$1 = (persistType, key = initKey) => {
|
|
280
|
+
if (persistType === 'session') {
|
|
281
|
+
return getSession(key);
|
|
282
|
+
}
|
|
283
|
+
return getLocal(key);
|
|
284
|
+
};
|
|
285
|
+
const saveKV = (data) => {
|
|
286
|
+
let currentSession = getData$1('session');
|
|
287
|
+
if (!currentSession) {
|
|
288
|
+
currentSession = {};
|
|
289
|
+
}
|
|
290
|
+
if (!currentSession['kv']) {
|
|
291
|
+
currentSession['kv'] = {};
|
|
292
|
+
}
|
|
293
|
+
currentSession['kv'] = Object.assign(Object.assign({}, currentSession['kv']), data);
|
|
294
|
+
saveData('session', currentSession);
|
|
295
|
+
};
|
|
296
|
+
const saveLocal = (value, key) => {
|
|
297
|
+
try {
|
|
298
|
+
if (!localStorage) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
localStorage.setItem(key, JSON.stringify(value));
|
|
302
|
+
}
|
|
303
|
+
catch (_a) {
|
|
304
|
+
console.log('Local storage not supported');
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
const getLocal = (key) => {
|
|
308
|
+
try {
|
|
309
|
+
if (!localStorage) {
|
|
310
|
+
return {};
|
|
311
|
+
}
|
|
312
|
+
const data = localStorage.getItem(key);
|
|
313
|
+
if (!data) {
|
|
314
|
+
return {};
|
|
315
|
+
}
|
|
316
|
+
return JSON.parse(data) || {};
|
|
317
|
+
}
|
|
318
|
+
catch (_a) {
|
|
319
|
+
return {};
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
const saveSession = (value, key) => {
|
|
323
|
+
try {
|
|
324
|
+
if (!sessionStorage) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
sessionStorage.setItem(key, JSON.stringify(value));
|
|
328
|
+
}
|
|
329
|
+
catch (_a) {
|
|
330
|
+
console.log('Session storage not supported');
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
const getSession = (key) => {
|
|
334
|
+
try {
|
|
335
|
+
if (!sessionStorage) {
|
|
336
|
+
return {};
|
|
337
|
+
}
|
|
338
|
+
const data = sessionStorage.getItem(key);
|
|
339
|
+
if (!data) {
|
|
340
|
+
return {};
|
|
341
|
+
}
|
|
342
|
+
return JSON.parse(data) || {};
|
|
343
|
+
}
|
|
344
|
+
catch (_a) {
|
|
345
|
+
return {};
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
let initUserId = '';
|
|
350
|
+
const handleGetUserId = () => {
|
|
351
|
+
if (initUserId) {
|
|
352
|
+
return initUserId;
|
|
353
|
+
}
|
|
354
|
+
return getCookieValue('tag_user_id');
|
|
355
|
+
};
|
|
356
|
+
const setUserId = (userId) => {
|
|
357
|
+
initUserId = userId;
|
|
358
|
+
};
|
|
359
|
+
|
|
338
360
|
const beacon = (url, payload) => {
|
|
339
361
|
let blob;
|
|
340
362
|
if (payload) {
|
|
@@ -348,6 +370,7 @@ const ajax = (method, url, payload) => __awaiter(void 0, void 0, void 0, functio
|
|
|
348
370
|
headers: {
|
|
349
371
|
'Content-type': 'application/json; charset=utf-8',
|
|
350
372
|
Accept: 'application/json; charset=utf-8',
|
|
373
|
+
EdgeTagUserId: handleGetUserId(),
|
|
351
374
|
},
|
|
352
375
|
body: JSON.stringify(payload),
|
|
353
376
|
credentials: 'include',
|
|
@@ -366,7 +389,14 @@ const ajax = (method, url, payload) => __awaiter(void 0, void 0, void 0, functio
|
|
|
366
389
|
});
|
|
367
390
|
});
|
|
368
391
|
const getStandardPayload = (payload) => {
|
|
369
|
-
|
|
392
|
+
let pageUrl;
|
|
393
|
+
try {
|
|
394
|
+
pageUrl = window.location.href;
|
|
395
|
+
}
|
|
396
|
+
catch (_a) {
|
|
397
|
+
pageUrl = '';
|
|
398
|
+
}
|
|
399
|
+
const data = Object.assign({ pageUrl, userAgent: getUserAgent() }, (payload || {}));
|
|
370
400
|
let storage = {};
|
|
371
401
|
const session = getData$1('session');
|
|
372
402
|
if (session) {
|
|
@@ -408,7 +438,9 @@ function getRequest(url, options) {
|
|
|
408
438
|
const info = (data) => {
|
|
409
439
|
};
|
|
410
440
|
|
|
441
|
+
let memoryConsent;
|
|
411
442
|
const saveConsent = (consent) => {
|
|
443
|
+
setConsent(consent);
|
|
412
444
|
savePerKey('local', tagStorage, consent, consentKey);
|
|
413
445
|
};
|
|
414
446
|
const handleConsent = (consent) => {
|
|
@@ -418,6 +450,16 @@ const handleConsent = (consent) => {
|
|
|
418
450
|
saveConsent(consent);
|
|
419
451
|
postRequest(getConsentURL(), payload).catch(info);
|
|
420
452
|
};
|
|
453
|
+
const setConsent = (newConsent) => {
|
|
454
|
+
memoryConsent = newConsent;
|
|
455
|
+
};
|
|
456
|
+
const getConsent = () => {
|
|
457
|
+
const storageConsent = getDataPerKey('local', tagStorage, consentKey);
|
|
458
|
+
if (storageConsent) {
|
|
459
|
+
return storageConsent;
|
|
460
|
+
}
|
|
461
|
+
return memoryConsent;
|
|
462
|
+
};
|
|
421
463
|
|
|
422
464
|
const generateEventId = (name) => {
|
|
423
465
|
let time = Date.now().toString();
|
|
@@ -431,10 +473,6 @@ const generateEventId = (name) => {
|
|
|
431
473
|
return `${btoa(name)}-${v4()}-${time}`;
|
|
432
474
|
};
|
|
433
475
|
|
|
434
|
-
const handleGetUserId = () => {
|
|
435
|
-
return getCookieValue('tag_user_id');
|
|
436
|
-
};
|
|
437
|
-
|
|
438
476
|
const manifestVariables = {};
|
|
439
477
|
const addProviderVariable = (name, variables) => {
|
|
440
478
|
manifestVariables[name] = variables;
|
|
@@ -453,6 +491,7 @@ const processStubs = () => {
|
|
|
453
491
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
454
492
|
// @ts-ignore
|
|
455
493
|
stubs.forEach((stub) => api[stub.name](...(stub.arguments || [])));
|
|
494
|
+
stubs = [];
|
|
456
495
|
}
|
|
457
496
|
catch (e) {
|
|
458
497
|
console.error(e);
|
|
@@ -461,6 +500,7 @@ const processStubs = () => {
|
|
|
461
500
|
|
|
462
501
|
const sendTag = ({ eventName, eventId, data, providerData, providers, options, }) => {
|
|
463
502
|
if (!allowProviders(providers)) {
|
|
503
|
+
console.log('Provider is not allowed.');
|
|
464
504
|
return;
|
|
465
505
|
}
|
|
466
506
|
const payload = {
|
|
@@ -483,6 +523,10 @@ const handleTag = (eventName, data = {}, providers, options) => {
|
|
|
483
523
|
});
|
|
484
524
|
return;
|
|
485
525
|
}
|
|
526
|
+
if (!allowProviders(providers)) {
|
|
527
|
+
console.log('Provider is not allowed.');
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
486
530
|
if (!allowTag(providers)) {
|
|
487
531
|
console.log('No consent');
|
|
488
532
|
return;
|
|
@@ -547,7 +591,12 @@ const saveDataToEdge = (key, value, provider) => {
|
|
|
547
591
|
handleData({ [`${provider}::${key}`]: value });
|
|
548
592
|
};
|
|
549
593
|
const handleCaptureQuery = (provider, key, persistType) => {
|
|
550
|
-
|
|
594
|
+
try {
|
|
595
|
+
if (!window) {
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
catch (_a) {
|
|
551
600
|
return;
|
|
552
601
|
}
|
|
553
602
|
const params = new URLSearchParams(window.location.search);
|
|
@@ -649,6 +698,7 @@ const handleInit = (preferences) => {
|
|
|
649
698
|
saveConsent({ all: true });
|
|
650
699
|
}
|
|
651
700
|
if (preferences.userId) {
|
|
701
|
+
setUserId(preferences.userId);
|
|
652
702
|
url.searchParams.set('userId', preferences.userId);
|
|
653
703
|
}
|
|
654
704
|
getRequest(url.href)
|