@blotoutio/edgetag-sdk-js 0.7.1 → 0.7.3
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 +84 -39
- package/index.esm.js +84 -39
- package/internal.d.ts +3 -0
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -59,11 +59,32 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
const getMessage = (error) => {
|
|
63
|
+
if (error instanceof Error) {
|
|
64
|
+
return error.message;
|
|
65
|
+
}
|
|
66
|
+
if (typeof error === 'string') {
|
|
67
|
+
return error;
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
return JSON.stringify(error);
|
|
71
|
+
}
|
|
72
|
+
catch (_a) {
|
|
73
|
+
return error;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const log = (data) => {
|
|
77
|
+
console.log('[EdgeTag]', getMessage(data));
|
|
78
|
+
};
|
|
79
|
+
const error = (data) => {
|
|
80
|
+
console.error('[EdgeTag]', getMessage(data));
|
|
81
|
+
};
|
|
82
|
+
|
|
62
83
|
let endpointUrl = '';
|
|
63
84
|
const generateUrl = (path) => {
|
|
64
85
|
const endpoint = getUrl();
|
|
65
86
|
if (!endpoint) {
|
|
66
|
-
|
|
87
|
+
log('URL is not valid');
|
|
67
88
|
return '';
|
|
68
89
|
}
|
|
69
90
|
return `${endpoint}${path}`;
|
|
@@ -109,7 +130,7 @@ const setPreferences = (preferences) => {
|
|
|
109
130
|
return false;
|
|
110
131
|
}
|
|
111
132
|
if (!preferences.edgeURL) {
|
|
112
|
-
|
|
133
|
+
error('Please provide URL for EdgeTag');
|
|
113
134
|
return false;
|
|
114
135
|
}
|
|
115
136
|
consentDisabled = !!preferences.disableConsentCheck;
|
|
@@ -190,6 +211,43 @@ const getUserAgent = () => {
|
|
|
190
211
|
return '';
|
|
191
212
|
}
|
|
192
213
|
};
|
|
214
|
+
const getReferrer = () => {
|
|
215
|
+
let referrer = '';
|
|
216
|
+
try {
|
|
217
|
+
const referrerUrl = new URL(document.referrer);
|
|
218
|
+
if (referrerUrl.host !== window.location.host) {
|
|
219
|
+
referrer = referrerUrl.href;
|
|
220
|
+
}
|
|
221
|
+
return referrer;
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
return referrer;
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
const getPageUrl = () => {
|
|
228
|
+
try {
|
|
229
|
+
return window.location.href;
|
|
230
|
+
}
|
|
231
|
+
catch (_a) {
|
|
232
|
+
return '';
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
const getSearch = () => {
|
|
236
|
+
try {
|
|
237
|
+
return window.location.search;
|
|
238
|
+
}
|
|
239
|
+
catch (_a) {
|
|
240
|
+
return '';
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
const getPageTitle = () => {
|
|
244
|
+
try {
|
|
245
|
+
return document.title;
|
|
246
|
+
}
|
|
247
|
+
catch (_a) {
|
|
248
|
+
return '';
|
|
249
|
+
}
|
|
250
|
+
};
|
|
193
251
|
const isProviderIncluded = (providers, providerValue) => {
|
|
194
252
|
return (providerValue || (providers['all'] === true && providerValue === undefined));
|
|
195
253
|
};
|
|
@@ -343,7 +401,7 @@ const saveLocal = (value, key) => {
|
|
|
343
401
|
localStorage.setItem(key, JSON.stringify(value));
|
|
344
402
|
}
|
|
345
403
|
catch (_a) {
|
|
346
|
-
|
|
404
|
+
log('Local storage not supported.');
|
|
347
405
|
}
|
|
348
406
|
};
|
|
349
407
|
const getLocal = (key) => {
|
|
@@ -369,7 +427,7 @@ const saveSession = (value, key) => {
|
|
|
369
427
|
sessionStorage.setItem(key, JSON.stringify(value));
|
|
370
428
|
}
|
|
371
429
|
catch (_a) {
|
|
372
|
-
|
|
430
|
+
log('Session storage not supported.');
|
|
373
431
|
}
|
|
374
432
|
};
|
|
375
433
|
const getSession = (key) => {
|
|
@@ -413,8 +471,7 @@ const beacon = (url, payload) => {
|
|
|
413
471
|
return navigator.sendBeacon(url, blob);
|
|
414
472
|
}
|
|
415
473
|
catch (e) {
|
|
416
|
-
|
|
417
|
-
return Promise.reject(new Error('Beacon not supported'));
|
|
474
|
+
return Promise.reject(new Error('Beacon not supported.'));
|
|
418
475
|
}
|
|
419
476
|
};
|
|
420
477
|
const fallbackAjax = (method, url, payload) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -452,7 +509,7 @@ const ajax = (method, url, payload) => __awaiter(void 0, void 0, void 0, functio
|
|
|
452
509
|
return yield fallbackAjax(method, url, payload)
|
|
453
510
|
.then((data) => {
|
|
454
511
|
if (data.status < 200 || data.status >= 300) {
|
|
455
|
-
return Promise.reject(new Error(JSON.stringify(data.body)));
|
|
512
|
+
return Promise.reject(new Error(`Request failed with code ${data.status} occurred: ${JSON.stringify(data.body)}`));
|
|
456
513
|
}
|
|
457
514
|
return Promise.resolve(data.body);
|
|
458
515
|
})
|
|
@@ -469,25 +526,16 @@ const ajax = (method, url, payload) => __awaiter(void 0, void 0, void 0, functio
|
|
|
469
526
|
.then((response) => response.json().then((data) => ({ status: response.status, body: data })))
|
|
470
527
|
.then((data) => {
|
|
471
528
|
if (data.status < 200 || data.status >= 300) {
|
|
472
|
-
|
|
473
|
-
return Promise.reject(new Error(JSON.stringify(data.body)));
|
|
529
|
+
return Promise.reject(new Error(`Request failed with code ${data.status}: ${JSON.stringify(data.body)}`));
|
|
474
530
|
}
|
|
475
531
|
return Promise.resolve(data.body);
|
|
476
532
|
})
|
|
477
533
|
.catch((error) => {
|
|
478
|
-
// Q: do we need to retry?
|
|
479
534
|
return Promise.reject(new Error(error));
|
|
480
535
|
});
|
|
481
536
|
});
|
|
482
537
|
const getStandardPayload = (payload) => {
|
|
483
|
-
|
|
484
|
-
try {
|
|
485
|
-
pageUrl = window.location.href;
|
|
486
|
-
}
|
|
487
|
-
catch (_a) {
|
|
488
|
-
pageUrl = '';
|
|
489
|
-
}
|
|
490
|
-
const data = Object.assign({ pageUrl, userAgent: getUserAgent() }, (payload || {}));
|
|
538
|
+
const data = Object.assign({ pageUrl: getPageUrl(), pageTitle: getPageTitle(), userAgent: getUserAgent(), referrer: getReferrer(), search: getSearch() }, (payload || {}));
|
|
491
539
|
let storage = {};
|
|
492
540
|
const session = getData$1('session');
|
|
493
541
|
if (session) {
|
|
@@ -503,7 +551,7 @@ const getStandardPayload = (payload) => {
|
|
|
503
551
|
function postRequest(url, data, options) {
|
|
504
552
|
return __awaiter(this, void 0, void 0, function* () {
|
|
505
553
|
if (!url) {
|
|
506
|
-
return Promise.reject(new Error('URL is empty'));
|
|
554
|
+
return Promise.reject(new Error('URL is empty.'));
|
|
507
555
|
}
|
|
508
556
|
const payload = getStandardPayload(data);
|
|
509
557
|
if (options && options.method === 'beacon') {
|
|
@@ -515,7 +563,7 @@ function postRequest(url, data, options) {
|
|
|
515
563
|
function getRequest(url, options) {
|
|
516
564
|
return __awaiter(this, void 0, void 0, function* () {
|
|
517
565
|
if (!url) {
|
|
518
|
-
return Promise.reject(new Error('URL is empty'));
|
|
566
|
+
return Promise.reject(new Error('URL is empty.'));
|
|
519
567
|
}
|
|
520
568
|
if (options && options.method === 'beacon') {
|
|
521
569
|
return {
|
|
@@ -526,9 +574,6 @@ function getRequest(url, options) {
|
|
|
526
574
|
});
|
|
527
575
|
}
|
|
528
576
|
|
|
529
|
-
const info = (data) => {
|
|
530
|
-
};
|
|
531
|
-
|
|
532
577
|
let memoryConsent;
|
|
533
578
|
const saveConsent = (consent) => {
|
|
534
579
|
setConsent(consent);
|
|
@@ -539,7 +584,7 @@ const handleConsent = (consent) => {
|
|
|
539
584
|
consentString: consent,
|
|
540
585
|
};
|
|
541
586
|
saveConsent(consent);
|
|
542
|
-
postRequest(getConsentURL(), payload).catch(
|
|
587
|
+
postRequest(getConsentURL(), payload).catch(error);
|
|
543
588
|
};
|
|
544
589
|
const setConsent = (newConsent) => {
|
|
545
590
|
memoryConsent = newConsent;
|
|
@@ -591,13 +636,13 @@ const processStubs = () => {
|
|
|
591
636
|
stubs = [];
|
|
592
637
|
}
|
|
593
638
|
catch (e) {
|
|
594
|
-
|
|
639
|
+
error(e);
|
|
595
640
|
}
|
|
596
641
|
};
|
|
597
642
|
|
|
598
643
|
const sendTag = ({ eventName, eventId, data, providerData, providers, options, }) => {
|
|
599
644
|
if (!allowProviders(providers)) {
|
|
600
|
-
|
|
645
|
+
log('Provider is not allowed.');
|
|
601
646
|
return;
|
|
602
647
|
}
|
|
603
648
|
const payload = {
|
|
@@ -610,7 +655,7 @@ const sendTag = ({ eventName, eventId, data, providerData, providers, options, }
|
|
|
610
655
|
if (providers) {
|
|
611
656
|
payload.providers = providers;
|
|
612
657
|
}
|
|
613
|
-
postRequest(getTagURL(), payload, options).catch(
|
|
658
|
+
postRequest(getTagURL(), payload, options).catch(error);
|
|
614
659
|
};
|
|
615
660
|
const handleTag = (eventName, data = {}, providers, options) => {
|
|
616
661
|
if (!isInitialized()) {
|
|
@@ -621,11 +666,11 @@ const handleTag = (eventName, data = {}, providers, options) => {
|
|
|
621
666
|
return;
|
|
622
667
|
}
|
|
623
668
|
if (!allowProviders(providers)) {
|
|
624
|
-
|
|
669
|
+
log('Provider is not allowed.');
|
|
625
670
|
return;
|
|
626
671
|
}
|
|
627
672
|
if (!allowTag(providers)) {
|
|
628
|
-
|
|
673
|
+
log('Consent is missing.');
|
|
629
674
|
return;
|
|
630
675
|
}
|
|
631
676
|
let eventId = data['eventId'];
|
|
@@ -665,11 +710,11 @@ const handleTag = (eventName, data = {}, providers, options) => {
|
|
|
665
710
|
|
|
666
711
|
const handleData = (data, options) => {
|
|
667
712
|
if (!data || Object.keys(data).length === 0) {
|
|
668
|
-
|
|
713
|
+
error('Provide data for data API.');
|
|
669
714
|
return;
|
|
670
715
|
}
|
|
671
716
|
saveKV(data);
|
|
672
|
-
postRequest(getDataURL(), { data }, options).catch(
|
|
717
|
+
postRequest(getDataURL(), { data }, options).catch(error);
|
|
673
718
|
};
|
|
674
719
|
|
|
675
720
|
const saveDataToEdge = (key, value, provider) => {
|
|
@@ -681,7 +726,7 @@ const saveDataToEdge = (key, value, provider) => {
|
|
|
681
726
|
value = JSON.stringify(value);
|
|
682
727
|
}
|
|
683
728
|
catch (_a) {
|
|
684
|
-
|
|
729
|
+
log('Error stringify value.');
|
|
685
730
|
return;
|
|
686
731
|
}
|
|
687
732
|
}
|
|
@@ -801,17 +846,17 @@ const handleInit = (preferences) => {
|
|
|
801
846
|
getRequest(url.href)
|
|
802
847
|
.then((result) => {
|
|
803
848
|
if (!result) {
|
|
804
|
-
|
|
849
|
+
log('Initialization failed');
|
|
805
850
|
return;
|
|
806
851
|
}
|
|
807
852
|
handleManifest(result.result);
|
|
808
853
|
})
|
|
809
|
-
.catch(
|
|
854
|
+
.catch(error);
|
|
810
855
|
};
|
|
811
856
|
|
|
812
857
|
const handleUser = (key, value, options) => {
|
|
813
858
|
if (!key || !value) {
|
|
814
|
-
|
|
859
|
+
error('Key or Value is missing in user API.');
|
|
815
860
|
return;
|
|
816
861
|
}
|
|
817
862
|
saveKV({
|
|
@@ -820,19 +865,19 @@ const handleUser = (key, value, options) => {
|
|
|
820
865
|
postRequest(getUserURL(), {
|
|
821
866
|
key,
|
|
822
867
|
value,
|
|
823
|
-
}, options).catch(
|
|
868
|
+
}, options).catch(error);
|
|
824
869
|
};
|
|
825
870
|
|
|
826
871
|
const handleGetData = (keys, callback) => {
|
|
827
872
|
if (!keys || keys.length === 0) {
|
|
828
|
-
|
|
873
|
+
error('Provide keys for get data API.');
|
|
829
874
|
return;
|
|
830
875
|
}
|
|
831
876
|
getRequest(getGetDataURL(keys))
|
|
832
877
|
.then((result) => {
|
|
833
878
|
callback((result === null || result === void 0 ? void 0 : result.result) || {});
|
|
834
879
|
})
|
|
835
|
-
.catch(
|
|
880
|
+
.catch(error);
|
|
836
881
|
};
|
|
837
882
|
|
|
838
883
|
const handleKeys = (callback) => {
|
|
@@ -840,7 +885,7 @@ const handleKeys = (callback) => {
|
|
|
840
885
|
.then((result) => {
|
|
841
886
|
callback((result === null || result === void 0 ? void 0 : result.result) || []);
|
|
842
887
|
})
|
|
843
|
-
.catch(
|
|
888
|
+
.catch(error);
|
|
844
889
|
};
|
|
845
890
|
|
|
846
891
|
const init = (preferences) => {
|
package/index.esm.js
CHANGED
|
@@ -37,11 +37,32 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
const getMessage = (error) => {
|
|
41
|
+
if (error instanceof Error) {
|
|
42
|
+
return error.message;
|
|
43
|
+
}
|
|
44
|
+
if (typeof error === 'string') {
|
|
45
|
+
return error;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
return JSON.stringify(error);
|
|
49
|
+
}
|
|
50
|
+
catch (_a) {
|
|
51
|
+
return error;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const log = (data) => {
|
|
55
|
+
console.log('[EdgeTag]', getMessage(data));
|
|
56
|
+
};
|
|
57
|
+
const error = (data) => {
|
|
58
|
+
console.error('[EdgeTag]', getMessage(data));
|
|
59
|
+
};
|
|
60
|
+
|
|
40
61
|
let endpointUrl = '';
|
|
41
62
|
const generateUrl = (path) => {
|
|
42
63
|
const endpoint = getUrl();
|
|
43
64
|
if (!endpoint) {
|
|
44
|
-
|
|
65
|
+
log('URL is not valid');
|
|
45
66
|
return '';
|
|
46
67
|
}
|
|
47
68
|
return `${endpoint}${path}`;
|
|
@@ -87,7 +108,7 @@ const setPreferences = (preferences) => {
|
|
|
87
108
|
return false;
|
|
88
109
|
}
|
|
89
110
|
if (!preferences.edgeURL) {
|
|
90
|
-
|
|
111
|
+
error('Please provide URL for EdgeTag');
|
|
91
112
|
return false;
|
|
92
113
|
}
|
|
93
114
|
consentDisabled = !!preferences.disableConsentCheck;
|
|
@@ -168,6 +189,43 @@ const getUserAgent = () => {
|
|
|
168
189
|
return '';
|
|
169
190
|
}
|
|
170
191
|
};
|
|
192
|
+
const getReferrer = () => {
|
|
193
|
+
let referrer = '';
|
|
194
|
+
try {
|
|
195
|
+
const referrerUrl = new URL(document.referrer);
|
|
196
|
+
if (referrerUrl.host !== window.location.host) {
|
|
197
|
+
referrer = referrerUrl.href;
|
|
198
|
+
}
|
|
199
|
+
return referrer;
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
return referrer;
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
const getPageUrl = () => {
|
|
206
|
+
try {
|
|
207
|
+
return window.location.href;
|
|
208
|
+
}
|
|
209
|
+
catch (_a) {
|
|
210
|
+
return '';
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
const getSearch = () => {
|
|
214
|
+
try {
|
|
215
|
+
return window.location.search;
|
|
216
|
+
}
|
|
217
|
+
catch (_a) {
|
|
218
|
+
return '';
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
const getPageTitle = () => {
|
|
222
|
+
try {
|
|
223
|
+
return document.title;
|
|
224
|
+
}
|
|
225
|
+
catch (_a) {
|
|
226
|
+
return '';
|
|
227
|
+
}
|
|
228
|
+
};
|
|
171
229
|
const isProviderIncluded = (providers, providerValue) => {
|
|
172
230
|
return (providerValue || (providers['all'] === true && providerValue === undefined));
|
|
173
231
|
};
|
|
@@ -321,7 +379,7 @@ const saveLocal = (value, key) => {
|
|
|
321
379
|
localStorage.setItem(key, JSON.stringify(value));
|
|
322
380
|
}
|
|
323
381
|
catch (_a) {
|
|
324
|
-
|
|
382
|
+
log('Local storage not supported.');
|
|
325
383
|
}
|
|
326
384
|
};
|
|
327
385
|
const getLocal = (key) => {
|
|
@@ -347,7 +405,7 @@ const saveSession = (value, key) => {
|
|
|
347
405
|
sessionStorage.setItem(key, JSON.stringify(value));
|
|
348
406
|
}
|
|
349
407
|
catch (_a) {
|
|
350
|
-
|
|
408
|
+
log('Session storage not supported.');
|
|
351
409
|
}
|
|
352
410
|
};
|
|
353
411
|
const getSession = (key) => {
|
|
@@ -391,8 +449,7 @@ const beacon = (url, payload) => {
|
|
|
391
449
|
return navigator.sendBeacon(url, blob);
|
|
392
450
|
}
|
|
393
451
|
catch (e) {
|
|
394
|
-
|
|
395
|
-
return Promise.reject(new Error('Beacon not supported'));
|
|
452
|
+
return Promise.reject(new Error('Beacon not supported.'));
|
|
396
453
|
}
|
|
397
454
|
};
|
|
398
455
|
const fallbackAjax = (method, url, payload) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -430,7 +487,7 @@ const ajax = (method, url, payload) => __awaiter(void 0, void 0, void 0, functio
|
|
|
430
487
|
return yield fallbackAjax(method, url, payload)
|
|
431
488
|
.then((data) => {
|
|
432
489
|
if (data.status < 200 || data.status >= 300) {
|
|
433
|
-
return Promise.reject(new Error(JSON.stringify(data.body)));
|
|
490
|
+
return Promise.reject(new Error(`Request failed with code ${data.status} occurred: ${JSON.stringify(data.body)}`));
|
|
434
491
|
}
|
|
435
492
|
return Promise.resolve(data.body);
|
|
436
493
|
})
|
|
@@ -447,25 +504,16 @@ const ajax = (method, url, payload) => __awaiter(void 0, void 0, void 0, functio
|
|
|
447
504
|
.then((response) => response.json().then((data) => ({ status: response.status, body: data })))
|
|
448
505
|
.then((data) => {
|
|
449
506
|
if (data.status < 200 || data.status >= 300) {
|
|
450
|
-
|
|
451
|
-
return Promise.reject(new Error(JSON.stringify(data.body)));
|
|
507
|
+
return Promise.reject(new Error(`Request failed with code ${data.status}: ${JSON.stringify(data.body)}`));
|
|
452
508
|
}
|
|
453
509
|
return Promise.resolve(data.body);
|
|
454
510
|
})
|
|
455
511
|
.catch((error) => {
|
|
456
|
-
// Q: do we need to retry?
|
|
457
512
|
return Promise.reject(new Error(error));
|
|
458
513
|
});
|
|
459
514
|
});
|
|
460
515
|
const getStandardPayload = (payload) => {
|
|
461
|
-
|
|
462
|
-
try {
|
|
463
|
-
pageUrl = window.location.href;
|
|
464
|
-
}
|
|
465
|
-
catch (_a) {
|
|
466
|
-
pageUrl = '';
|
|
467
|
-
}
|
|
468
|
-
const data = Object.assign({ pageUrl, userAgent: getUserAgent() }, (payload || {}));
|
|
516
|
+
const data = Object.assign({ pageUrl: getPageUrl(), pageTitle: getPageTitle(), userAgent: getUserAgent(), referrer: getReferrer(), search: getSearch() }, (payload || {}));
|
|
469
517
|
let storage = {};
|
|
470
518
|
const session = getData$1('session');
|
|
471
519
|
if (session) {
|
|
@@ -481,7 +529,7 @@ const getStandardPayload = (payload) => {
|
|
|
481
529
|
function postRequest(url, data, options) {
|
|
482
530
|
return __awaiter(this, void 0, void 0, function* () {
|
|
483
531
|
if (!url) {
|
|
484
|
-
return Promise.reject(new Error('URL is empty'));
|
|
532
|
+
return Promise.reject(new Error('URL is empty.'));
|
|
485
533
|
}
|
|
486
534
|
const payload = getStandardPayload(data);
|
|
487
535
|
if (options && options.method === 'beacon') {
|
|
@@ -493,7 +541,7 @@ function postRequest(url, data, options) {
|
|
|
493
541
|
function getRequest(url, options) {
|
|
494
542
|
return __awaiter(this, void 0, void 0, function* () {
|
|
495
543
|
if (!url) {
|
|
496
|
-
return Promise.reject(new Error('URL is empty'));
|
|
544
|
+
return Promise.reject(new Error('URL is empty.'));
|
|
497
545
|
}
|
|
498
546
|
if (options && options.method === 'beacon') {
|
|
499
547
|
return {
|
|
@@ -504,9 +552,6 @@ function getRequest(url, options) {
|
|
|
504
552
|
});
|
|
505
553
|
}
|
|
506
554
|
|
|
507
|
-
const info = (data) => {
|
|
508
|
-
};
|
|
509
|
-
|
|
510
555
|
let memoryConsent;
|
|
511
556
|
const saveConsent = (consent) => {
|
|
512
557
|
setConsent(consent);
|
|
@@ -517,7 +562,7 @@ const handleConsent = (consent) => {
|
|
|
517
562
|
consentString: consent,
|
|
518
563
|
};
|
|
519
564
|
saveConsent(consent);
|
|
520
|
-
postRequest(getConsentURL(), payload).catch(
|
|
565
|
+
postRequest(getConsentURL(), payload).catch(error);
|
|
521
566
|
};
|
|
522
567
|
const setConsent = (newConsent) => {
|
|
523
568
|
memoryConsent = newConsent;
|
|
@@ -569,13 +614,13 @@ const processStubs = () => {
|
|
|
569
614
|
stubs = [];
|
|
570
615
|
}
|
|
571
616
|
catch (e) {
|
|
572
|
-
|
|
617
|
+
error(e);
|
|
573
618
|
}
|
|
574
619
|
};
|
|
575
620
|
|
|
576
621
|
const sendTag = ({ eventName, eventId, data, providerData, providers, options, }) => {
|
|
577
622
|
if (!allowProviders(providers)) {
|
|
578
|
-
|
|
623
|
+
log('Provider is not allowed.');
|
|
579
624
|
return;
|
|
580
625
|
}
|
|
581
626
|
const payload = {
|
|
@@ -588,7 +633,7 @@ const sendTag = ({ eventName, eventId, data, providerData, providers, options, }
|
|
|
588
633
|
if (providers) {
|
|
589
634
|
payload.providers = providers;
|
|
590
635
|
}
|
|
591
|
-
postRequest(getTagURL(), payload, options).catch(
|
|
636
|
+
postRequest(getTagURL(), payload, options).catch(error);
|
|
592
637
|
};
|
|
593
638
|
const handleTag = (eventName, data = {}, providers, options) => {
|
|
594
639
|
if (!isInitialized()) {
|
|
@@ -599,11 +644,11 @@ const handleTag = (eventName, data = {}, providers, options) => {
|
|
|
599
644
|
return;
|
|
600
645
|
}
|
|
601
646
|
if (!allowProviders(providers)) {
|
|
602
|
-
|
|
647
|
+
log('Provider is not allowed.');
|
|
603
648
|
return;
|
|
604
649
|
}
|
|
605
650
|
if (!allowTag(providers)) {
|
|
606
|
-
|
|
651
|
+
log('Consent is missing.');
|
|
607
652
|
return;
|
|
608
653
|
}
|
|
609
654
|
let eventId = data['eventId'];
|
|
@@ -643,11 +688,11 @@ const handleTag = (eventName, data = {}, providers, options) => {
|
|
|
643
688
|
|
|
644
689
|
const handleData = (data, options) => {
|
|
645
690
|
if (!data || Object.keys(data).length === 0) {
|
|
646
|
-
|
|
691
|
+
error('Provide data for data API.');
|
|
647
692
|
return;
|
|
648
693
|
}
|
|
649
694
|
saveKV(data);
|
|
650
|
-
postRequest(getDataURL(), { data }, options).catch(
|
|
695
|
+
postRequest(getDataURL(), { data }, options).catch(error);
|
|
651
696
|
};
|
|
652
697
|
|
|
653
698
|
const saveDataToEdge = (key, value, provider) => {
|
|
@@ -659,7 +704,7 @@ const saveDataToEdge = (key, value, provider) => {
|
|
|
659
704
|
value = JSON.stringify(value);
|
|
660
705
|
}
|
|
661
706
|
catch (_a) {
|
|
662
|
-
|
|
707
|
+
log('Error stringify value.');
|
|
663
708
|
return;
|
|
664
709
|
}
|
|
665
710
|
}
|
|
@@ -779,17 +824,17 @@ const handleInit = (preferences) => {
|
|
|
779
824
|
getRequest(url.href)
|
|
780
825
|
.then((result) => {
|
|
781
826
|
if (!result) {
|
|
782
|
-
|
|
827
|
+
log('Initialization failed');
|
|
783
828
|
return;
|
|
784
829
|
}
|
|
785
830
|
handleManifest(result.result);
|
|
786
831
|
})
|
|
787
|
-
.catch(
|
|
832
|
+
.catch(error);
|
|
788
833
|
};
|
|
789
834
|
|
|
790
835
|
const handleUser = (key, value, options) => {
|
|
791
836
|
if (!key || !value) {
|
|
792
|
-
|
|
837
|
+
error('Key or Value is missing in user API.');
|
|
793
838
|
return;
|
|
794
839
|
}
|
|
795
840
|
saveKV({
|
|
@@ -798,19 +843,19 @@ const handleUser = (key, value, options) => {
|
|
|
798
843
|
postRequest(getUserURL(), {
|
|
799
844
|
key,
|
|
800
845
|
value,
|
|
801
|
-
}, options).catch(
|
|
846
|
+
}, options).catch(error);
|
|
802
847
|
};
|
|
803
848
|
|
|
804
849
|
const handleGetData = (keys, callback) => {
|
|
805
850
|
if (!keys || keys.length === 0) {
|
|
806
|
-
|
|
851
|
+
error('Provide keys for get data API.');
|
|
807
852
|
return;
|
|
808
853
|
}
|
|
809
854
|
getRequest(getGetDataURL(keys))
|
|
810
855
|
.then((result) => {
|
|
811
856
|
callback((result === null || result === void 0 ? void 0 : result.result) || {});
|
|
812
857
|
})
|
|
813
|
-
.catch(
|
|
858
|
+
.catch(error);
|
|
814
859
|
};
|
|
815
860
|
|
|
816
861
|
const handleKeys = (callback) => {
|
|
@@ -818,7 +863,7 @@ const handleKeys = (callback) => {
|
|
|
818
863
|
.then((result) => {
|
|
819
864
|
callback((result === null || result === void 0 ? void 0 : result.result) || []);
|
|
820
865
|
})
|
|
821
|
-
.catch(
|
|
866
|
+
.catch(error);
|
|
822
867
|
};
|
|
823
868
|
|
|
824
869
|
const init = (preferences) => {
|
package/internal.d.ts
CHANGED