@blotoutio/edgetag-sdk-js 0.6.5 → 0.6.6
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 +47 -0
- package/index.d.ts +3 -0
- package/index.esm.js +47 -0
- 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
|
|
|
@@ -196,6 +208,7 @@ const getKeysURL = () => {
|
|
|
196
208
|
return generateUrl(`/keys`);
|
|
197
209
|
};
|
|
198
210
|
|
|
211
|
+
let initialized = false;
|
|
199
212
|
let consentDisabled = false;
|
|
200
213
|
const providers = {};
|
|
201
214
|
const setPreferences = (preferences) => {
|
|
@@ -227,6 +240,10 @@ const setPreferences = (preferences) => {
|
|
|
227
240
|
};
|
|
228
241
|
const isConsentDisabled = () => consentDisabled;
|
|
229
242
|
const getProvidersPackage = () => providers;
|
|
243
|
+
const isInitialized = () => initialized;
|
|
244
|
+
const setInitialized = () => {
|
|
245
|
+
initialized = true;
|
|
246
|
+
};
|
|
230
247
|
|
|
231
248
|
const getUserAgent = () => {
|
|
232
249
|
const nav = navigator;
|
|
@@ -390,6 +407,24 @@ const addProviderVariable = (name, variables) => {
|
|
|
390
407
|
};
|
|
391
408
|
const getProviderVariables = (name) => manifestVariables[name] || {};
|
|
392
409
|
|
|
410
|
+
let stubs = [];
|
|
411
|
+
const addStubs = (newStubs) => {
|
|
412
|
+
stubs = [...stubs, ...newStubs];
|
|
413
|
+
};
|
|
414
|
+
const addStub = (stub) => {
|
|
415
|
+
stubs.push(stub);
|
|
416
|
+
};
|
|
417
|
+
const processStubs = () => {
|
|
418
|
+
try {
|
|
419
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
420
|
+
// @ts-ignore
|
|
421
|
+
stubs.forEach((stub) => api[stub.name](...(stub.arguments || [])));
|
|
422
|
+
}
|
|
423
|
+
catch (e) {
|
|
424
|
+
console.error(e);
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
|
|
393
428
|
const sendTag = ({ eventName, eventId, data, providerData, providers, options, }) => {
|
|
394
429
|
const payload = {
|
|
395
430
|
eventName,
|
|
@@ -404,6 +439,13 @@ const sendTag = ({ eventName, eventId, data, providerData, providers, options, }
|
|
|
404
439
|
postRequest(getTagURL(), payload, options).catch(info);
|
|
405
440
|
};
|
|
406
441
|
const handleTag = (eventName, data = {}, providers, options) => {
|
|
442
|
+
if (!isInitialized()) {
|
|
443
|
+
addStub({
|
|
444
|
+
name: 'tag',
|
|
445
|
+
arguments: [eventName, data, providers, options],
|
|
446
|
+
});
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
407
449
|
if (!allowTag(providers)) {
|
|
408
450
|
console.log('No consent');
|
|
409
451
|
return;
|
|
@@ -548,6 +590,8 @@ const handleManifest = (manifest) => {
|
|
|
548
590
|
}
|
|
549
591
|
}
|
|
550
592
|
});
|
|
593
|
+
setInitialized();
|
|
594
|
+
processStubs();
|
|
551
595
|
savePerKey('local', tagStorage, providers, providersKey);
|
|
552
596
|
};
|
|
553
597
|
|
|
@@ -556,6 +600,9 @@ const handleInit = (preferences) => {
|
|
|
556
600
|
if (!success) {
|
|
557
601
|
return;
|
|
558
602
|
}
|
|
603
|
+
if (preferences.afterManifestEvents) {
|
|
604
|
+
addStubs(preferences.afterManifestEvents);
|
|
605
|
+
}
|
|
559
606
|
const url = new URL(getInitURL());
|
|
560
607
|
if (preferences.disableConsentCheck) {
|
|
561
608
|
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
|
|
|
@@ -192,6 +204,7 @@ const getKeysURL = () => {
|
|
|
192
204
|
return generateUrl(`/keys`);
|
|
193
205
|
};
|
|
194
206
|
|
|
207
|
+
let initialized = false;
|
|
195
208
|
let consentDisabled = false;
|
|
196
209
|
const providers = {};
|
|
197
210
|
const setPreferences = (preferences) => {
|
|
@@ -223,6 +236,10 @@ const setPreferences = (preferences) => {
|
|
|
223
236
|
};
|
|
224
237
|
const isConsentDisabled = () => consentDisabled;
|
|
225
238
|
const getProvidersPackage = () => providers;
|
|
239
|
+
const isInitialized = () => initialized;
|
|
240
|
+
const setInitialized = () => {
|
|
241
|
+
initialized = true;
|
|
242
|
+
};
|
|
226
243
|
|
|
227
244
|
const getUserAgent = () => {
|
|
228
245
|
const nav = navigator;
|
|
@@ -386,6 +403,24 @@ const addProviderVariable = (name, variables) => {
|
|
|
386
403
|
};
|
|
387
404
|
const getProviderVariables = (name) => manifestVariables[name] || {};
|
|
388
405
|
|
|
406
|
+
let stubs = [];
|
|
407
|
+
const addStubs = (newStubs) => {
|
|
408
|
+
stubs = [...stubs, ...newStubs];
|
|
409
|
+
};
|
|
410
|
+
const addStub = (stub) => {
|
|
411
|
+
stubs.push(stub);
|
|
412
|
+
};
|
|
413
|
+
const processStubs = () => {
|
|
414
|
+
try {
|
|
415
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
416
|
+
// @ts-ignore
|
|
417
|
+
stubs.forEach((stub) => api[stub.name](...(stub.arguments || [])));
|
|
418
|
+
}
|
|
419
|
+
catch (e) {
|
|
420
|
+
console.error(e);
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
|
|
389
424
|
const sendTag = ({ eventName, eventId, data, providerData, providers, options, }) => {
|
|
390
425
|
const payload = {
|
|
391
426
|
eventName,
|
|
@@ -400,6 +435,13 @@ const sendTag = ({ eventName, eventId, data, providerData, providers, options, }
|
|
|
400
435
|
postRequest(getTagURL(), payload, options).catch(info);
|
|
401
436
|
};
|
|
402
437
|
const handleTag = (eventName, data = {}, providers, options) => {
|
|
438
|
+
if (!isInitialized()) {
|
|
439
|
+
addStub({
|
|
440
|
+
name: 'tag',
|
|
441
|
+
arguments: [eventName, data, providers, options],
|
|
442
|
+
});
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
403
445
|
if (!allowTag(providers)) {
|
|
404
446
|
console.log('No consent');
|
|
405
447
|
return;
|
|
@@ -544,6 +586,8 @@ const handleManifest = (manifest) => {
|
|
|
544
586
|
}
|
|
545
587
|
}
|
|
546
588
|
});
|
|
589
|
+
setInitialized();
|
|
590
|
+
processStubs();
|
|
547
591
|
savePerKey('local', tagStorage, providers, providersKey);
|
|
548
592
|
};
|
|
549
593
|
|
|
@@ -552,6 +596,9 @@ const handleInit = (preferences) => {
|
|
|
552
596
|
if (!success) {
|
|
553
597
|
return;
|
|
554
598
|
}
|
|
599
|
+
if (preferences.afterManifestEvents) {
|
|
600
|
+
addStubs(preferences.afterManifestEvents);
|
|
601
|
+
}
|
|
555
602
|
const url = new URL(getInitURL());
|
|
556
603
|
if (preferences.disableConsentCheck) {
|
|
557
604
|
url.searchParams.set('consentDisabled', 'true');
|