Leap use technology to transform businesses with E-commerce, Data Integrations and App Development. Leap is proud to partner with clients across the United Kingdom.

EURO order conversion tracking values incorrect on Shopify

If you’re using multi-currency on a single Shopify site with conversion tracking such as Google Ads or Bing Ads you may be experiencing pain around the format of the values you wish to send. This is due to the way Shopify implies display formatting on any currency values.

If you’ve got a UK/GB setup you will be familiar with this script:

<script>
gtag('event', 'conversion', {
'send_to': 'XX-XXXXXXXXX/XXXXXXXXX_XX',
'value': {{ checkout.total_price | money_without_currency | remove:',' }},
'currency': '{{ order.currency }}',
'transaction_id': '{{ order.order_number }}'
});
</script>

This will work perfectly for GBP values. For the example total_price of £1,999.99 our conversion tracking value will be 1999.99.

Perfect! It just removes the comma thousand separator which is all that is required here.

Now, enter the EUR currency, where we can expect values in this format: €1.999,99.

Using the above tracking code, the following would be our conversion tracking value: 1.99999

This is obviously incorrect! Notice how in our original amount value the thousand and decimal separator are switched. To handle this, we can do the following in our tracking code:

{%- if order.currency == "EUR" -%}
	{{ checkout.total_price | money_without_currency | remove: '.' | replace: ',', '.' }}
{%- else -%}
	{{ checkout.total_price | money_without_currency | remove:',' }}
{%- endif -%}

Now, our conversion value will be 1999.99 since we are removing the thousand separator dot and then replacing the comma in the decimal separator with a dot. Great!

But wait, according to the Shopify docs , EUR values can also be in this format: €1,999.99. Notice now, how this is similar to our original formatting for GBP!

However, if we were to leave our tracking code as above, it would give us our conversion value as 199999 which is incorrect. Now we not only need to check the currency is EUR but also the format of the currency, i.e. whether it’s 5,99 or 5.99.

Surely there must be an easier way?

Thankfully, there is a much easier way but I didn’t find it easily when googling. Revising our original script where we set the value as below:

{{ checkout.total_price | money_without_currency | remove:',' }}

Instead of applying the money_whout_currency operator, we can instead ignore that (which doesn’t apply the currency formatting) and then divide the number by 100.0 to get a float value which should be correct regardless of the currency or formatting.

Note: you must divide by a float (100.0 and not 100) in order to get your result in a float.

{{checkout.total_price | divided_by: 100.0}}

Putting it all together, your script should look like below:

<script>
gtag('event', 'conversion', {
'send_to': 'XX-XXXXXXXXX/XXXXXXXXX_XX',
'value': {{checkout.total_price | divided_by: 100.0}},
'currency': '{{ order.currency }}',
'transaction_id': '{{ order.order_number }}'
});
</script>

If you would like to learn more about how Leap could help your business with Shopify, then please get in touch for a no obligation chat