0

I have a question about Google Tag Manager (GTM) and Data Layer:

Let's assume that the analytics team asks developers to push an event in Data Layer called "test" which has the following structure:

{ product_id : '1234', category: 'toys' } 

Let's assume I have a tag that needs to send those variables to a third party provider.

According to my understanding of the GTM workflow I have to create two separate data Layer variables, one for product_id and one for category.

This is quite a manual/long/error prone process for events with a lot of variables, and I also worry that there could be confusion if another variable is called ‘category’ from another event.

So my question is:

Can I define in GTM the 'parent' level variable called 'test' (the name of the event itself), and then create test.product_id and test.category variables?

Thanks

1 Answer 1

1

Proper data governance should dictate that your data layer keys are well defined so that you don't have redundancy and ambiguity. Also, use of the event key is vital if you absolutely need to reuse a particular name, like category, with a different event. In that example, your data layer variable can be used for whatever event, and the event itself will ensure that that key is getting the correct value into the correct event tag.

If you do need to use a nested data structure, make sure your data layer variable uses the proper dot notation as you've indicated (ie. test.0.category). Note that in much the same way, the enhanced ecommerce data layer parameters can accessed.

Sign up to request clarification or add additional context in comments.

5 Comments

thanks for your answer. When you say use of the event key is vital you mean when creating variables in GTM?
When you push data to the dataLayer, it's a good practice to always push an event as well, eg. dataLayer.push({'event': 'test', 'category': 'chicken'}). That way you can be sure that when you want to fire your tag and use the correct category value, you can do so with the test event as your trigger.
Great, this is what I am doing, thanks. In regards to using nested data structure, would it be something like dataLayer.push({'event': 'animal', 'animal':[{'name': 'chicken'}, {'habitat':'farm'}]) and then the variables will be defined as animal.name and animal.farm?
It would be more like dataLayer.push({'event': 'animal', 'animal':[{'name': 'chicken', 'habitat':'farm'}]), and then to access them as data layer variables in GTM, you would go animal.0.name and animal.0.habitat.
thanks, I think this is the best approach. This way I could define only a single variable animal in GTM and then access the single elements from the tag.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.