Skip to main content
All CollectionsTracking scriptsCustom scripts
Datatrics script changes for country codes
Datatrics script changes for country codes

This article explains how you can alter the e-commerce & tracking script to match on item-id's that have a country code within the content

Odin Bergman avatar
Written by Odin Bergman
Updated over a week ago

Some projects within Datatrics use source systems (e.g, LightSpeed), where it can happen that the item id's within the content have a country code suffix in them.

If you have implemented the e-commerce script with Google Tag Manager, there is a chance that we capture the item id's without a country suffix, depending on the implementation.

This causes a mismatch between the item that we can find in the content, with the actual item we capture with our tracking script. When that happens, you will be unable to use any functionality that requires items found in a conversion or abandoned cart.

If it is unclear how to test this, you can use the Datatrics debugger on your website. You can find the documentation through this link.

You can solve this item id issue by logging in to your Google Tag Manager container, and then go to the variables tab.

In the User-Defined Variables section, create a new custom javascript variable, and place the following javascript within the code:

function() {

var pageUrl = window.location.href;

return pageUrl.split("/")[3];


Call the variable "Datatrics - Language", and save it.

This javascript variable will check the URL, and it will pick the part after the 3rd slash, which is often the country code. If your country code is after the 5th slash, change this code accordingly.

Next up, go to the tags section, and place this variable within both the e-commerce and tracking script on every line where the the "" is present.

You can achieve that by placing the following code on every line:"-"+{{Datatrics - Language}},

When you have saved both scripts, test the changes by previewing the Google Tag Manager container.

If you then place an item within the shopping cart, you will notice that the -nl is placed after the item id.

You have now successfully matched the item id on the website to the item id of the content item within Datatrics.

Datatrics can now actively see which item a visitor has added to the cart, or what a visitor has bought, and this can be used in hybrid flows, journeys or campaigns.

Did this answer your question?