Overview
Currently, in Aspire, all dollar amounts are tracked as USD. This article serves as an example of how a brand could use a custom solution to convert their order amounts to USD before sending it to Aspire to record a conversion. This is recommended for all Link Tracking Offers where you'll be offering commission per sale and working with international influencers.
Requirements
Technical ability to write custom Javascript code before the conversion is recorded.
A link tracking offer with either Server Postback w/ Transaction ID or Server Postback w/ Partner ID as the conversion tracking method. You can also use Javascript SDK to implement Server Postback w/ Transaction ID.
An exchange rate API key (this example uses Exchange Rates API - https://exchangeratesapi.io/documentation/)
Please note that you must upgrade to a paid plan to use Exchange Rates API for this purpose. Their Basic plan (currently $10/month) provides up to 10,000 API requests per month and supports all base currencies.
Instructions
Before calling the postback or SDK to indicate a conversion, you should use the Exchange Rate API (or a similar service) to convert the order amount to USD. After converting, you will pass the new USD order amount to the Aspire postback or SDK.
The example below is for a Shopify brand using Server Postback w/ Transaction ID (implemented via Javascript SDK) using Exchange Rate API. This is a script that a Shopify brand would enter in their Order Status Page under Additional Scripts under Checkout in Shopify. More information on Javascript SDK can be found here.
⚠️ Important: the following code is not one-size-fits-all and is merely given as an example to help your technical team implement a solution that meets your needs. This script is specific to Shopify brands using Exchange Rates API.
Example Code for Shopify brands using Exchange Rates API
{% if first_time_accessed %}
<script>
// Adding the Aspire SDK
!function(){var o=window.tdl=window.tdl||[];if(o.invoked)window.console&&console.error&&console.error("Tune snippet has been included more than once.");else{o.invoked = !0, o.methods = ["init", "identify", "convert"], o.factory = function (n) { return function () { var e = Array.prototype.slice.call(arguments); return e.unshift(n), o.push(e), o } };for(var e=0;e<o.methods.length;e++){var n=o.methods[e];o[n]=o.factory(n)}o.init=function(e){var n=document.createElement("script");n.type="text/javascript",n.async=!0,n.src="https://js.go2sdk.com/v2/tune.js";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(n,t),o.domain=e}}}(); tdl.init("https://aspireiq.go2cloud.org")
const EXCHANGE_RATES_API_KEY = 'YOUR API KEY HERE';
async function convertToUSD(currencyCodeFrom, amount) {
// Documentation for this API: https://exchangeratesapi.io/documentation/
const response = await fetch(`https://api.exchangeratesapi.io/v1/convert?access_key=${EXCHANGE_RATES_API_KEY}&from=${currencyCodeFrom}&to=USD&amount=${amount}`,{method: 'GET' });
const result = await response.json();
return result.result;
}
async function recordAspireConversion() {
const cartSubtotalWithCurrency = '{{ subtotal_price | money_with_currency}}'
const cartSubtotalCurrencyCode = cartSubtotalWithCurrency.split(' ')[1];
const cartSubtotal = `{{ subtotal_price | money_without_currency | remove: ',' }}`
let cartSubtotalUSD = null;
if (cartSubtotalCurrencyCode === 'USD')
{cartSubtotalUSD = cartSubtotal; }
else {
try {
cartSubtotalUSD = await convertToUSD(cartSubtotalCurrencyCode, cartSubtotal);
} catch (error) {console.error('Error when converting cart subtotal to USD', error);}
}
tdl.convert({'amount': cartSubtotalUSD });
}
recordAspireConversion();
</script>
{% endif %}
Implementation Notes:
Enter the API key you received from Exchange Rates API in the placeholder value
YOUR API KEY HERE
in the snippet below:
const EXCHANGE_RATES_API_KEY = 'YOUR API KEY HERE';
Enter your store's currency in the placeholder value
{currencyCodeFrom}
in the snippet below:
`https://api.exchangeratesapi.io/v1/convert?access_key=${EXCHANGE_RATES_API_KEY}&from=${currencyCodeFrom}&to=USD&amount=${amount}`,
For example, if your store's local currency is GBP, you would replace{currencyCodeFrom}
with GBP so it looks like this:
https://api.exchangeratesapi.io/v1/convert?access_key=${EXCHANGE_RATES_API_KEY}&from=GBP&to=USD&amount=${amount}
If you have multiple Shopify stores with non-USD store currencies, you must add this script to each Shopify store (excluding your US store).