Not sure which type of e-commerce events are shared with your Google Tag Manager container? Please read this article first.

Note: If you have gtag.js installed on your website and would like to capture the gtag.js e-commerce events and send them to Datatrics via Google Tag Manager, it’s still necessary to have installed Google Tag Manager on your website as well.

Log in to Google Tag Manager and ensure you are in an empty workspace. If workspace changes are not yet submitted, like in the screenshot below, contact the user who made the changes if the changes can be reversed or published. This will prevent you from publishing unwanted changes to your Google Tag Manager container. You can also create a new workspace where you only work on these changes and publish them.

Before implementing the e-commerce scripts, make sure you have the basic script added to your Google Tag Manager container. The e-commerce scripts won’t work without the basic tracking script present on every (virtual) page view.

We’ve created this file to import into your container, containing variables, triggers, and tags that capture gtag.js ecommerce (GA4) data and send it over to our tracking script in the correct format.

To import this file into your container, navigate to the admin environment of Google Tag Manager and click Import Container. When importing the file, please select the correct workspace (probably Default Workspace), MERGE the workspace and RENAME conflicting tags. This prevents you from losing present tags. Example:

After confirming the import, all tags, triggers, and variables are now present in your container.

This setup assumes you have set up your gtag.js ecommerce (GA4) events correctly, but there are a few fail-safes built-in. For example, all fields that are often in the wrong format for most websites are parsed to the correct format using JavaScript. Below are two examples:


With the parseFloat method, the value “datatrics_product.price” parses the value as a string and returns it as a number. The toString() method returns the value given to it in a string format. Both are added to the scripts to ensure our tracker receives the data in the correct format. If you know exactly what you’re doing and are sure the values in the dataLayer are in the correct format, you can remove these methods or change them accordingly.

Checking if the implementation is correct

All other variables, triggers, and tags should work out-of-the-box if you implemented gtag.js ecommerce (GA4) events correctly. To check if that’s the case and everything is working, you can preview the changes from your container in the Tag Assistant and see if the newly added tags fire correctly on the corresponding pages and events.

For example, when you add something to the shopping cart, the add_to_cart event should appear, and when you click it (1), the newly added Datatrics shopping cart tag should fire (2):

Please also perform other e-commerce events on your website and check if the corresponding tags fire.

Publishing your workspace to the live environment

After checking, don’t forget to publish the changes by clicking on the blue Submit button in the top right corner. After clicking GTM prompts a confirmation window where you can enter a title and subscription for the changes:

Publish it and sing like no one is listening. You now added the Datatrics tracking script to your website!

Note that there are also tags added for item/product detail and category pages, but these are just for feeding the algorithm with valuable information, not for page recognition. For recognizing item detail and category pages, it’s essential to include the URLs in content items and categories imported to Datatrics via an integration or our custom importer.

Verifying if carts and conversions are correctly identified by Datatrics

To check if carts and conversions are identified correctly by our tracking script, check out the following articles:

Did this answer your question?