Get Latest Exchange – If the prices are not in the browser

https://www.youtube.com/watch?v=tB36FvBydNM

The goal is to get the current exchange rates of exchangeangeratesapi.io, cache them with sessionStorage and transfer the results to DataLayer. If the exchange rates are in the browser memory and the cache has not expired yet, delete them from the memory and transfer them to DataLayer. NOTE: Currency conversion will only work if the original variable is available at the time of conversion and if the exchange rates have been successfully restored. First the variable at the data flow level extracts the corresponding object from the GTM data model. You can use the ExchangeRates event name in a user event if you do not want to activate the tag until the exchange rates have been successfully recovered. This variable passes the original value and the payment object. There is no point in receiving the last payments all the time, so cache what you can live with. With DataLayer they can be used in custom JavaScript variables and custom variable templates to perform client transformations. Change the expiry time to specify how long the exchange rates should be cached in your browser. You also need to specify the base currency for calculating exchange rates. In the example I use “EUR” because I want the exchange rates to be calculated in euros.