@blotoutio/edgetag-sdk-browser 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.js +97 -90
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -276,6 +276,7 @@
|
|
|
276
276
|
const tagStorage = 'edgeTag';
|
|
277
277
|
const consentKey = 'consent';
|
|
278
278
|
const keyPrefix = `_worker`;
|
|
279
|
+
const cookieKey = 'tag_user_id';
|
|
279
280
|
|
|
280
281
|
const getMessage = (error) => {
|
|
281
282
|
if (error instanceof Error) {
|
|
@@ -421,8 +422,80 @@
|
|
|
421
422
|
}
|
|
422
423
|
};
|
|
423
424
|
|
|
425
|
+
const encodeString = (name) => {
|
|
426
|
+
if (typeof btoa === 'undefined') {
|
|
427
|
+
return Buffer.from(name).toString('base64');
|
|
428
|
+
}
|
|
429
|
+
return btoa(name);
|
|
430
|
+
};
|
|
431
|
+
const getBasicRandomNumber = () => {
|
|
432
|
+
return parseInt((Math.random() * 10000000000).toString(), 10);
|
|
433
|
+
};
|
|
434
|
+
const generateUUID = () => {
|
|
435
|
+
let id = '';
|
|
436
|
+
try {
|
|
437
|
+
id = crypto.randomUUID();
|
|
438
|
+
if (!id) {
|
|
439
|
+
const array = new Uint32Array(20);
|
|
440
|
+
const numbers = crypto.getRandomValues(array);
|
|
441
|
+
for (let i = 0; i < 5; i++) {
|
|
442
|
+
const y = i * 3;
|
|
443
|
+
if (i !== 0) {
|
|
444
|
+
id += '-';
|
|
445
|
+
}
|
|
446
|
+
const sum = numbers[y + 1] + numbers[y + 2] + numbers[y + 3];
|
|
447
|
+
id += sum.toString();
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
catch {
|
|
452
|
+
id = `${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}`;
|
|
453
|
+
console.log('[EdgeTag] Crypto module not found');
|
|
454
|
+
}
|
|
455
|
+
return id;
|
|
456
|
+
};
|
|
457
|
+
const generateEventId = (name) => {
|
|
458
|
+
let time = Date.now().toString();
|
|
459
|
+
if (typeof performance !== 'undefined' &&
|
|
460
|
+
typeof performance.now === 'function') {
|
|
461
|
+
const perf = performance.now();
|
|
462
|
+
if (perf) {
|
|
463
|
+
time = perf.toFixed(4);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
return `${encodeString(name)}-${generateUUID()}-${time}`;
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
const getCookieValue = (key) => {
|
|
470
|
+
try {
|
|
471
|
+
if (!document || !document.cookie) {
|
|
472
|
+
return '';
|
|
473
|
+
}
|
|
474
|
+
const name = `${key}=`;
|
|
475
|
+
const decodedCookie = decodeURIComponent(document.cookie);
|
|
476
|
+
const ca = decodedCookie.split(';');
|
|
477
|
+
for (let i = 0; i < ca.length; i++) {
|
|
478
|
+
let c = ca[i];
|
|
479
|
+
while (c.charAt(0) === ' ') {
|
|
480
|
+
c = c.substring(1);
|
|
481
|
+
}
|
|
482
|
+
if (c.indexOf(name) === 0) {
|
|
483
|
+
return c.substring(name.length, c.length);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
return '';
|
|
487
|
+
}
|
|
488
|
+
catch {
|
|
489
|
+
return '';
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
|
|
424
493
|
const getUserId$1 = (destination) => {
|
|
425
|
-
|
|
494
|
+
const userId = getSetting(destination, 'userId');
|
|
495
|
+
if (userId) {
|
|
496
|
+
return userId;
|
|
497
|
+
}
|
|
498
|
+
return getCookieValue(cookieKey);
|
|
426
499
|
};
|
|
427
500
|
const handleGetUserId = (options) => {
|
|
428
501
|
if (options === null || options === void 0 ? void 0 : options.destination) {
|
|
@@ -431,7 +504,7 @@
|
|
|
431
504
|
const instances = getInstances();
|
|
432
505
|
if (instances.length > 1) {
|
|
433
506
|
error('Multiple instances detected! Please provide a destination.');
|
|
434
|
-
return
|
|
507
|
+
return '';
|
|
435
508
|
}
|
|
436
509
|
return getUserId$1(instances[0]);
|
|
437
510
|
};
|
|
@@ -475,7 +548,7 @@
|
|
|
475
548
|
referrer: getReferrer(destination),
|
|
476
549
|
search: getSearch(destination),
|
|
477
550
|
locale: getLocale(),
|
|
478
|
-
sdkVersion: "0.52.
|
|
551
|
+
sdkVersion: "0.52.1" ,
|
|
479
552
|
...(payload || {}),
|
|
480
553
|
};
|
|
481
554
|
let storage = {};
|
|
@@ -602,74 +675,6 @@
|
|
|
602
675
|
return providers;
|
|
603
676
|
};
|
|
604
677
|
|
|
605
|
-
const encodeString = (name) => {
|
|
606
|
-
if (typeof btoa === 'undefined') {
|
|
607
|
-
return Buffer.from(name).toString('base64');
|
|
608
|
-
}
|
|
609
|
-
return btoa(name);
|
|
610
|
-
};
|
|
611
|
-
const getBasicRandomNumber = () => {
|
|
612
|
-
return parseInt((Math.random() * 10000000000).toString(), 10);
|
|
613
|
-
};
|
|
614
|
-
const generateUUID = () => {
|
|
615
|
-
let id = '';
|
|
616
|
-
try {
|
|
617
|
-
id = crypto.randomUUID();
|
|
618
|
-
if (!id) {
|
|
619
|
-
const array = new Uint32Array(20);
|
|
620
|
-
const numbers = crypto.getRandomValues(array);
|
|
621
|
-
for (let i = 0; i < 5; i++) {
|
|
622
|
-
const y = i * 3;
|
|
623
|
-
if (i !== 0) {
|
|
624
|
-
id += '-';
|
|
625
|
-
}
|
|
626
|
-
const sum = numbers[y + 1] + numbers[y + 2] + numbers[y + 3];
|
|
627
|
-
id += sum.toString();
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
catch {
|
|
632
|
-
id = `${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}`;
|
|
633
|
-
console.log('[EdgeTag] Crypto module not found');
|
|
634
|
-
}
|
|
635
|
-
return id;
|
|
636
|
-
};
|
|
637
|
-
const generateEventId = (name) => {
|
|
638
|
-
let time = Date.now().toString();
|
|
639
|
-
if (typeof performance !== 'undefined' &&
|
|
640
|
-
typeof performance.now === 'function') {
|
|
641
|
-
const perf = performance.now();
|
|
642
|
-
if (perf) {
|
|
643
|
-
time = perf.toFixed(4);
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
return `${encodeString(name)}-${generateUUID()}-${time}`;
|
|
647
|
-
};
|
|
648
|
-
|
|
649
|
-
const getCookieValue = (key) => {
|
|
650
|
-
try {
|
|
651
|
-
if (!document || !document.cookie) {
|
|
652
|
-
return '';
|
|
653
|
-
}
|
|
654
|
-
const name = `${key}=`;
|
|
655
|
-
const decodedCookie = decodeURIComponent(document.cookie);
|
|
656
|
-
const ca = decodedCookie.split(';');
|
|
657
|
-
for (let i = 0; i < ca.length; i++) {
|
|
658
|
-
let c = ca[i];
|
|
659
|
-
while (c.charAt(0) === ' ') {
|
|
660
|
-
c = c.substring(1);
|
|
661
|
-
}
|
|
662
|
-
if (c.indexOf(name) === 0) {
|
|
663
|
-
return c.substring(name.length, c.length);
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
return '';
|
|
667
|
-
}
|
|
668
|
-
catch {
|
|
669
|
-
return '';
|
|
670
|
-
}
|
|
671
|
-
};
|
|
672
|
-
|
|
673
678
|
const getConsent$1 = (destination) => {
|
|
674
679
|
const storageConsent = getDataPerKey(destination, 'local', tagStorage, consentKey);
|
|
675
680
|
if (storageConsent) {
|
|
@@ -729,7 +734,7 @@
|
|
|
729
734
|
const userId = getUserId$1(destination);
|
|
730
735
|
const providerData = {};
|
|
731
736
|
const consent = getConsent$1(destination);
|
|
732
|
-
for (const pkg of
|
|
737
|
+
for (const pkg of providerPackages) {
|
|
733
738
|
if (!pkg || !pkg.name || !pkg.tag) {
|
|
734
739
|
continue;
|
|
735
740
|
}
|
|
@@ -825,7 +830,7 @@
|
|
|
825
830
|
const configuredTags = getSetting(destination, 'channels');
|
|
826
831
|
const userId = getUserId$1(destination);
|
|
827
832
|
const consent = getConsent$1(destination);
|
|
828
|
-
for (const pkg of
|
|
833
|
+
for (const pkg of providerPackages) {
|
|
829
834
|
if (!pkg || !pkg.user || !pkg.name) {
|
|
830
835
|
continue;
|
|
831
836
|
}
|
|
@@ -897,7 +902,7 @@
|
|
|
897
902
|
const providerPackages = getProvidersPackage(destination);
|
|
898
903
|
const executionContext = new Map();
|
|
899
904
|
/* Calling Init for all provider instances based on consent check */
|
|
900
|
-
for (const pkg of
|
|
905
|
+
for (const pkg of providerPackages) {
|
|
901
906
|
if (!pkg || !pkg.name || !pkg.init) {
|
|
902
907
|
continue;
|
|
903
908
|
}
|
|
@@ -1062,7 +1067,7 @@
|
|
|
1062
1067
|
const manifest = response.result;
|
|
1063
1068
|
manifest.forEach((provider) => {
|
|
1064
1069
|
addChannel(destination, provider.package, provider.tagName);
|
|
1065
|
-
const pkg = providerPackages
|
|
1070
|
+
const pkg = providerPackages.find((pkg) => pkg.name === provider.package);
|
|
1066
1071
|
if (provider.rules) {
|
|
1067
1072
|
Object.entries(provider.rules).forEach(([name, recipe]) => {
|
|
1068
1073
|
switch (name) {
|
|
@@ -1157,7 +1162,7 @@
|
|
|
1157
1162
|
const configuredTags = getSetting(destination, 'channels');
|
|
1158
1163
|
const consent = getConsent$1(destination);
|
|
1159
1164
|
const userId = getUserId$1(destination);
|
|
1160
|
-
for (const pkg of
|
|
1165
|
+
for (const pkg of providerPackages) {
|
|
1161
1166
|
if (!pkg || !pkg.name || !pkg.user) {
|
|
1162
1167
|
continue;
|
|
1163
1168
|
}
|
|
@@ -1379,23 +1384,25 @@
|
|
|
1379
1384
|
|
|
1380
1385
|
const library = api;
|
|
1381
1386
|
let stubs = [];
|
|
1382
|
-
if (window.edgetag) {
|
|
1387
|
+
if (!window.edgetag?.live) {
|
|
1383
1388
|
stubs = window.edgetag.stubs || [];
|
|
1384
|
-
}
|
|
1385
1389
|
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1390
|
+
// this needs to be regular function for arguments to work
|
|
1391
|
+
window.edgetag = function () {
|
|
1392
|
+
const sliced = [].slice.call(arguments);
|
|
1393
|
+
if (!Array.isArray(sliced)) {
|
|
1394
|
+
return
|
|
1395
|
+
}
|
|
1392
1396
|
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1397
|
+
try {
|
|
1398
|
+
return library[sliced[0]](...sliced.slice(1))
|
|
1399
|
+
} catch (e) {
|
|
1400
|
+
console.error(e);
|
|
1401
|
+
}
|
|
1402
|
+
};
|
|
1403
|
+
|
|
1404
|
+
window.edgetag.live = true;
|
|
1405
|
+
}
|
|
1399
1406
|
|
|
1400
1407
|
const beforeManifestEvents = [];
|
|
1401
1408
|
const afterManifestEvents = [];
|