@blotoutio/edgetag-sdk-js 0.6.5 → 0.6.7
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 +99 -13
- package/index.d.ts +3 -0
- package/index.esm.js +99 -13
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -4,6 +4,18 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var uuid = require('uuid');
|
|
6
6
|
|
|
7
|
+
var api = /*#__PURE__*/Object.freeze({
|
|
8
|
+
__proto__: null,
|
|
9
|
+
get init () { return init; },
|
|
10
|
+
get tag () { return tag; },
|
|
11
|
+
get consent () { return consent; },
|
|
12
|
+
get user () { return user; },
|
|
13
|
+
get data () { return data; },
|
|
14
|
+
get getData () { return getData; },
|
|
15
|
+
get keys () { return keys; },
|
|
16
|
+
get getUserId () { return getUserId; }
|
|
17
|
+
});
|
|
18
|
+
|
|
7
19
|
/******************************************************************************
|
|
8
20
|
Copyright (c) Microsoft Corporation.
|
|
9
21
|
|
|
@@ -31,7 +43,6 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
31
43
|
|
|
32
44
|
const tagStorage = 'edgeTag';
|
|
33
45
|
const consentKey = 'consent';
|
|
34
|
-
const providersKey = 'providers';
|
|
35
46
|
const keyPrefix = `_worker`;
|
|
36
47
|
|
|
37
48
|
const initKey = `${keyPrefix}Store`;
|
|
@@ -196,8 +207,10 @@ const getKeysURL = () => {
|
|
|
196
207
|
return generateUrl(`/keys`);
|
|
197
208
|
};
|
|
198
209
|
|
|
210
|
+
let allowedProvider = [];
|
|
211
|
+
let initialized = false;
|
|
199
212
|
let consentDisabled = false;
|
|
200
|
-
const
|
|
213
|
+
const providersPackages = {};
|
|
201
214
|
const setPreferences = (preferences) => {
|
|
202
215
|
var _a;
|
|
203
216
|
if (!preferences) {
|
|
@@ -212,21 +225,29 @@ const setPreferences = (preferences) => {
|
|
|
212
225
|
if (!provider.name) {
|
|
213
226
|
return;
|
|
214
227
|
}
|
|
215
|
-
|
|
228
|
+
providersPackages[provider.name] = provider;
|
|
216
229
|
});
|
|
217
230
|
if (window && Array.isArray(window.edgetagProviders)) {
|
|
218
231
|
window.edgetagProviders.forEach((provider) => {
|
|
219
232
|
if (!provider.name) {
|
|
220
233
|
return;
|
|
221
234
|
}
|
|
222
|
-
|
|
235
|
+
providersPackages[provider.name] = provider;
|
|
223
236
|
});
|
|
224
237
|
}
|
|
225
238
|
setUrl(preferences.edgeURL);
|
|
226
239
|
return true;
|
|
227
240
|
};
|
|
228
241
|
const isConsentDisabled = () => consentDisabled;
|
|
229
|
-
const getProvidersPackage = () =>
|
|
242
|
+
const getProvidersPackage = () => providersPackages;
|
|
243
|
+
const isInitialized = () => initialized;
|
|
244
|
+
const setInitialized = () => {
|
|
245
|
+
initialized = true;
|
|
246
|
+
};
|
|
247
|
+
const getAllowedProviders = () => allowedProvider;
|
|
248
|
+
const setAllowedProviders = (providers) => {
|
|
249
|
+
allowedProvider = providers;
|
|
250
|
+
};
|
|
230
251
|
|
|
231
252
|
const getUserAgent = () => {
|
|
232
253
|
const nav = navigator;
|
|
@@ -235,6 +256,9 @@ const getUserAgent = () => {
|
|
|
235
256
|
return ua;
|
|
236
257
|
};
|
|
237
258
|
const allowTag = (providers) => {
|
|
259
|
+
if (!allowProviders(providers)) {
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
238
262
|
const consent = getDataPerKey('local', tagStorage, consentKey);
|
|
239
263
|
if (isConsentDisabled()) {
|
|
240
264
|
return true;
|
|
@@ -248,8 +272,7 @@ const allowTag = (providers) => {
|
|
|
248
272
|
if (!providers) {
|
|
249
273
|
return (Object.values(consent).find((isAllowed) => isAllowed) || false);
|
|
250
274
|
}
|
|
251
|
-
const allProviders = (
|
|
252
|
-
[]);
|
|
275
|
+
const allProviders = getAllowedProviders();
|
|
253
276
|
for (const provider of allProviders) {
|
|
254
277
|
const tagProviderSetting = providers[provider];
|
|
255
278
|
if (tagProviderSetting ||
|
|
@@ -262,7 +285,39 @@ const allowTag = (providers) => {
|
|
|
262
285
|
}
|
|
263
286
|
return false;
|
|
264
287
|
};
|
|
265
|
-
const
|
|
288
|
+
const allowProviders = (providers) => {
|
|
289
|
+
if (!providers) {
|
|
290
|
+
return true;
|
|
291
|
+
}
|
|
292
|
+
const allowedProvider = getAllowedProviders();
|
|
293
|
+
if (allowedProvider && allowedProvider.length > 0) {
|
|
294
|
+
let found = false;
|
|
295
|
+
Object.entries(providers).forEach(([key, value]) => {
|
|
296
|
+
if (!value) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
if (allowedProvider.includes(key)) {
|
|
300
|
+
found = true;
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
return found;
|
|
304
|
+
}
|
|
305
|
+
return true;
|
|
306
|
+
};
|
|
307
|
+
const allowProvider = (providerId) => {
|
|
308
|
+
if (!providerId) {
|
|
309
|
+
return true;
|
|
310
|
+
}
|
|
311
|
+
const allowedProvider = getAllowedProviders();
|
|
312
|
+
if (allowedProvider && allowedProvider.length > 0) {
|
|
313
|
+
return allowedProvider.includes(providerId);
|
|
314
|
+
}
|
|
315
|
+
return true;
|
|
316
|
+
};
|
|
317
|
+
const allowProviderWithConsent = (providers, providerId) => {
|
|
318
|
+
if (!allowProvider(providerId)) {
|
|
319
|
+
return false;
|
|
320
|
+
}
|
|
266
321
|
if (providers && Object.keys(providers).length) {
|
|
267
322
|
const tagProvider = providers[providerId];
|
|
268
323
|
if (!(tagProvider ||
|
|
@@ -390,7 +445,28 @@ const addProviderVariable = (name, variables) => {
|
|
|
390
445
|
};
|
|
391
446
|
const getProviderVariables = (name) => manifestVariables[name] || {};
|
|
392
447
|
|
|
448
|
+
let stubs = [];
|
|
449
|
+
const addStubs = (newStubs) => {
|
|
450
|
+
stubs = [...stubs, ...newStubs];
|
|
451
|
+
};
|
|
452
|
+
const addStub = (stub) => {
|
|
453
|
+
stubs.push(stub);
|
|
454
|
+
};
|
|
455
|
+
const processStubs = () => {
|
|
456
|
+
try {
|
|
457
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
458
|
+
// @ts-ignore
|
|
459
|
+
stubs.forEach((stub) => api[stub.name](...(stub.arguments || [])));
|
|
460
|
+
}
|
|
461
|
+
catch (e) {
|
|
462
|
+
console.error(e);
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
|
|
393
466
|
const sendTag = ({ eventName, eventId, data, providerData, providers, options, }) => {
|
|
467
|
+
if (!allowProviders(providers)) {
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
394
470
|
const payload = {
|
|
395
471
|
eventName,
|
|
396
472
|
eventId,
|
|
@@ -404,6 +480,13 @@ const sendTag = ({ eventName, eventId, data, providerData, providers, options, }
|
|
|
404
480
|
postRequest(getTagURL(), payload, options).catch(info);
|
|
405
481
|
};
|
|
406
482
|
const handleTag = (eventName, data = {}, providers, options) => {
|
|
483
|
+
if (!isInitialized()) {
|
|
484
|
+
addStub({
|
|
485
|
+
name: 'tag',
|
|
486
|
+
arguments: [eventName, data, providers, options],
|
|
487
|
+
});
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
407
490
|
if (!allowTag(providers)) {
|
|
408
491
|
console.log('No consent');
|
|
409
492
|
return;
|
|
@@ -417,7 +500,7 @@ const handleTag = (eventName, data = {}, providers, options) => {
|
|
|
417
500
|
const providerData = {};
|
|
418
501
|
if (providerPackages) {
|
|
419
502
|
Object.values(providerPackages).forEach((pkg) => {
|
|
420
|
-
if (!pkg || !pkg.tag || !
|
|
503
|
+
if (!pkg || !pkg.tag || !allowProviderWithConsent(providers, pkg.name)) {
|
|
421
504
|
return;
|
|
422
505
|
}
|
|
423
506
|
const result = pkg.tag({
|
|
@@ -525,11 +608,10 @@ const handleCapture = (provider, params) => {
|
|
|
525
608
|
};
|
|
526
609
|
|
|
527
610
|
const handleManifest = (manifest) => {
|
|
528
|
-
const providers = [];
|
|
529
611
|
const providerPackages = getProvidersPackage();
|
|
530
612
|
const userId = handleGetUserId();
|
|
613
|
+
setAllowedProviders(manifest.map((provider) => provider.package));
|
|
531
614
|
manifest.forEach((provider) => {
|
|
532
|
-
providers.push(provider.package);
|
|
533
615
|
addProviderVariable(provider.package, provider.variables);
|
|
534
616
|
if (provider.rules) {
|
|
535
617
|
Object.entries(provider.rules).forEach(([name, recipe]) => {
|
|
@@ -543,12 +625,13 @@ const handleManifest = (manifest) => {
|
|
|
543
625
|
}
|
|
544
626
|
if (providerPackages) {
|
|
545
627
|
const pkg = providerPackages[provider.package];
|
|
546
|
-
if (pkg && pkg.init) {
|
|
628
|
+
if (pkg && pkg.init && allowProvider(pkg.name)) {
|
|
547
629
|
pkg.init({ userId, manifest: provider, sendTag });
|
|
548
630
|
}
|
|
549
631
|
}
|
|
550
632
|
});
|
|
551
|
-
|
|
633
|
+
setInitialized();
|
|
634
|
+
processStubs();
|
|
552
635
|
};
|
|
553
636
|
|
|
554
637
|
const handleInit = (preferences) => {
|
|
@@ -556,6 +639,9 @@ const handleInit = (preferences) => {
|
|
|
556
639
|
if (!success) {
|
|
557
640
|
return;
|
|
558
641
|
}
|
|
642
|
+
if (preferences.afterManifestEvents) {
|
|
643
|
+
addStubs(preferences.afterManifestEvents);
|
|
644
|
+
}
|
|
559
645
|
const url = new URL(getInitURL());
|
|
560
646
|
if (preferences.disableConsentCheck) {
|
|
561
647
|
url.searchParams.set('consentDisabled', 'true');
|
package/index.d.ts
CHANGED
|
@@ -66,11 +66,14 @@ type UserKey =
|
|
|
66
66
|
| 'zip'
|
|
67
67
|
| 'address'
|
|
68
68
|
|
|
69
|
+
type Stub = { name: string; arguments: unknown[] }
|
|
70
|
+
|
|
69
71
|
type InitPreferences = {
|
|
70
72
|
edgeURL: string
|
|
71
73
|
disableConsentCheck?: boolean
|
|
72
74
|
userId?: string
|
|
73
75
|
providers?: ProviderInit[]
|
|
76
|
+
afterManifestEvents?: Stub[]
|
|
74
77
|
}
|
|
75
78
|
|
|
76
79
|
export declare const init: (preferences: InitPreferences) => void
|
package/index.esm.js
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import { v4 } from 'uuid';
|
|
2
2
|
|
|
3
|
+
var api = /*#__PURE__*/Object.freeze({
|
|
4
|
+
__proto__: null,
|
|
5
|
+
get init () { return init; },
|
|
6
|
+
get tag () { return tag; },
|
|
7
|
+
get consent () { return consent; },
|
|
8
|
+
get user () { return user; },
|
|
9
|
+
get data () { return data; },
|
|
10
|
+
get getData () { return getData; },
|
|
11
|
+
get keys () { return keys; },
|
|
12
|
+
get getUserId () { return getUserId; }
|
|
13
|
+
});
|
|
14
|
+
|
|
3
15
|
/******************************************************************************
|
|
4
16
|
Copyright (c) Microsoft Corporation.
|
|
5
17
|
|
|
@@ -27,7 +39,6 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
27
39
|
|
|
28
40
|
const tagStorage = 'edgeTag';
|
|
29
41
|
const consentKey = 'consent';
|
|
30
|
-
const providersKey = 'providers';
|
|
31
42
|
const keyPrefix = `_worker`;
|
|
32
43
|
|
|
33
44
|
const initKey = `${keyPrefix}Store`;
|
|
@@ -192,8 +203,10 @@ const getKeysURL = () => {
|
|
|
192
203
|
return generateUrl(`/keys`);
|
|
193
204
|
};
|
|
194
205
|
|
|
206
|
+
let allowedProvider = [];
|
|
207
|
+
let initialized = false;
|
|
195
208
|
let consentDisabled = false;
|
|
196
|
-
const
|
|
209
|
+
const providersPackages = {};
|
|
197
210
|
const setPreferences = (preferences) => {
|
|
198
211
|
var _a;
|
|
199
212
|
if (!preferences) {
|
|
@@ -208,21 +221,29 @@ const setPreferences = (preferences) => {
|
|
|
208
221
|
if (!provider.name) {
|
|
209
222
|
return;
|
|
210
223
|
}
|
|
211
|
-
|
|
224
|
+
providersPackages[provider.name] = provider;
|
|
212
225
|
});
|
|
213
226
|
if (window && Array.isArray(window.edgetagProviders)) {
|
|
214
227
|
window.edgetagProviders.forEach((provider) => {
|
|
215
228
|
if (!provider.name) {
|
|
216
229
|
return;
|
|
217
230
|
}
|
|
218
|
-
|
|
231
|
+
providersPackages[provider.name] = provider;
|
|
219
232
|
});
|
|
220
233
|
}
|
|
221
234
|
setUrl(preferences.edgeURL);
|
|
222
235
|
return true;
|
|
223
236
|
};
|
|
224
237
|
const isConsentDisabled = () => consentDisabled;
|
|
225
|
-
const getProvidersPackage = () =>
|
|
238
|
+
const getProvidersPackage = () => providersPackages;
|
|
239
|
+
const isInitialized = () => initialized;
|
|
240
|
+
const setInitialized = () => {
|
|
241
|
+
initialized = true;
|
|
242
|
+
};
|
|
243
|
+
const getAllowedProviders = () => allowedProvider;
|
|
244
|
+
const setAllowedProviders = (providers) => {
|
|
245
|
+
allowedProvider = providers;
|
|
246
|
+
};
|
|
226
247
|
|
|
227
248
|
const getUserAgent = () => {
|
|
228
249
|
const nav = navigator;
|
|
@@ -231,6 +252,9 @@ const getUserAgent = () => {
|
|
|
231
252
|
return ua;
|
|
232
253
|
};
|
|
233
254
|
const allowTag = (providers) => {
|
|
255
|
+
if (!allowProviders(providers)) {
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
234
258
|
const consent = getDataPerKey('local', tagStorage, consentKey);
|
|
235
259
|
if (isConsentDisabled()) {
|
|
236
260
|
return true;
|
|
@@ -244,8 +268,7 @@ const allowTag = (providers) => {
|
|
|
244
268
|
if (!providers) {
|
|
245
269
|
return (Object.values(consent).find((isAllowed) => isAllowed) || false);
|
|
246
270
|
}
|
|
247
|
-
const allProviders = (
|
|
248
|
-
[]);
|
|
271
|
+
const allProviders = getAllowedProviders();
|
|
249
272
|
for (const provider of allProviders) {
|
|
250
273
|
const tagProviderSetting = providers[provider];
|
|
251
274
|
if (tagProviderSetting ||
|
|
@@ -258,7 +281,39 @@ const allowTag = (providers) => {
|
|
|
258
281
|
}
|
|
259
282
|
return false;
|
|
260
283
|
};
|
|
261
|
-
const
|
|
284
|
+
const allowProviders = (providers) => {
|
|
285
|
+
if (!providers) {
|
|
286
|
+
return true;
|
|
287
|
+
}
|
|
288
|
+
const allowedProvider = getAllowedProviders();
|
|
289
|
+
if (allowedProvider && allowedProvider.length > 0) {
|
|
290
|
+
let found = false;
|
|
291
|
+
Object.entries(providers).forEach(([key, value]) => {
|
|
292
|
+
if (!value) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
if (allowedProvider.includes(key)) {
|
|
296
|
+
found = true;
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
return found;
|
|
300
|
+
}
|
|
301
|
+
return true;
|
|
302
|
+
};
|
|
303
|
+
const allowProvider = (providerId) => {
|
|
304
|
+
if (!providerId) {
|
|
305
|
+
return true;
|
|
306
|
+
}
|
|
307
|
+
const allowedProvider = getAllowedProviders();
|
|
308
|
+
if (allowedProvider && allowedProvider.length > 0) {
|
|
309
|
+
return allowedProvider.includes(providerId);
|
|
310
|
+
}
|
|
311
|
+
return true;
|
|
312
|
+
};
|
|
313
|
+
const allowProviderWithConsent = (providers, providerId) => {
|
|
314
|
+
if (!allowProvider(providerId)) {
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
262
317
|
if (providers && Object.keys(providers).length) {
|
|
263
318
|
const tagProvider = providers[providerId];
|
|
264
319
|
if (!(tagProvider ||
|
|
@@ -386,7 +441,28 @@ const addProviderVariable = (name, variables) => {
|
|
|
386
441
|
};
|
|
387
442
|
const getProviderVariables = (name) => manifestVariables[name] || {};
|
|
388
443
|
|
|
444
|
+
let stubs = [];
|
|
445
|
+
const addStubs = (newStubs) => {
|
|
446
|
+
stubs = [...stubs, ...newStubs];
|
|
447
|
+
};
|
|
448
|
+
const addStub = (stub) => {
|
|
449
|
+
stubs.push(stub);
|
|
450
|
+
};
|
|
451
|
+
const processStubs = () => {
|
|
452
|
+
try {
|
|
453
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
454
|
+
// @ts-ignore
|
|
455
|
+
stubs.forEach((stub) => api[stub.name](...(stub.arguments || [])));
|
|
456
|
+
}
|
|
457
|
+
catch (e) {
|
|
458
|
+
console.error(e);
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
|
|
389
462
|
const sendTag = ({ eventName, eventId, data, providerData, providers, options, }) => {
|
|
463
|
+
if (!allowProviders(providers)) {
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
390
466
|
const payload = {
|
|
391
467
|
eventName,
|
|
392
468
|
eventId,
|
|
@@ -400,6 +476,13 @@ const sendTag = ({ eventName, eventId, data, providerData, providers, options, }
|
|
|
400
476
|
postRequest(getTagURL(), payload, options).catch(info);
|
|
401
477
|
};
|
|
402
478
|
const handleTag = (eventName, data = {}, providers, options) => {
|
|
479
|
+
if (!isInitialized()) {
|
|
480
|
+
addStub({
|
|
481
|
+
name: 'tag',
|
|
482
|
+
arguments: [eventName, data, providers, options],
|
|
483
|
+
});
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
403
486
|
if (!allowTag(providers)) {
|
|
404
487
|
console.log('No consent');
|
|
405
488
|
return;
|
|
@@ -413,7 +496,7 @@ const handleTag = (eventName, data = {}, providers, options) => {
|
|
|
413
496
|
const providerData = {};
|
|
414
497
|
if (providerPackages) {
|
|
415
498
|
Object.values(providerPackages).forEach((pkg) => {
|
|
416
|
-
if (!pkg || !pkg.tag || !
|
|
499
|
+
if (!pkg || !pkg.tag || !allowProviderWithConsent(providers, pkg.name)) {
|
|
417
500
|
return;
|
|
418
501
|
}
|
|
419
502
|
const result = pkg.tag({
|
|
@@ -521,11 +604,10 @@ const handleCapture = (provider, params) => {
|
|
|
521
604
|
};
|
|
522
605
|
|
|
523
606
|
const handleManifest = (manifest) => {
|
|
524
|
-
const providers = [];
|
|
525
607
|
const providerPackages = getProvidersPackage();
|
|
526
608
|
const userId = handleGetUserId();
|
|
609
|
+
setAllowedProviders(manifest.map((provider) => provider.package));
|
|
527
610
|
manifest.forEach((provider) => {
|
|
528
|
-
providers.push(provider.package);
|
|
529
611
|
addProviderVariable(provider.package, provider.variables);
|
|
530
612
|
if (provider.rules) {
|
|
531
613
|
Object.entries(provider.rules).forEach(([name, recipe]) => {
|
|
@@ -539,12 +621,13 @@ const handleManifest = (manifest) => {
|
|
|
539
621
|
}
|
|
540
622
|
if (providerPackages) {
|
|
541
623
|
const pkg = providerPackages[provider.package];
|
|
542
|
-
if (pkg && pkg.init) {
|
|
624
|
+
if (pkg && pkg.init && allowProvider(pkg.name)) {
|
|
543
625
|
pkg.init({ userId, manifest: provider, sendTag });
|
|
544
626
|
}
|
|
545
627
|
}
|
|
546
628
|
});
|
|
547
|
-
|
|
629
|
+
setInitialized();
|
|
630
|
+
processStubs();
|
|
548
631
|
};
|
|
549
632
|
|
|
550
633
|
const handleInit = (preferences) => {
|
|
@@ -552,6 +635,9 @@ const handleInit = (preferences) => {
|
|
|
552
635
|
if (!success) {
|
|
553
636
|
return;
|
|
554
637
|
}
|
|
638
|
+
if (preferences.afterManifestEvents) {
|
|
639
|
+
addStubs(preferences.afterManifestEvents);
|
|
640
|
+
}
|
|
555
641
|
const url = new URL(getInitURL());
|
|
556
642
|
if (preferences.disableConsentCheck) {
|
|
557
643
|
url.searchParams.set('consentDisabled', 'true');
|