@blotoutio/edgetag-sdk-js
Advanced tools
Comparing version 0.66.0 to 0.67.0
@@ -565,3 +565,3 @@ 'use strict'; | ||
locale: getLocale(), | ||
sdkVersion: "0.66.0" , | ||
sdkVersion: "0.67.0" , | ||
...(payload || {}), | ||
@@ -678,2 +678,29 @@ }; | ||
const preparePayloadWithConversion = (payloadData, currencySettings) => { | ||
const currency = payloadData['currency']; | ||
const value = parseFloat(payloadData['value']); | ||
if (!currency || !currencySettings) { | ||
return null; | ||
} | ||
const conversion = currencySettings.rates.find((rate) => rate.from === currency); | ||
if (!conversion) { | ||
return null; | ||
} | ||
payloadData['currency'] = conversion.to; | ||
if (value) { | ||
payloadData['value'] = parseFloat((value * conversion.value).toFixed(3)); | ||
} | ||
if ('contents' in payloadData && Array.isArray(payloadData['contents'])) { | ||
for (const content of payloadData['contents']) { | ||
if ('item_price' in content) { | ||
content.item_price = parseFloat((content.item_price * conversion.value).toFixed(3)); | ||
} | ||
} | ||
} | ||
return { | ||
providers: currencySettings.providers, | ||
payload: payloadData, | ||
}; | ||
}; | ||
const sendTag = (destination, { eventName, eventId, data, providerData, providers, options }) => { | ||
@@ -693,2 +720,3 @@ const payload = { | ||
const processTag = (destination, eventName, data = {}, providers, options) => { | ||
var _a, _b; | ||
if (!getSetting(destination, 'initialized')) { | ||
@@ -710,2 +738,3 @@ addStub(destination, { | ||
const consent = getConsent$1(destination); | ||
const conversion = preparePayloadWithConversion(JSON.parse(JSON.stringify(data)), getSetting(destination, 'currency')); | ||
for (const pkg of providerPackages) { | ||
@@ -731,2 +760,6 @@ if (!pkg || !pkg.name || !pkg.tag) { | ||
} | ||
const payload = ((_a = conversion === null || conversion === void 0 ? void 0 : conversion.providers) === null || _a === void 0 ? void 0 : _a.length) === 0 || | ||
((_b = conversion === null || conversion === void 0 ? void 0 : conversion.providers) === null || _b === void 0 ? void 0 : _b.includes(pkg.name)) | ||
? conversion.payload | ||
: data; | ||
result[variable.tagName] = pkg.tag({ | ||
@@ -736,3 +769,3 @@ userId, | ||
eventId, | ||
data: JSON.parse(JSON.stringify(data)), | ||
data: JSON.parse(JSON.stringify(payload)), | ||
sendTag: sendTag.bind(null, destination), | ||
@@ -1196,2 +1229,3 @@ manifestVariables: variable.variableSet, | ||
storageId: result.storageId, | ||
currency: result.currency, | ||
}); | ||
@@ -1198,0 +1232,0 @@ if (result.storageId != null) { |
@@ -59,2 +59,6 @@ import { | ||
} | ||
currency?: { | ||
providers: string[] | ||
rates: { from: string; to: string; value: number }[] | ||
} | ||
} |
{ | ||
"name": "@blotoutio/edgetag-sdk-js", | ||
"version": "0.66.0", | ||
"version": "0.67.0", | ||
"description": "JS SDK for EdgeTag", | ||
@@ -5,0 +5,0 @@ "author": "Blotout", |
Sorry, the diff of this file is not supported yet
95902
2924