How To Setup GA Event Value Currency Exchange In GTM
Here's a scenario we had on a non-ecommerce website. A user could notify a dealer by adding items to a wishlist [basket] and sending the list to the dealer. We already had a dataLayer push for the event value. As usual, posted this in GTM Forum and Simo Ahava helped [with this one too!]. This blog post is a breakdown of the discussion thread.
The challenge was to convert the values to a common currency as otherwise, a particular store with a weaker currency might show a much higher Google Analytics event value but this would not be valid.
Steps required to setup Google Analytics event value based on market in GTM
What we needed?
A method to identify the store and then convert the value to a master currency.
How did we go about it?
The landing page had a query string variable for 'country'. We used this to create a URL based variable where the query field was used to pick up the value for 'country'.
How to do the currency conversion?
function() { var market = {{Market}}; var value = {{value}}; switch (market) { case 'ca': return value * 1.41; case 'mx': return value / 0.27; } return value; }
What does this JavaScript do?
Since Simo provided this script, I pasted it [as in] in GTM to pick up the value of the market and convert it to a master currency. I read up about the switch function in JS and it appears to be like an IF/ELSE based execution, So, if there's a case where market = 'ca', it should convert the value obtained initially in the dataLayer, multiply the value by 1.41 and then override the value for the event with the newly multiplied value. IF not , it will check for the next case [IF market = 'mx']
https://www.w3schools.com/js/js_switch.asp
Limitations about the event value method?
In passing the event value, the decimal values are automatically stripped off and only the whole number gets passed to Google Analytics.
Can the Lookup table method work?
So, I tried creating a Lookup table where input = ca and output equals * 1.41 but as Simo pointed out that the Lookup table cannot execute arithmetic inside out, only have a static output value.
Hope this tip helped.
Link to Google Tag Manager Product Forum Thread: https://productforums.google.com/forum/#!topic/tag-manager/9jlsGFmgW9Y;context-place=mydiscussions