@blotoutio/edgetag-sdk-browser 0.33.0 → 0.34.0
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 +27 -5
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -335,7 +335,7 @@
|
|
|
335
335
|
referrer: getReferrer(),
|
|
336
336
|
search: getSearch(),
|
|
337
337
|
locale: getLocale(),
|
|
338
|
-
sdkVersion: "0.
|
|
338
|
+
sdkVersion: "0.34.0" ,
|
|
339
339
|
...(payload || {}),
|
|
340
340
|
};
|
|
341
341
|
let storage = {};
|
|
@@ -396,8 +396,12 @@
|
|
|
396
396
|
}
|
|
397
397
|
endpointUrl = url;
|
|
398
398
|
};
|
|
399
|
-
const getTagURL = () => {
|
|
400
|
-
|
|
399
|
+
const getTagURL = (options) => {
|
|
400
|
+
const url = new URL(generateUrl('/tag'));
|
|
401
|
+
if (options === null || options === void 0 ? void 0 : options.sync) {
|
|
402
|
+
url.searchParams.set('sync', 'true');
|
|
403
|
+
}
|
|
404
|
+
return url.toString();
|
|
401
405
|
};
|
|
402
406
|
const getInitURL = () => {
|
|
403
407
|
return generateUrl('/init');
|
|
@@ -593,7 +597,7 @@
|
|
|
593
597
|
if (providers) {
|
|
594
598
|
payload.providers = providers;
|
|
595
599
|
}
|
|
596
|
-
postRequest(getTagURL(), payload, options).catch(error);
|
|
600
|
+
postRequest(getTagURL(options), payload, options).catch(error);
|
|
597
601
|
};
|
|
598
602
|
const handleTag = (eventName, data = {}, providers, options) => {
|
|
599
603
|
if (!isInitialized()) {
|
|
@@ -707,6 +711,7 @@
|
|
|
707
711
|
postRequest(getDataURL(), { data, providers }, options).catch(error);
|
|
708
712
|
};
|
|
709
713
|
|
|
714
|
+
const cacheKey = `${keyPrefix}Cache`;
|
|
710
715
|
const saveDataToEdge = (key, value, provider) => {
|
|
711
716
|
if (!value) {
|
|
712
717
|
return;
|
|
@@ -745,6 +750,21 @@
|
|
|
745
750
|
}
|
|
746
751
|
saveDataPerKey(persistType, provider, data, key);
|
|
747
752
|
};
|
|
753
|
+
const getFromCache = (persistType, provider, key) => {
|
|
754
|
+
var _a;
|
|
755
|
+
const cache = getData$1(persistType === 'edge' ? 'local' : persistType, cacheKey);
|
|
756
|
+
return (_a = cache[provider]) === null || _a === void 0 ? void 0 : _a[key];
|
|
757
|
+
};
|
|
758
|
+
const saveToCache = (persistType, provider, key, value) => {
|
|
759
|
+
const cache = getData$1(persistType === 'edge' ? 'local' : persistType, cacheKey);
|
|
760
|
+
if (!cache[provider]) {
|
|
761
|
+
cache[provider] = { [key]: value };
|
|
762
|
+
}
|
|
763
|
+
else {
|
|
764
|
+
cache[provider][key] = value;
|
|
765
|
+
}
|
|
766
|
+
saveData(persistType === 'edge' ? 'local' : persistType, cache, cacheKey);
|
|
767
|
+
};
|
|
748
768
|
const handleCaptureStorage = (provider, key, persistType, location) => {
|
|
749
769
|
let data;
|
|
750
770
|
try {
|
|
@@ -765,10 +785,12 @@
|
|
|
765
785
|
catch {
|
|
766
786
|
return;
|
|
767
787
|
}
|
|
788
|
+
const cachedValue = getFromCache(persistType, provider, key);
|
|
789
|
+
saveToCache(persistType, provider, key, data);
|
|
768
790
|
if (!data) {
|
|
769
791
|
return;
|
|
770
792
|
}
|
|
771
|
-
if (persistType === 'edge') {
|
|
793
|
+
if (persistType === 'edge' && cachedValue !== data) {
|
|
772
794
|
saveDataToEdge(key, data, provider);
|
|
773
795
|
return;
|
|
774
796
|
}
|