Get Latest Exchange – If exchange rates are not found in

If exchange rates are not found in the browser memory or when a cache timeout occurs, the latest exchange rates are retrieved through an HTTP request using the base currency type you specified in the script configuration. The goal is to retrieve the latest exchange rates from the “exchangeeratesapi.io” service, cache them using sessionStorage, and pass the results to dataLayer. If exchange rates are in browser memory and the cache has not yet expired, the rates are retrieved from memory and inserted into the dataLayer. If the exchange rate object does not exist, OR if the source variable does not return a number, then the source variable is returned unchanged. NOTE: Currency conversion works only if the source variable exists at the time of conversion AND if the exchange rates have been successfully recovered. Otherwise, the variable divides the original variable by the rate to get the value of the original variable in the base currency configured in the custom HTML tag. The data-level variable for exchange rates first looks for the corresponding object in the GTM data model. You can use the ExchangeRates event name in the custom event trigger if you want to call the shortcut only after the exchange rate has been successfully recovered. You can also create a custom variable template in which you specify the source variable to be used and the currency symbol. This variable implies the value of the original variable and the rate object. There is no point in always retrieving the latest rates, so set the cache to a value you can live with. Change the cacheExpiresHours setting to specify how long rates are stored in the browser cache. At the data level, they can be used in JavaScript custom variables and custom variable templates to perform client-side conversions. You also need to specify the base currency against which the rates will be calculated. In this example, I use “EUR” because I want the fees to be calculated in euros.

Written by

Steven has over 12 years of internet experience, from design, to programming to internet marketing. It's his background in branding and marketing that led him to the path of protecting his clients reputation online, a specialized field that he has received years of training. When he is not researching the latest online marketing trends, you can find Austin meeting with clients and working to deliver businesses the results they need.