@blotoutio/edgetag-sdk-js 0.52.0 → 0.52.1
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.js +81 -76
- package/index.mjs +81 -76
- package/package.json +1 -1
package/index.cjs.js
CHANGED
|
@@ -275,6 +275,7 @@ const areEqual = (a, b) => {
|
|
|
275
275
|
const tagStorage = 'edgeTag';
|
|
276
276
|
const consentKey = 'consent';
|
|
277
277
|
const keyPrefix = `_worker`;
|
|
278
|
+
const cookieKey = 'tag_user_id';
|
|
278
279
|
|
|
279
280
|
const getMessage = (error) => {
|
|
280
281
|
if (error instanceof Error) {
|
|
@@ -420,8 +421,80 @@ const getSession = (key) => {
|
|
|
420
421
|
}
|
|
421
422
|
};
|
|
422
423
|
|
|
424
|
+
const encodeString = (name) => {
|
|
425
|
+
if (typeof btoa === 'undefined') {
|
|
426
|
+
return Buffer.from(name).toString('base64');
|
|
427
|
+
}
|
|
428
|
+
return btoa(name);
|
|
429
|
+
};
|
|
430
|
+
const getBasicRandomNumber = () => {
|
|
431
|
+
return parseInt((Math.random() * 10000000000).toString(), 10);
|
|
432
|
+
};
|
|
433
|
+
const generateUUID = () => {
|
|
434
|
+
let id = '';
|
|
435
|
+
try {
|
|
436
|
+
id = crypto.randomUUID();
|
|
437
|
+
if (!id) {
|
|
438
|
+
const array = new Uint32Array(20);
|
|
439
|
+
const numbers = crypto.getRandomValues(array);
|
|
440
|
+
for (let i = 0; i < 5; i++) {
|
|
441
|
+
const y = i * 3;
|
|
442
|
+
if (i !== 0) {
|
|
443
|
+
id += '-';
|
|
444
|
+
}
|
|
445
|
+
const sum = numbers[y + 1] + numbers[y + 2] + numbers[y + 3];
|
|
446
|
+
id += sum.toString();
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
catch {
|
|
451
|
+
id = `${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}`;
|
|
452
|
+
console.log('[EdgeTag] Crypto module not found');
|
|
453
|
+
}
|
|
454
|
+
return id;
|
|
455
|
+
};
|
|
456
|
+
const generateEventId = (name) => {
|
|
457
|
+
let time = Date.now().toString();
|
|
458
|
+
if (typeof performance !== 'undefined' &&
|
|
459
|
+
typeof performance.now === 'function') {
|
|
460
|
+
const perf = performance.now();
|
|
461
|
+
if (perf) {
|
|
462
|
+
time = perf.toFixed(4);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
return `${encodeString(name)}-${generateUUID()}-${time}`;
|
|
466
|
+
};
|
|
467
|
+
|
|
468
|
+
const getCookieValue = (key) => {
|
|
469
|
+
try {
|
|
470
|
+
if (!document || !document.cookie) {
|
|
471
|
+
return '';
|
|
472
|
+
}
|
|
473
|
+
const name = `${key}=`;
|
|
474
|
+
const decodedCookie = decodeURIComponent(document.cookie);
|
|
475
|
+
const ca = decodedCookie.split(';');
|
|
476
|
+
for (let i = 0; i < ca.length; i++) {
|
|
477
|
+
let c = ca[i];
|
|
478
|
+
while (c.charAt(0) === ' ') {
|
|
479
|
+
c = c.substring(1);
|
|
480
|
+
}
|
|
481
|
+
if (c.indexOf(name) === 0) {
|
|
482
|
+
return c.substring(name.length, c.length);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
return '';
|
|
486
|
+
}
|
|
487
|
+
catch {
|
|
488
|
+
return '';
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
|
|
423
492
|
const getUserId$1 = (destination) => {
|
|
424
|
-
|
|
493
|
+
const userId = getSetting(destination, 'userId');
|
|
494
|
+
if (userId) {
|
|
495
|
+
return userId;
|
|
496
|
+
}
|
|
497
|
+
return getCookieValue(cookieKey);
|
|
425
498
|
};
|
|
426
499
|
const handleGetUserId = (options) => {
|
|
427
500
|
if (options === null || options === void 0 ? void 0 : options.destination) {
|
|
@@ -430,7 +503,7 @@ const handleGetUserId = (options) => {
|
|
|
430
503
|
const instances = getInstances();
|
|
431
504
|
if (instances.length > 1) {
|
|
432
505
|
error('Multiple instances detected! Please provide a destination.');
|
|
433
|
-
return
|
|
506
|
+
return '';
|
|
434
507
|
}
|
|
435
508
|
return getUserId$1(instances[0]);
|
|
436
509
|
};
|
|
@@ -474,7 +547,7 @@ const getStandardPayload = (destination, payload) => {
|
|
|
474
547
|
referrer: getReferrer(destination),
|
|
475
548
|
search: getSearch(destination),
|
|
476
549
|
locale: getLocale(),
|
|
477
|
-
sdkVersion: "0.52.
|
|
550
|
+
sdkVersion: "0.52.1" ,
|
|
478
551
|
...(payload || {}),
|
|
479
552
|
};
|
|
480
553
|
let storage = {};
|
|
@@ -601,74 +674,6 @@ const getProvidersPackage = (destination) => {
|
|
|
601
674
|
return providers;
|
|
602
675
|
};
|
|
603
676
|
|
|
604
|
-
const encodeString = (name) => {
|
|
605
|
-
if (typeof btoa === 'undefined') {
|
|
606
|
-
return Buffer.from(name).toString('base64');
|
|
607
|
-
}
|
|
608
|
-
return btoa(name);
|
|
609
|
-
};
|
|
610
|
-
const getBasicRandomNumber = () => {
|
|
611
|
-
return parseInt((Math.random() * 10000000000).toString(), 10);
|
|
612
|
-
};
|
|
613
|
-
const generateUUID = () => {
|
|
614
|
-
let id = '';
|
|
615
|
-
try {
|
|
616
|
-
id = crypto.randomUUID();
|
|
617
|
-
if (!id) {
|
|
618
|
-
const array = new Uint32Array(20);
|
|
619
|
-
const numbers = crypto.getRandomValues(array);
|
|
620
|
-
for (let i = 0; i < 5; i++) {
|
|
621
|
-
const y = i * 3;
|
|
622
|
-
if (i !== 0) {
|
|
623
|
-
id += '-';
|
|
624
|
-
}
|
|
625
|
-
const sum = numbers[y + 1] + numbers[y + 2] + numbers[y + 3];
|
|
626
|
-
id += sum.toString();
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
catch {
|
|
631
|
-
id = `${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}`;
|
|
632
|
-
console.log('[EdgeTag] Crypto module not found');
|
|
633
|
-
}
|
|
634
|
-
return id;
|
|
635
|
-
};
|
|
636
|
-
const generateEventId = (name) => {
|
|
637
|
-
let time = Date.now().toString();
|
|
638
|
-
if (typeof performance !== 'undefined' &&
|
|
639
|
-
typeof performance.now === 'function') {
|
|
640
|
-
const perf = performance.now();
|
|
641
|
-
if (perf) {
|
|
642
|
-
time = perf.toFixed(4);
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
return `${encodeString(name)}-${generateUUID()}-${time}`;
|
|
646
|
-
};
|
|
647
|
-
|
|
648
|
-
const getCookieValue = (key) => {
|
|
649
|
-
try {
|
|
650
|
-
if (!document || !document.cookie) {
|
|
651
|
-
return '';
|
|
652
|
-
}
|
|
653
|
-
const name = `${key}=`;
|
|
654
|
-
const decodedCookie = decodeURIComponent(document.cookie);
|
|
655
|
-
const ca = decodedCookie.split(';');
|
|
656
|
-
for (let i = 0; i < ca.length; i++) {
|
|
657
|
-
let c = ca[i];
|
|
658
|
-
while (c.charAt(0) === ' ') {
|
|
659
|
-
c = c.substring(1);
|
|
660
|
-
}
|
|
661
|
-
if (c.indexOf(name) === 0) {
|
|
662
|
-
return c.substring(name.length, c.length);
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
return '';
|
|
666
|
-
}
|
|
667
|
-
catch {
|
|
668
|
-
return '';
|
|
669
|
-
}
|
|
670
|
-
};
|
|
671
|
-
|
|
672
677
|
const getConsent$1 = (destination) => {
|
|
673
678
|
const storageConsent = getDataPerKey(destination, 'local', tagStorage, consentKey);
|
|
674
679
|
if (storageConsent) {
|
|
@@ -728,7 +733,7 @@ const processTag = (destination, eventName, data = {}, providers, options) => {
|
|
|
728
733
|
const userId = getUserId$1(destination);
|
|
729
734
|
const providerData = {};
|
|
730
735
|
const consent = getConsent$1(destination);
|
|
731
|
-
for (const pkg of
|
|
736
|
+
for (const pkg of providerPackages) {
|
|
732
737
|
if (!pkg || !pkg.name || !pkg.tag) {
|
|
733
738
|
continue;
|
|
734
739
|
}
|
|
@@ -824,7 +829,7 @@ const processData = (destination, data, providers, options) => {
|
|
|
824
829
|
const configuredTags = getSetting(destination, 'channels');
|
|
825
830
|
const userId = getUserId$1(destination);
|
|
826
831
|
const consent = getConsent$1(destination);
|
|
827
|
-
for (const pkg of
|
|
832
|
+
for (const pkg of providerPackages) {
|
|
828
833
|
if (!pkg || !pkg.user || !pkg.name) {
|
|
829
834
|
continue;
|
|
830
835
|
}
|
|
@@ -896,7 +901,7 @@ const processConsent = (destination, consent, localSave) => {
|
|
|
896
901
|
const providerPackages = getProvidersPackage(destination);
|
|
897
902
|
const executionContext = new Map();
|
|
898
903
|
/* Calling Init for all provider instances based on consent check */
|
|
899
|
-
for (const pkg of
|
|
904
|
+
for (const pkg of providerPackages) {
|
|
900
905
|
if (!pkg || !pkg.name || !pkg.init) {
|
|
901
906
|
continue;
|
|
902
907
|
}
|
|
@@ -1061,7 +1066,7 @@ const handleManifest = (destination, response) => {
|
|
|
1061
1066
|
const manifest = response.result;
|
|
1062
1067
|
manifest.forEach((provider) => {
|
|
1063
1068
|
addChannel(destination, provider.package, provider.tagName);
|
|
1064
|
-
const pkg = providerPackages
|
|
1069
|
+
const pkg = providerPackages.find((pkg) => pkg.name === provider.package);
|
|
1065
1070
|
if (provider.rules) {
|
|
1066
1071
|
Object.entries(provider.rules).forEach(([name, recipe]) => {
|
|
1067
1072
|
switch (name) {
|
|
@@ -1156,7 +1161,7 @@ const processUser = (destination, key, value, providers, options) => {
|
|
|
1156
1161
|
const configuredTags = getSetting(destination, 'channels');
|
|
1157
1162
|
const consent = getConsent$1(destination);
|
|
1158
1163
|
const userId = getUserId$1(destination);
|
|
1159
|
-
for (const pkg of
|
|
1164
|
+
for (const pkg of providerPackages) {
|
|
1160
1165
|
if (!pkg || !pkg.name || !pkg.user) {
|
|
1161
1166
|
continue;
|
|
1162
1167
|
}
|
package/index.mjs
CHANGED
|
@@ -273,6 +273,7 @@ const areEqual = (a, b) => {
|
|
|
273
273
|
const tagStorage = 'edgeTag';
|
|
274
274
|
const consentKey = 'consent';
|
|
275
275
|
const keyPrefix = `_worker`;
|
|
276
|
+
const cookieKey = 'tag_user_id';
|
|
276
277
|
|
|
277
278
|
const getMessage = (error) => {
|
|
278
279
|
if (error instanceof Error) {
|
|
@@ -418,8 +419,80 @@ const getSession = (key) => {
|
|
|
418
419
|
}
|
|
419
420
|
};
|
|
420
421
|
|
|
422
|
+
const encodeString = (name) => {
|
|
423
|
+
if (typeof btoa === 'undefined') {
|
|
424
|
+
return Buffer.from(name).toString('base64');
|
|
425
|
+
}
|
|
426
|
+
return btoa(name);
|
|
427
|
+
};
|
|
428
|
+
const getBasicRandomNumber = () => {
|
|
429
|
+
return parseInt((Math.random() * 10000000000).toString(), 10);
|
|
430
|
+
};
|
|
431
|
+
const generateUUID = () => {
|
|
432
|
+
let id = '';
|
|
433
|
+
try {
|
|
434
|
+
id = crypto.randomUUID();
|
|
435
|
+
if (!id) {
|
|
436
|
+
const array = new Uint32Array(20);
|
|
437
|
+
const numbers = crypto.getRandomValues(array);
|
|
438
|
+
for (let i = 0; i < 5; i++) {
|
|
439
|
+
const y = i * 3;
|
|
440
|
+
if (i !== 0) {
|
|
441
|
+
id += '-';
|
|
442
|
+
}
|
|
443
|
+
const sum = numbers[y + 1] + numbers[y + 2] + numbers[y + 3];
|
|
444
|
+
id += sum.toString();
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
catch {
|
|
449
|
+
id = `${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}`;
|
|
450
|
+
console.log('[EdgeTag] Crypto module not found');
|
|
451
|
+
}
|
|
452
|
+
return id;
|
|
453
|
+
};
|
|
454
|
+
const generateEventId = (name) => {
|
|
455
|
+
let time = Date.now().toString();
|
|
456
|
+
if (typeof performance !== 'undefined' &&
|
|
457
|
+
typeof performance.now === 'function') {
|
|
458
|
+
const perf = performance.now();
|
|
459
|
+
if (perf) {
|
|
460
|
+
time = perf.toFixed(4);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
return `${encodeString(name)}-${generateUUID()}-${time}`;
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
const getCookieValue = (key) => {
|
|
467
|
+
try {
|
|
468
|
+
if (!document || !document.cookie) {
|
|
469
|
+
return '';
|
|
470
|
+
}
|
|
471
|
+
const name = `${key}=`;
|
|
472
|
+
const decodedCookie = decodeURIComponent(document.cookie);
|
|
473
|
+
const ca = decodedCookie.split(';');
|
|
474
|
+
for (let i = 0; i < ca.length; i++) {
|
|
475
|
+
let c = ca[i];
|
|
476
|
+
while (c.charAt(0) === ' ') {
|
|
477
|
+
c = c.substring(1);
|
|
478
|
+
}
|
|
479
|
+
if (c.indexOf(name) === 0) {
|
|
480
|
+
return c.substring(name.length, c.length);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
return '';
|
|
484
|
+
}
|
|
485
|
+
catch {
|
|
486
|
+
return '';
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
|
|
421
490
|
const getUserId$1 = (destination) => {
|
|
422
|
-
|
|
491
|
+
const userId = getSetting(destination, 'userId');
|
|
492
|
+
if (userId) {
|
|
493
|
+
return userId;
|
|
494
|
+
}
|
|
495
|
+
return getCookieValue(cookieKey);
|
|
423
496
|
};
|
|
424
497
|
const handleGetUserId = (options) => {
|
|
425
498
|
if (options === null || options === void 0 ? void 0 : options.destination) {
|
|
@@ -428,7 +501,7 @@ const handleGetUserId = (options) => {
|
|
|
428
501
|
const instances = getInstances();
|
|
429
502
|
if (instances.length > 1) {
|
|
430
503
|
error('Multiple instances detected! Please provide a destination.');
|
|
431
|
-
return
|
|
504
|
+
return '';
|
|
432
505
|
}
|
|
433
506
|
return getUserId$1(instances[0]);
|
|
434
507
|
};
|
|
@@ -472,7 +545,7 @@ const getStandardPayload = (destination, payload) => {
|
|
|
472
545
|
referrer: getReferrer(destination),
|
|
473
546
|
search: getSearch(destination),
|
|
474
547
|
locale: getLocale(),
|
|
475
|
-
sdkVersion: "0.52.
|
|
548
|
+
sdkVersion: "0.52.1" ,
|
|
476
549
|
...(payload || {}),
|
|
477
550
|
};
|
|
478
551
|
let storage = {};
|
|
@@ -599,74 +672,6 @@ const getProvidersPackage = (destination) => {
|
|
|
599
672
|
return providers;
|
|
600
673
|
};
|
|
601
674
|
|
|
602
|
-
const encodeString = (name) => {
|
|
603
|
-
if (typeof btoa === 'undefined') {
|
|
604
|
-
return Buffer.from(name).toString('base64');
|
|
605
|
-
}
|
|
606
|
-
return btoa(name);
|
|
607
|
-
};
|
|
608
|
-
const getBasicRandomNumber = () => {
|
|
609
|
-
return parseInt((Math.random() * 10000000000).toString(), 10);
|
|
610
|
-
};
|
|
611
|
-
const generateUUID = () => {
|
|
612
|
-
let id = '';
|
|
613
|
-
try {
|
|
614
|
-
id = crypto.randomUUID();
|
|
615
|
-
if (!id) {
|
|
616
|
-
const array = new Uint32Array(20);
|
|
617
|
-
const numbers = crypto.getRandomValues(array);
|
|
618
|
-
for (let i = 0; i < 5; i++) {
|
|
619
|
-
const y = i * 3;
|
|
620
|
-
if (i !== 0) {
|
|
621
|
-
id += '-';
|
|
622
|
-
}
|
|
623
|
-
const sum = numbers[y + 1] + numbers[y + 2] + numbers[y + 3];
|
|
624
|
-
id += sum.toString();
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
catch {
|
|
629
|
-
id = `${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}`;
|
|
630
|
-
console.log('[EdgeTag] Crypto module not found');
|
|
631
|
-
}
|
|
632
|
-
return id;
|
|
633
|
-
};
|
|
634
|
-
const generateEventId = (name) => {
|
|
635
|
-
let time = Date.now().toString();
|
|
636
|
-
if (typeof performance !== 'undefined' &&
|
|
637
|
-
typeof performance.now === 'function') {
|
|
638
|
-
const perf = performance.now();
|
|
639
|
-
if (perf) {
|
|
640
|
-
time = perf.toFixed(4);
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
return `${encodeString(name)}-${generateUUID()}-${time}`;
|
|
644
|
-
};
|
|
645
|
-
|
|
646
|
-
const getCookieValue = (key) => {
|
|
647
|
-
try {
|
|
648
|
-
if (!document || !document.cookie) {
|
|
649
|
-
return '';
|
|
650
|
-
}
|
|
651
|
-
const name = `${key}=`;
|
|
652
|
-
const decodedCookie = decodeURIComponent(document.cookie);
|
|
653
|
-
const ca = decodedCookie.split(';');
|
|
654
|
-
for (let i = 0; i < ca.length; i++) {
|
|
655
|
-
let c = ca[i];
|
|
656
|
-
while (c.charAt(0) === ' ') {
|
|
657
|
-
c = c.substring(1);
|
|
658
|
-
}
|
|
659
|
-
if (c.indexOf(name) === 0) {
|
|
660
|
-
return c.substring(name.length, c.length);
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
return '';
|
|
664
|
-
}
|
|
665
|
-
catch {
|
|
666
|
-
return '';
|
|
667
|
-
}
|
|
668
|
-
};
|
|
669
|
-
|
|
670
675
|
const getConsent$1 = (destination) => {
|
|
671
676
|
const storageConsent = getDataPerKey(destination, 'local', tagStorage, consentKey);
|
|
672
677
|
if (storageConsent) {
|
|
@@ -726,7 +731,7 @@ const processTag = (destination, eventName, data = {}, providers, options) => {
|
|
|
726
731
|
const userId = getUserId$1(destination);
|
|
727
732
|
const providerData = {};
|
|
728
733
|
const consent = getConsent$1(destination);
|
|
729
|
-
for (const pkg of
|
|
734
|
+
for (const pkg of providerPackages) {
|
|
730
735
|
if (!pkg || !pkg.name || !pkg.tag) {
|
|
731
736
|
continue;
|
|
732
737
|
}
|
|
@@ -822,7 +827,7 @@ const processData = (destination, data, providers, options) => {
|
|
|
822
827
|
const configuredTags = getSetting(destination, 'channels');
|
|
823
828
|
const userId = getUserId$1(destination);
|
|
824
829
|
const consent = getConsent$1(destination);
|
|
825
|
-
for (const pkg of
|
|
830
|
+
for (const pkg of providerPackages) {
|
|
826
831
|
if (!pkg || !pkg.user || !pkg.name) {
|
|
827
832
|
continue;
|
|
828
833
|
}
|
|
@@ -894,7 +899,7 @@ const processConsent = (destination, consent, localSave) => {
|
|
|
894
899
|
const providerPackages = getProvidersPackage(destination);
|
|
895
900
|
const executionContext = new Map();
|
|
896
901
|
/* Calling Init for all provider instances based on consent check */
|
|
897
|
-
for (const pkg of
|
|
902
|
+
for (const pkg of providerPackages) {
|
|
898
903
|
if (!pkg || !pkg.name || !pkg.init) {
|
|
899
904
|
continue;
|
|
900
905
|
}
|
|
@@ -1059,7 +1064,7 @@ const handleManifest = (destination, response) => {
|
|
|
1059
1064
|
const manifest = response.result;
|
|
1060
1065
|
manifest.forEach((provider) => {
|
|
1061
1066
|
addChannel(destination, provider.package, provider.tagName);
|
|
1062
|
-
const pkg = providerPackages
|
|
1067
|
+
const pkg = providerPackages.find((pkg) => pkg.name === provider.package);
|
|
1063
1068
|
if (provider.rules) {
|
|
1064
1069
|
Object.entries(provider.rules).forEach(([name, recipe]) => {
|
|
1065
1070
|
switch (name) {
|
|
@@ -1154,7 +1159,7 @@ const processUser = (destination, key, value, providers, options) => {
|
|
|
1154
1159
|
const configuredTags = getSetting(destination, 'channels');
|
|
1155
1160
|
const consent = getConsent$1(destination);
|
|
1156
1161
|
const userId = getUserId$1(destination);
|
|
1157
|
-
for (const pkg of
|
|
1162
|
+
for (const pkg of providerPackages) {
|
|
1158
1163
|
if (!pkg || !pkg.name || !pkg.user) {
|
|
1159
1164
|
continue;
|
|
1160
1165
|
}
|