Skip to content

Instantly share code, notes, and snippets.

@vwo-kb
Created January 8, 2024 12:31
Show Gist options
  • Save vwo-kb/b134523e59e6f7fca35e43b13a9b7439 to your computer and use it in GitHub Desktop.
Save vwo-kb/b134523e59e6f7fca35e43b13a9b7439 to your computer and use it in GitHub Desktop.
<script>
(function () {
function convertToDefaultCurrency(amount, fromCurrency, precision = 2) {
var defaultCurrency = "USD";
var currencyConversion = {
"USD": 1, // Always keep the default store currency in the array
"EUR": 1.1, // Euro
"GBP": 0.82, // Great British Pound
"AUD": 1.43, // Australian Dollar
"CAD": 1.4, // Canadian Dollar
"CZK": 26, // Czech Koruna
"DKK": 7.3, // Danish Kroner
"HKD": 7.76, // Hong Kong Dollar
"ISK": 170, // Icelandic Krona
"ILS": 3.8, // Israeli New Shekel
"NZD": 1.43, // New Zealand Dollar
"NOK": 14, // Norwegian Kroner
"PLN": 4.6, // Polish Zloty
"RON": 5, // Romanian Leu
"SGD": 1.34, // Singaporean Dollar
"KRW": 1200, // South Korean Won
"SEK": 10.55, // Swedish Krona
"JPY": 120, // Japanese Yen
};
if (!currencyConversion[fromCurrency.toUpperCase()]) {
console.error("Unsupported currency code: {{ currency }}");
return null;
}
return (amount / currencyConversion[fromCurrency.toUpperCase()]).toFixed(precision);
}
// Example usage:
{% assign _vis_opt_revenue = total_price | divided_by: 100.0 %}
var revenue = {{ _vis_opt_revenue }};
var currency = "{{ currency }}";
var convertedAmount = convertToDefaultCurrency(revenue, currency);
// Do not change anything in the following two lines
window.VWO = window.VWO || [];
VWO.event = VWO.event || function () {VWO.push(["event"].concat([].slice.call(arguments)))};
VWO.event("purchase", {
"revenue": convertedAmount || revenue,
"currency": currency
});
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment