Format the DataLayer – Change other DataLayers to fit GTM Enhanced Ecommerce

Transforming other DataLayers

Before i start. If you are new to DataLayers and want a deeper understanding of how they work, id recommend reading A Complete Introduction to the Data Layer for Digital Marketers (with Examples)”, by datalayer doctor, before reading this.

I often see other DataLayer objects that does not follow the syntax of the Google Tag Manager datalayer, and the recommended setup for for Enhanced Ecommerce.

This could be:

The reason for this is that the other platforms rely on a different structure, or simply that it is easier for developers to maintain. That said, it does make setting up tracking a bit more difficult if you are not a developer and used to having everything served on a silverplatter.

How to do deal with other datalayers

To see how a datalayer is structured I personally like to use DataSlayer, and add the line as shown below:

what this gives us is a readable format to which we can see the valuables in a datalayer. In this case, it is the one from Shopify:

The actual transformation of datalayer variables to Google Tag Manager standard

In this example, the company More Cosmetics, have a product array which is structured like this:

what we want is to display this information as product impressions, in the Google analytics. To do this it must be formatted correctly. The next steps will show you how to:

  1. Read the product DataLayer
  2. Add it as a function
  3. Display it in an product impression custom html script

1. Read the product DataLayer

at first you want to go to variables, add new and choose DataLayer variable:

Here you need to make sure that you set it up to link to your products:


If it is not a GTM DataLayer variable, then select JavaScript variable instead.

2. Modify the product array as a function

Now we have the product array, we can begin transforming it:

What happened is that we took the variables from the array:

  • id
  • name
  • price
  • category1 + / + caregory2 + caregory3 + category 4 + category 5
  • brand
  • variant id
  • lists

And said that for the total count of products in the DataLayer, create a new array, where we only use the specific variables selected and give them a new naming. Save the function as productArray, and it can be used for any Enhanced ecommerce setting where you need to list your products.

3. Add the function as a GTM Enhanced Ecommerce product impression

Now all we need to do is to set a custom html tag an make it fire on places where there is a product impression:

The products array will take all the products mapped from the previous function we created in step2.

Now all that is left is to configure a tag to fire when the event is equal to productImpressions

Tag configuration – Don’t forget to turn on enhanced ecommerce

Trigger – I usually have all my events in one tag if possible

And that’s it!

You should now be able to see product impressions in Google Analytics once you have published the tag. Remember to set limitations to this if you show a lot of products on one page.

Let me know if there is something that should be explained or added to this blogpost. Remember this approach can be used for working with all sorts of data, and not only product impressions.