@blotoutio/edgetag-sdk-browser 0.6.4 → 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.js +273 -133
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
(function () {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
+
var api$1 = /*#__PURE__*/Object.freeze({
|
|
5
|
+
__proto__: null,
|
|
6
|
+
get init () { return init; },
|
|
7
|
+
get tag () { return tag; },
|
|
8
|
+
get consent () { return consent; },
|
|
9
|
+
get user () { return user; },
|
|
10
|
+
get data () { return data; },
|
|
11
|
+
get getData () { return getData; },
|
|
12
|
+
get keys () { return keys; },
|
|
13
|
+
get getUserId () { return getUserId; }
|
|
14
|
+
});
|
|
15
|
+
|
|
4
16
|
/******************************************************************************
|
|
5
17
|
Copyright (c) Microsoft Corporation.
|
|
6
18
|
|
|
@@ -101,24 +113,56 @@
|
|
|
101
113
|
saveData('session', currentSession);
|
|
102
114
|
};
|
|
103
115
|
const saveLocal = (value, key) => {
|
|
104
|
-
|
|
116
|
+
try {
|
|
117
|
+
if (!localStorage) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
localStorage.setItem(key, JSON.stringify(value));
|
|
121
|
+
}
|
|
122
|
+
catch (_a) {
|
|
123
|
+
console.log('Local storage not supported');
|
|
124
|
+
}
|
|
105
125
|
};
|
|
106
126
|
const getLocal = (key) => {
|
|
107
|
-
|
|
108
|
-
|
|
127
|
+
try {
|
|
128
|
+
if (!localStorage) {
|
|
129
|
+
return {};
|
|
130
|
+
}
|
|
131
|
+
const data = localStorage.getItem(key);
|
|
132
|
+
if (!data) {
|
|
133
|
+
return {};
|
|
134
|
+
}
|
|
135
|
+
return JSON.parse(data) || {};
|
|
136
|
+
}
|
|
137
|
+
catch (_a) {
|
|
109
138
|
return {};
|
|
110
139
|
}
|
|
111
|
-
return JSON.parse(data) || {};
|
|
112
140
|
};
|
|
113
141
|
const saveSession = (value, key) => {
|
|
114
|
-
|
|
142
|
+
try {
|
|
143
|
+
if (!sessionStorage) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
sessionStorage.setItem(key, JSON.stringify(value));
|
|
147
|
+
}
|
|
148
|
+
catch (_a) {
|
|
149
|
+
console.log('Session storage not supported');
|
|
150
|
+
}
|
|
115
151
|
};
|
|
116
152
|
const getSession = (key) => {
|
|
117
|
-
|
|
118
|
-
|
|
153
|
+
try {
|
|
154
|
+
if (!sessionStorage) {
|
|
155
|
+
return {};
|
|
156
|
+
}
|
|
157
|
+
const data = sessionStorage.getItem(key);
|
|
158
|
+
if (!data) {
|
|
159
|
+
return {};
|
|
160
|
+
}
|
|
161
|
+
return JSON.parse(data) || {};
|
|
162
|
+
}
|
|
163
|
+
catch (_a) {
|
|
119
164
|
return {};
|
|
120
165
|
}
|
|
121
|
-
return JSON.parse(data) || {};
|
|
122
166
|
};
|
|
123
167
|
|
|
124
168
|
let endpointUrl = '';
|
|
@@ -161,6 +205,7 @@
|
|
|
161
205
|
return generateUrl(`/keys`);
|
|
162
206
|
};
|
|
163
207
|
|
|
208
|
+
let initialized = false;
|
|
164
209
|
let consentDisabled = false;
|
|
165
210
|
const providers = {};
|
|
166
211
|
const setPreferences = (preferences) => {
|
|
@@ -192,6 +237,10 @@
|
|
|
192
237
|
};
|
|
193
238
|
const isConsentDisabled = () => consentDisabled;
|
|
194
239
|
const getProvidersPackage = () => providers;
|
|
240
|
+
const isInitialized = () => initialized;
|
|
241
|
+
const setInitialized = () => {
|
|
242
|
+
initialized = true;
|
|
243
|
+
};
|
|
195
244
|
|
|
196
245
|
const getUserAgent = () => {
|
|
197
246
|
const nav = navigator;
|
|
@@ -336,14 +385,13 @@
|
|
|
336
385
|
// Unique ID creation requires a high quality random # generator. In the browser we therefore
|
|
337
386
|
// require the crypto API and do not support built-in fallback to lower quality random number
|
|
338
387
|
// generators (like Math.random()).
|
|
339
|
-
|
|
340
|
-
|
|
388
|
+
let getRandomValues;
|
|
389
|
+
const rnds8 = new Uint8Array(16);
|
|
341
390
|
function rng() {
|
|
342
391
|
// lazy load so that environments that need to polyfill have a chance to do so
|
|
343
392
|
if (!getRandomValues) {
|
|
344
|
-
// getRandomValues needs to be invoked in a context where "this" is a Crypto implementation.
|
|
345
|
-
|
|
346
|
-
getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== 'undefined' && typeof msCrypto.getRandomValues === 'function' && msCrypto.getRandomValues.bind(msCrypto);
|
|
393
|
+
// getRandomValues needs to be invoked in a context where "this" is a Crypto implementation.
|
|
394
|
+
getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
|
|
347
395
|
|
|
348
396
|
if (!getRandomValues) {
|
|
349
397
|
throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
|
|
@@ -364,27 +412,16 @@
|
|
|
364
412
|
* XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
|
|
365
413
|
*/
|
|
366
414
|
|
|
367
|
-
|
|
415
|
+
const byteToHex = [];
|
|
368
416
|
|
|
369
|
-
for (
|
|
370
|
-
byteToHex.push((i + 0x100).toString(16).
|
|
417
|
+
for (let i = 0; i < 256; ++i) {
|
|
418
|
+
byteToHex.push((i + 0x100).toString(16).slice(1));
|
|
371
419
|
}
|
|
372
420
|
|
|
373
|
-
function
|
|
374
|
-
var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
421
|
+
function unsafeStringify(arr, offset = 0) {
|
|
375
422
|
// Note: Be careful editing this code! It's been tuned for performance
|
|
376
423
|
// and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
|
|
377
|
-
|
|
378
|
-
// of the following:
|
|
379
|
-
// - One or more input array values don't map to a hex octet (leading to
|
|
380
|
-
// "undefined" in the uuid)
|
|
381
|
-
// - Invalid input values for the RFC `version` or `variant` fields
|
|
382
|
-
|
|
383
|
-
if (!validate(uuid)) {
|
|
384
|
-
throw TypeError('Stringified UUID is invalid');
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
return uuid;
|
|
424
|
+
return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
|
|
388
425
|
}
|
|
389
426
|
|
|
390
427
|
function parse(uuid) {
|
|
@@ -392,8 +429,8 @@
|
|
|
392
429
|
throw TypeError('Invalid UUID');
|
|
393
430
|
}
|
|
394
431
|
|
|
395
|
-
|
|
396
|
-
|
|
432
|
+
let v;
|
|
433
|
+
const arr = new Uint8Array(16); // Parse ########-....-....-....-............
|
|
397
434
|
|
|
398
435
|
arr[0] = (v = parseInt(uuid.slice(0, 8), 16)) >>> 24;
|
|
399
436
|
arr[1] = v >>> 16 & 0xff;
|
|
@@ -422,19 +459,21 @@
|
|
|
422
459
|
function stringToBytes(str) {
|
|
423
460
|
str = unescape(encodeURIComponent(str)); // UTF8 escape
|
|
424
461
|
|
|
425
|
-
|
|
462
|
+
const bytes = [];
|
|
426
463
|
|
|
427
|
-
for (
|
|
464
|
+
for (let i = 0; i < str.length; ++i) {
|
|
428
465
|
bytes.push(str.charCodeAt(i));
|
|
429
466
|
}
|
|
430
467
|
|
|
431
468
|
return bytes;
|
|
432
469
|
}
|
|
433
470
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
function v35
|
|
471
|
+
const DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
|
|
472
|
+
const URL$1 = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
|
|
473
|
+
function v35(name, version, hashfunc) {
|
|
437
474
|
function generateUUID(value, namespace, buf, offset) {
|
|
475
|
+
var _namespace;
|
|
476
|
+
|
|
438
477
|
if (typeof value === 'string') {
|
|
439
478
|
value = stringToBytes(value);
|
|
440
479
|
}
|
|
@@ -443,14 +482,14 @@
|
|
|
443
482
|
namespace = parse(namespace);
|
|
444
483
|
}
|
|
445
484
|
|
|
446
|
-
if (namespace.length !== 16) {
|
|
485
|
+
if (((_namespace = namespace) === null || _namespace === void 0 ? void 0 : _namespace.length) !== 16) {
|
|
447
486
|
throw TypeError('Namespace must be array-like (16 iterable integer values, 0-255)');
|
|
448
487
|
} // Compute hash of namespace and value, Per 4.3
|
|
449
488
|
// Future: Use spread syntax when supported on all platforms, e.g. `bytes =
|
|
450
489
|
// hashfunc([...namespace, ... value])`
|
|
451
490
|
|
|
452
491
|
|
|
453
|
-
|
|
492
|
+
let bytes = new Uint8Array(16 + value.length);
|
|
454
493
|
bytes.set(namespace);
|
|
455
494
|
bytes.set(value, namespace.length);
|
|
456
495
|
bytes = hashfunc(bytes);
|
|
@@ -460,14 +499,14 @@
|
|
|
460
499
|
if (buf) {
|
|
461
500
|
offset = offset || 0;
|
|
462
501
|
|
|
463
|
-
for (
|
|
502
|
+
for (let i = 0; i < 16; ++i) {
|
|
464
503
|
buf[offset + i] = bytes[i];
|
|
465
504
|
}
|
|
466
505
|
|
|
467
506
|
return buf;
|
|
468
507
|
}
|
|
469
508
|
|
|
470
|
-
return
|
|
509
|
+
return unsafeStringify(bytes);
|
|
471
510
|
} // Function#name is not settable on some platforms (#270)
|
|
472
511
|
|
|
473
512
|
|
|
@@ -503,11 +542,11 @@
|
|
|
503
542
|
*/
|
|
504
543
|
function md5(bytes) {
|
|
505
544
|
if (typeof bytes === 'string') {
|
|
506
|
-
|
|
545
|
+
const msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
|
|
507
546
|
|
|
508
547
|
bytes = new Uint8Array(msg.length);
|
|
509
548
|
|
|
510
|
-
for (
|
|
549
|
+
for (let i = 0; i < msg.length; ++i) {
|
|
511
550
|
bytes[i] = msg.charCodeAt(i);
|
|
512
551
|
}
|
|
513
552
|
}
|
|
@@ -520,13 +559,13 @@
|
|
|
520
559
|
|
|
521
560
|
|
|
522
561
|
function md5ToHexEncodedArray(input) {
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
562
|
+
const output = [];
|
|
563
|
+
const length32 = input.length * 32;
|
|
564
|
+
const hexTab = '0123456789abcdef';
|
|
526
565
|
|
|
527
|
-
for (
|
|
528
|
-
|
|
529
|
-
|
|
566
|
+
for (let i = 0; i < length32; i += 8) {
|
|
567
|
+
const x = input[i >> 5] >>> i % 32 & 0xff;
|
|
568
|
+
const hex = parseInt(hexTab.charAt(x >>> 4 & 0x0f) + hexTab.charAt(x & 0x0f), 16);
|
|
530
569
|
output.push(hex);
|
|
531
570
|
}
|
|
532
571
|
|
|
@@ -549,16 +588,16 @@
|
|
|
549
588
|
/* append padding */
|
|
550
589
|
x[len >> 5] |= 0x80 << len % 32;
|
|
551
590
|
x[getOutputLength(len) - 1] = len;
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
for (
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
591
|
+
let a = 1732584193;
|
|
592
|
+
let b = -271733879;
|
|
593
|
+
let c = -1732584194;
|
|
594
|
+
let d = 271733878;
|
|
595
|
+
|
|
596
|
+
for (let i = 0; i < x.length; i += 16) {
|
|
597
|
+
const olda = a;
|
|
598
|
+
const oldb = b;
|
|
599
|
+
const oldc = c;
|
|
600
|
+
const oldd = d;
|
|
562
601
|
a = md5ff(a, b, c, d, x[i], 7, -680876936);
|
|
563
602
|
d = md5ff(d, a, b, c, x[i + 1], 12, -389564586);
|
|
564
603
|
c = md5ff(c, d, a, b, x[i + 2], 17, 606105819);
|
|
@@ -642,10 +681,10 @@
|
|
|
642
681
|
return [];
|
|
643
682
|
}
|
|
644
683
|
|
|
645
|
-
|
|
646
|
-
|
|
684
|
+
const length8 = input.length * 8;
|
|
685
|
+
const output = new Uint32Array(getOutputLength(length8));
|
|
647
686
|
|
|
648
|
-
for (
|
|
687
|
+
for (let i = 0; i < length8; i += 8) {
|
|
649
688
|
output[i >> 5] |= (input[i / 8] & 0xff) << i % 32;
|
|
650
689
|
}
|
|
651
690
|
|
|
@@ -658,8 +697,8 @@
|
|
|
658
697
|
|
|
659
698
|
|
|
660
699
|
function safeAdd(x, y) {
|
|
661
|
-
|
|
662
|
-
|
|
700
|
+
const lsw = (x & 0xffff) + (y & 0xffff);
|
|
701
|
+
const msw = (x >> 16) + (y >> 16) + (lsw >> 16);
|
|
663
702
|
return msw << 16 | lsw & 0xffff;
|
|
664
703
|
}
|
|
665
704
|
/*
|
|
@@ -697,9 +736,18 @@
|
|
|
697
736
|
|
|
698
737
|
v35('v3', 0x30, md5);
|
|
699
738
|
|
|
739
|
+
const randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
740
|
+
var native = {
|
|
741
|
+
randomUUID
|
|
742
|
+
};
|
|
743
|
+
|
|
700
744
|
function v4(options, buf, offset) {
|
|
745
|
+
if (native.randomUUID && !buf && !options) {
|
|
746
|
+
return native.randomUUID();
|
|
747
|
+
}
|
|
748
|
+
|
|
701
749
|
options = options || {};
|
|
702
|
-
|
|
750
|
+
const rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
|
|
703
751
|
|
|
704
752
|
rnds[6] = rnds[6] & 0x0f | 0x40;
|
|
705
753
|
rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
|
|
@@ -707,14 +755,14 @@
|
|
|
707
755
|
if (buf) {
|
|
708
756
|
offset = offset || 0;
|
|
709
757
|
|
|
710
|
-
for (
|
|
758
|
+
for (let i = 0; i < 16; ++i) {
|
|
711
759
|
buf[offset + i] = rnds[i];
|
|
712
760
|
}
|
|
713
761
|
|
|
714
762
|
return buf;
|
|
715
763
|
}
|
|
716
764
|
|
|
717
|
-
return
|
|
765
|
+
return unsafeStringify(rnds);
|
|
718
766
|
}
|
|
719
767
|
|
|
720
768
|
// Adapted from Chris Veness' SHA1 code at
|
|
@@ -740,15 +788,15 @@
|
|
|
740
788
|
}
|
|
741
789
|
|
|
742
790
|
function sha1(bytes) {
|
|
743
|
-
|
|
744
|
-
|
|
791
|
+
const K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6];
|
|
792
|
+
const H = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];
|
|
745
793
|
|
|
746
794
|
if (typeof bytes === 'string') {
|
|
747
|
-
|
|
795
|
+
const msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
|
|
748
796
|
|
|
749
797
|
bytes = [];
|
|
750
798
|
|
|
751
|
-
for (
|
|
799
|
+
for (let i = 0; i < msg.length; ++i) {
|
|
752
800
|
bytes.push(msg.charCodeAt(i));
|
|
753
801
|
}
|
|
754
802
|
} else if (!Array.isArray(bytes)) {
|
|
@@ -757,44 +805,44 @@
|
|
|
757
805
|
}
|
|
758
806
|
|
|
759
807
|
bytes.push(0x80);
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
808
|
+
const l = bytes.length / 4 + 2;
|
|
809
|
+
const N = Math.ceil(l / 16);
|
|
810
|
+
const M = new Array(N);
|
|
763
811
|
|
|
764
|
-
for (
|
|
765
|
-
|
|
812
|
+
for (let i = 0; i < N; ++i) {
|
|
813
|
+
const arr = new Uint32Array(16);
|
|
766
814
|
|
|
767
|
-
for (
|
|
768
|
-
arr[j] = bytes[
|
|
815
|
+
for (let j = 0; j < 16; ++j) {
|
|
816
|
+
arr[j] = bytes[i * 64 + j * 4] << 24 | bytes[i * 64 + j * 4 + 1] << 16 | bytes[i * 64 + j * 4 + 2] << 8 | bytes[i * 64 + j * 4 + 3];
|
|
769
817
|
}
|
|
770
818
|
|
|
771
|
-
M[
|
|
819
|
+
M[i] = arr;
|
|
772
820
|
}
|
|
773
821
|
|
|
774
822
|
M[N - 1][14] = (bytes.length - 1) * 8 / Math.pow(2, 32);
|
|
775
823
|
M[N - 1][14] = Math.floor(M[N - 1][14]);
|
|
776
824
|
M[N - 1][15] = (bytes.length - 1) * 8 & 0xffffffff;
|
|
777
825
|
|
|
778
|
-
for (
|
|
779
|
-
|
|
826
|
+
for (let i = 0; i < N; ++i) {
|
|
827
|
+
const W = new Uint32Array(80);
|
|
780
828
|
|
|
781
|
-
for (
|
|
782
|
-
W[t] = M[
|
|
829
|
+
for (let t = 0; t < 16; ++t) {
|
|
830
|
+
W[t] = M[i][t];
|
|
783
831
|
}
|
|
784
832
|
|
|
785
|
-
for (
|
|
786
|
-
W[
|
|
833
|
+
for (let t = 16; t < 80; ++t) {
|
|
834
|
+
W[t] = ROTL(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1);
|
|
787
835
|
}
|
|
788
836
|
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
837
|
+
let a = H[0];
|
|
838
|
+
let b = H[1];
|
|
839
|
+
let c = H[2];
|
|
840
|
+
let d = H[3];
|
|
841
|
+
let e = H[4];
|
|
794
842
|
|
|
795
|
-
for (
|
|
796
|
-
|
|
797
|
-
|
|
843
|
+
for (let t = 0; t < 80; ++t) {
|
|
844
|
+
const s = Math.floor(t / 20);
|
|
845
|
+
const T = ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[t] >>> 0;
|
|
798
846
|
e = d;
|
|
799
847
|
d = c;
|
|
800
848
|
c = ROTL(b, 30) >>> 0;
|
|
@@ -836,6 +884,24 @@
|
|
|
836
884
|
};
|
|
837
885
|
const getProviderVariables = (name) => manifestVariables[name] || {};
|
|
838
886
|
|
|
887
|
+
let stubs = [];
|
|
888
|
+
const addStubs = (newStubs) => {
|
|
889
|
+
stubs = [...stubs, ...newStubs];
|
|
890
|
+
};
|
|
891
|
+
const addStub = (stub) => {
|
|
892
|
+
stubs.push(stub);
|
|
893
|
+
};
|
|
894
|
+
const processStubs = () => {
|
|
895
|
+
try {
|
|
896
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
897
|
+
// @ts-ignore
|
|
898
|
+
stubs.forEach((stub) => api$1[stub.name](...(stub.arguments || [])));
|
|
899
|
+
}
|
|
900
|
+
catch (e) {
|
|
901
|
+
console.error(e);
|
|
902
|
+
}
|
|
903
|
+
};
|
|
904
|
+
|
|
839
905
|
const sendTag = ({ eventName, eventId, data, providerData, providers, options, }) => {
|
|
840
906
|
const payload = {
|
|
841
907
|
eventName,
|
|
@@ -850,6 +916,13 @@
|
|
|
850
916
|
postRequest(getTagURL(), payload, options).catch(info);
|
|
851
917
|
};
|
|
852
918
|
const handleTag = (eventName, data = {}, providers, options) => {
|
|
919
|
+
if (!isInitialized()) {
|
|
920
|
+
addStub({
|
|
921
|
+
name: 'tag',
|
|
922
|
+
arguments: [eventName, data, providers, options],
|
|
923
|
+
});
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
853
926
|
if (!allowTag(providers)) {
|
|
854
927
|
console.log('No consent');
|
|
855
928
|
return;
|
|
@@ -863,21 +936,19 @@
|
|
|
863
936
|
const providerData = {};
|
|
864
937
|
if (providerPackages) {
|
|
865
938
|
Object.values(providerPackages).forEach((pkg) => {
|
|
866
|
-
if (!allowProvider(providers, pkg.name)) {
|
|
939
|
+
if (!pkg || !pkg.tag || !allowProvider(providers, pkg.name)) {
|
|
867
940
|
return;
|
|
868
941
|
}
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
providerData[pkg.name] = result;
|
|
880
|
-
}
|
|
942
|
+
const result = pkg.tag({
|
|
943
|
+
userId,
|
|
944
|
+
eventName,
|
|
945
|
+
eventId,
|
|
946
|
+
data,
|
|
947
|
+
sendTag,
|
|
948
|
+
manifestVariables: getProviderVariables(pkg.name),
|
|
949
|
+
});
|
|
950
|
+
if (result) {
|
|
951
|
+
providerData[pkg.name] = result;
|
|
881
952
|
}
|
|
882
953
|
});
|
|
883
954
|
}
|
|
@@ -891,6 +962,30 @@
|
|
|
891
962
|
});
|
|
892
963
|
};
|
|
893
964
|
|
|
965
|
+
const handleData = (data, options) => {
|
|
966
|
+
if (!data || Object.keys(data).length === 0) {
|
|
967
|
+
console.error('Provide data for data API.');
|
|
968
|
+
return;
|
|
969
|
+
}
|
|
970
|
+
saveKV(data);
|
|
971
|
+
postRequest(getDataURL(), { data }, options).catch(info);
|
|
972
|
+
};
|
|
973
|
+
|
|
974
|
+
const saveDataToEdge = (key, value, provider) => {
|
|
975
|
+
if (!value) {
|
|
976
|
+
return;
|
|
977
|
+
}
|
|
978
|
+
if (typeof value !== 'string') {
|
|
979
|
+
try {
|
|
980
|
+
value = JSON.stringify(value);
|
|
981
|
+
}
|
|
982
|
+
catch (_a) {
|
|
983
|
+
console.log('Error stringify value');
|
|
984
|
+
return;
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
handleData({ [`${provider}::${key}`]: value });
|
|
988
|
+
};
|
|
894
989
|
const handleCaptureQuery = (provider, key, persistType) => {
|
|
895
990
|
if (!window) {
|
|
896
991
|
return;
|
|
@@ -899,7 +994,15 @@
|
|
|
899
994
|
if (!params || !params.get(key)) {
|
|
900
995
|
return;
|
|
901
996
|
}
|
|
902
|
-
|
|
997
|
+
const data = params.get(key);
|
|
998
|
+
if (!data) {
|
|
999
|
+
return;
|
|
1000
|
+
}
|
|
1001
|
+
if (persistType === 'edge') {
|
|
1002
|
+
saveDataToEdge(key, data, provider);
|
|
1003
|
+
return;
|
|
1004
|
+
}
|
|
1005
|
+
saveDataPerKey(persistType, provider, data, key);
|
|
903
1006
|
};
|
|
904
1007
|
const handleCaptureStorage = (provider, key, persistType, location) => {
|
|
905
1008
|
let data;
|
|
@@ -909,17 +1012,20 @@
|
|
|
909
1012
|
break;
|
|
910
1013
|
}
|
|
911
1014
|
case 'local': {
|
|
912
|
-
data =
|
|
1015
|
+
data = getData$1('local', key);
|
|
913
1016
|
break;
|
|
914
1017
|
}
|
|
915
1018
|
case 'session': {
|
|
916
|
-
data =
|
|
917
|
-
break;
|
|
1019
|
+
data = getData$1('session', key);
|
|
918
1020
|
}
|
|
919
1021
|
}
|
|
920
1022
|
if (!data) {
|
|
921
1023
|
return;
|
|
922
1024
|
}
|
|
1025
|
+
if (persistType === 'edge') {
|
|
1026
|
+
saveDataToEdge(key, data, provider);
|
|
1027
|
+
return;
|
|
1028
|
+
}
|
|
923
1029
|
saveDataPerKey(persistType, provider, data, key);
|
|
924
1030
|
};
|
|
925
1031
|
const handleCapture = (provider, params) => {
|
|
@@ -961,6 +1067,8 @@
|
|
|
961
1067
|
}
|
|
962
1068
|
}
|
|
963
1069
|
});
|
|
1070
|
+
setInitialized();
|
|
1071
|
+
processStubs();
|
|
964
1072
|
savePerKey('local', tagStorage, providers, providersKey);
|
|
965
1073
|
};
|
|
966
1074
|
|
|
@@ -969,6 +1077,9 @@
|
|
|
969
1077
|
if (!success) {
|
|
970
1078
|
return;
|
|
971
1079
|
}
|
|
1080
|
+
if (preferences.afterManifestEvents) {
|
|
1081
|
+
addStubs(preferences.afterManifestEvents);
|
|
1082
|
+
}
|
|
972
1083
|
const url = new URL(getInitURL());
|
|
973
1084
|
if (preferences.disableConsentCheck) {
|
|
974
1085
|
url.searchParams.set('consentDisabled', 'true');
|
|
@@ -1002,15 +1113,6 @@
|
|
|
1002
1113
|
}, options).catch(info);
|
|
1003
1114
|
};
|
|
1004
1115
|
|
|
1005
|
-
const handleData = (data, options) => {
|
|
1006
|
-
if (!data || Object.keys(data).length === 0) {
|
|
1007
|
-
console.error('Provide data for data API.');
|
|
1008
|
-
return;
|
|
1009
|
-
}
|
|
1010
|
-
saveKV(data);
|
|
1011
|
-
postRequest(getDataURL(), { data }, options).catch(info);
|
|
1012
|
-
};
|
|
1013
|
-
|
|
1014
1116
|
const handleGetData = (keys, callback) => {
|
|
1015
1117
|
if (!keys || keys.length === 0) {
|
|
1016
1118
|
console.error('Provide keys for get data API.');
|
|
@@ -1052,6 +1154,9 @@
|
|
|
1052
1154
|
const keys = (callback) => {
|
|
1053
1155
|
handleKeys(callback);
|
|
1054
1156
|
};
|
|
1157
|
+
const getUserId = () => {
|
|
1158
|
+
return handleGetUserId();
|
|
1159
|
+
};
|
|
1055
1160
|
|
|
1056
1161
|
// TODO https://github.com/blotoutio/solutions/issues/826
|
|
1057
1162
|
|
|
@@ -1088,16 +1193,9 @@
|
|
|
1088
1193
|
var api = new API();
|
|
1089
1194
|
|
|
1090
1195
|
(function () {
|
|
1091
|
-
const
|
|
1092
|
-
const sliced = [].slice.call(arg);
|
|
1093
|
-
if (!Array.isArray(sliced)) {
|
|
1094
|
-
return
|
|
1095
|
-
}
|
|
1096
|
-
|
|
1196
|
+
const handleStubs = (event) => {
|
|
1097
1197
|
try {
|
|
1098
|
-
|
|
1099
|
-
// @ts-ignore
|
|
1100
|
-
return library[sliced[0]](...sliced.slice(1))
|
|
1198
|
+
return library[event.name](...event.arguments)
|
|
1101
1199
|
} catch (e) {
|
|
1102
1200
|
console.error(e);
|
|
1103
1201
|
}
|
|
@@ -1106,19 +1204,61 @@
|
|
|
1106
1204
|
const library = api;
|
|
1107
1205
|
let stubs = [];
|
|
1108
1206
|
if (window.edgetag) {
|
|
1109
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1110
|
-
// @ts-ignore
|
|
1111
1207
|
stubs = window.edgetag.stubs || [];
|
|
1112
1208
|
}
|
|
1113
1209
|
|
|
1114
1210
|
// this needs to be regular function for arguments to work
|
|
1115
1211
|
window.edgetag = function () {
|
|
1116
|
-
|
|
1117
|
-
|
|
1212
|
+
const sliced = [].slice.call(arguments);
|
|
1213
|
+
if (!Array.isArray(sliced)) {
|
|
1214
|
+
return
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
try {
|
|
1218
|
+
return library[sliced[0]](...sliced.slice(1))
|
|
1219
|
+
} catch (e) {
|
|
1220
|
+
console.error(e);
|
|
1221
|
+
}
|
|
1118
1222
|
};
|
|
1119
1223
|
|
|
1120
|
-
|
|
1121
|
-
|
|
1224
|
+
const beforeManifestEvents = [];
|
|
1225
|
+
const afterManifestEvents = [];
|
|
1226
|
+
let initCall = null;
|
|
1227
|
+
|
|
1228
|
+
stubs.forEach((arg) => {
|
|
1229
|
+
const sliced = [].slice.call(arg);
|
|
1230
|
+
if (!Array.isArray(sliced)) {
|
|
1231
|
+
return
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
if (sliced[0] === 'init') {
|
|
1235
|
+
initCall = sliced.slice(1);
|
|
1236
|
+
return
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
if (sliced[0] === 'tag') {
|
|
1240
|
+
afterManifestEvents.push({
|
|
1241
|
+
name: sliced[0],
|
|
1242
|
+
arguments: sliced.slice(1),
|
|
1243
|
+
});
|
|
1244
|
+
return
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
beforeManifestEvents.push({
|
|
1248
|
+
name: sliced[0],
|
|
1249
|
+
arguments: sliced.slice(1),
|
|
1250
|
+
});
|
|
1251
|
+
});
|
|
1252
|
+
|
|
1253
|
+
if (initCall) {
|
|
1254
|
+
initCall[0]['afterManifestEvents'] = afterManifestEvents;
|
|
1255
|
+
handleStubs({
|
|
1256
|
+
name: 'init',
|
|
1257
|
+
arguments: initCall,
|
|
1258
|
+
});
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
beforeManifestEvents.forEach(handleStubs);
|
|
1122
1262
|
})();
|
|
1123
1263
|
|
|
1124
1264
|
})();
|