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