@blotoutio/edgetag-sdk-js 0.66.0 → 0.67.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 +36 -2
- package/index.mjs +36 -2
- package/internal.d.ts +4 -0
- package/package.json +1 -1
package/index.cjs.js
CHANGED
|
@@ -562,7 +562,7 @@ const getStandardPayload = (destination, payload) => {
|
|
|
562
562
|
referrer: getReferrer(destination),
|
|
563
563
|
search: getSearch(destination),
|
|
564
564
|
locale: getLocale(),
|
|
565
|
-
sdkVersion: "0.
|
|
565
|
+
sdkVersion: "0.67.1" ,
|
|
566
566
|
...(payload || {}),
|
|
567
567
|
};
|
|
568
568
|
let storage = {};
|
|
@@ -674,6 +674,33 @@ const addStub = (destination, stub) => {
|
|
|
674
674
|
});
|
|
675
675
|
};
|
|
676
676
|
|
|
677
|
+
const preparePayloadWithConversion = (payloadData, currencySettings) => {
|
|
678
|
+
const currency = payloadData['currency'];
|
|
679
|
+
const value = parseFloat(payloadData['value']);
|
|
680
|
+
if (!currency || !currencySettings) {
|
|
681
|
+
return null;
|
|
682
|
+
}
|
|
683
|
+
const conversion = currencySettings.rates.find((rate) => rate.from === currency);
|
|
684
|
+
if (!conversion) {
|
|
685
|
+
return null;
|
|
686
|
+
}
|
|
687
|
+
payloadData['currency'] = conversion.to;
|
|
688
|
+
if (value) {
|
|
689
|
+
payloadData['value'] = parseFloat((value * conversion.value).toFixed(3));
|
|
690
|
+
}
|
|
691
|
+
if ('contents' in payloadData && Array.isArray(payloadData['contents'])) {
|
|
692
|
+
for (const content of payloadData['contents']) {
|
|
693
|
+
if ('item_price' in content) {
|
|
694
|
+
content.item_price = parseFloat((content.item_price * conversion.value).toFixed(3));
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
return {
|
|
699
|
+
providers: currencySettings.providers,
|
|
700
|
+
payload: payloadData,
|
|
701
|
+
};
|
|
702
|
+
};
|
|
703
|
+
|
|
677
704
|
const sendTag = (destination, { eventName, eventId, data, providerData, providers, options }) => {
|
|
678
705
|
const payload = {
|
|
679
706
|
eventName,
|
|
@@ -688,6 +715,7 @@ const sendTag = (destination, { eventName, eventId, data, providerData, provider
|
|
|
688
715
|
postRequest(getTagURL(destination, eventName, options), payload, options).catch(error);
|
|
689
716
|
};
|
|
690
717
|
const processTag = (destination, eventName, data = {}, providers, options) => {
|
|
718
|
+
var _a, _b;
|
|
691
719
|
if (!getSetting(destination, 'initialized')) {
|
|
692
720
|
addStub(destination, {
|
|
693
721
|
name: 'tag',
|
|
@@ -704,6 +732,7 @@ const processTag = (destination, eventName, data = {}, providers, options) => {
|
|
|
704
732
|
const userId = getUserId$1(destination);
|
|
705
733
|
const providerData = {};
|
|
706
734
|
const consent = getConsent$1(destination);
|
|
735
|
+
const conversion = preparePayloadWithConversion(JSON.parse(JSON.stringify(data)), getSetting(destination, 'currency'));
|
|
707
736
|
for (const pkg of providerPackages) {
|
|
708
737
|
if (!pkg || !pkg.name || !pkg.tag) {
|
|
709
738
|
continue;
|
|
@@ -724,11 +753,15 @@ const processTag = (destination, eventName, data = {}, providers, options) => {
|
|
|
724
753
|
log(`Consent is missing (${pkg.name}: ${variable.tagName})`);
|
|
725
754
|
continue;
|
|
726
755
|
}
|
|
756
|
+
const payload = ((_a = conversion === null || conversion === void 0 ? void 0 : conversion.providers) === null || _a === void 0 ? void 0 : _a.length) === 0 ||
|
|
757
|
+
((_b = conversion === null || conversion === void 0 ? void 0 : conversion.providers) === null || _b === void 0 ? void 0 : _b.includes(pkg.name))
|
|
758
|
+
? conversion.payload
|
|
759
|
+
: data;
|
|
727
760
|
result[variable.tagName] = pkg.tag({
|
|
728
761
|
userId,
|
|
729
762
|
eventName,
|
|
730
763
|
eventId,
|
|
731
|
-
data: JSON.parse(JSON.stringify(
|
|
764
|
+
data: JSON.parse(JSON.stringify(payload)),
|
|
732
765
|
sendTag: sendTag.bind(null, destination),
|
|
733
766
|
manifestVariables: variable.variableSet,
|
|
734
767
|
executionContext,
|
|
@@ -1187,6 +1220,7 @@ const handleInit = (preferences) => {
|
|
|
1187
1220
|
manifest: result.result,
|
|
1188
1221
|
browserPackages: Object.values(providers),
|
|
1189
1222
|
storageId: result.storageId,
|
|
1223
|
+
currency: result.currency,
|
|
1190
1224
|
});
|
|
1191
1225
|
if (result.storageId != null) {
|
|
1192
1226
|
savePerKey(preferences.edgeURL, 'local', tagStorage, result.storageId, storageIdKey);
|
package/index.mjs
CHANGED
|
@@ -560,7 +560,7 @@ const getStandardPayload = (destination, payload) => {
|
|
|
560
560
|
referrer: getReferrer(destination),
|
|
561
561
|
search: getSearch(destination),
|
|
562
562
|
locale: getLocale(),
|
|
563
|
-
sdkVersion: "0.
|
|
563
|
+
sdkVersion: "0.67.1" ,
|
|
564
564
|
...(payload || {}),
|
|
565
565
|
};
|
|
566
566
|
let storage = {};
|
|
@@ -672,6 +672,33 @@ const addStub = (destination, stub) => {
|
|
|
672
672
|
});
|
|
673
673
|
};
|
|
674
674
|
|
|
675
|
+
const preparePayloadWithConversion = (payloadData, currencySettings) => {
|
|
676
|
+
const currency = payloadData['currency'];
|
|
677
|
+
const value = parseFloat(payloadData['value']);
|
|
678
|
+
if (!currency || !currencySettings) {
|
|
679
|
+
return null;
|
|
680
|
+
}
|
|
681
|
+
const conversion = currencySettings.rates.find((rate) => rate.from === currency);
|
|
682
|
+
if (!conversion) {
|
|
683
|
+
return null;
|
|
684
|
+
}
|
|
685
|
+
payloadData['currency'] = conversion.to;
|
|
686
|
+
if (value) {
|
|
687
|
+
payloadData['value'] = parseFloat((value * conversion.value).toFixed(3));
|
|
688
|
+
}
|
|
689
|
+
if ('contents' in payloadData && Array.isArray(payloadData['contents'])) {
|
|
690
|
+
for (const content of payloadData['contents']) {
|
|
691
|
+
if ('item_price' in content) {
|
|
692
|
+
content.item_price = parseFloat((content.item_price * conversion.value).toFixed(3));
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
return {
|
|
697
|
+
providers: currencySettings.providers,
|
|
698
|
+
payload: payloadData,
|
|
699
|
+
};
|
|
700
|
+
};
|
|
701
|
+
|
|
675
702
|
const sendTag = (destination, { eventName, eventId, data, providerData, providers, options }) => {
|
|
676
703
|
const payload = {
|
|
677
704
|
eventName,
|
|
@@ -686,6 +713,7 @@ const sendTag = (destination, { eventName, eventId, data, providerData, provider
|
|
|
686
713
|
postRequest(getTagURL(destination, eventName, options), payload, options).catch(error);
|
|
687
714
|
};
|
|
688
715
|
const processTag = (destination, eventName, data = {}, providers, options) => {
|
|
716
|
+
var _a, _b;
|
|
689
717
|
if (!getSetting(destination, 'initialized')) {
|
|
690
718
|
addStub(destination, {
|
|
691
719
|
name: 'tag',
|
|
@@ -702,6 +730,7 @@ const processTag = (destination, eventName, data = {}, providers, options) => {
|
|
|
702
730
|
const userId = getUserId$1(destination);
|
|
703
731
|
const providerData = {};
|
|
704
732
|
const consent = getConsent$1(destination);
|
|
733
|
+
const conversion = preparePayloadWithConversion(JSON.parse(JSON.stringify(data)), getSetting(destination, 'currency'));
|
|
705
734
|
for (const pkg of providerPackages) {
|
|
706
735
|
if (!pkg || !pkg.name || !pkg.tag) {
|
|
707
736
|
continue;
|
|
@@ -722,11 +751,15 @@ const processTag = (destination, eventName, data = {}, providers, options) => {
|
|
|
722
751
|
log(`Consent is missing (${pkg.name}: ${variable.tagName})`);
|
|
723
752
|
continue;
|
|
724
753
|
}
|
|
754
|
+
const payload = ((_a = conversion === null || conversion === void 0 ? void 0 : conversion.providers) === null || _a === void 0 ? void 0 : _a.length) === 0 ||
|
|
755
|
+
((_b = conversion === null || conversion === void 0 ? void 0 : conversion.providers) === null || _b === void 0 ? void 0 : _b.includes(pkg.name))
|
|
756
|
+
? conversion.payload
|
|
757
|
+
: data;
|
|
725
758
|
result[variable.tagName] = pkg.tag({
|
|
726
759
|
userId,
|
|
727
760
|
eventName,
|
|
728
761
|
eventId,
|
|
729
|
-
data: JSON.parse(JSON.stringify(
|
|
762
|
+
data: JSON.parse(JSON.stringify(payload)),
|
|
730
763
|
sendTag: sendTag.bind(null, destination),
|
|
731
764
|
manifestVariables: variable.variableSet,
|
|
732
765
|
executionContext,
|
|
@@ -1185,6 +1218,7 @@ const handleInit = (preferences) => {
|
|
|
1185
1218
|
manifest: result.result,
|
|
1186
1219
|
browserPackages: Object.values(providers),
|
|
1187
1220
|
storageId: result.storageId,
|
|
1221
|
+
currency: result.currency,
|
|
1188
1222
|
});
|
|
1189
1223
|
if (result.storageId != null) {
|
|
1190
1224
|
savePerKey(preferences.edgeURL, 'local', tagStorage, result.storageId, storageIdKey);
|
package/internal.d.ts
CHANGED