Google Tag Manager Data Layer, Week 4

Photo by Christina @ wocintechchat.com on Unsplash

Disclaimer: I’m a learner at CXL Institute. In this post I will talk about the Digital Analytics Minidegree. It’s an in-depth program that can lead you from beginner to Digital analyst in 3 or more months. All courses are taught by world class instructors recognized for what they are doing in those specific fields.

If you use Google Tag Manager (GTM), you can collect data more easily than you would do by only using your analytical platforms tags. In fact, GTM can collect and distribute all the data he collects to any connected platform. Your website/mobile app will remain as faster as you want according to Core Web Vitals requirements. But do you know that you can make your GTM more powerful with one tool. This tool must be discovered if you want to use it because it’s not for analytics tourist, this tool is the GTM DataLayer. In this post, I will tell you what is it, why use it and how to configure and use the DataLayer. Pieces of code will show examples along the post so you can start using it today.

I decided to make this post about only the DL because I think that it’s a concept any digital analyst or digital marketer must master to benefit all the power of GTM.

WHAT IS THE DATALAYER

The data layer is often presented as a kind of big basket in Google Tag Manager, in which all sorts of information (page heading, user login, opening of a pop in…) are injected by your developers, store temporarily in order to be used by the web analytics tools.

We can define the DL as a big bucket where you can place temporary information of any action of users on your website or application. That information can then be sent to your analytical platform or any third services that need them. Technically A data layer is a JavaScript object that is used to pass information from your website to your Tag Manager container. You can then use that information to populate variables and activate triggers in your tag configurations.

Generally speaking, the DataLayer implementation is the responsibility of your developer because source code manipulation is involved. He can be ignorant of what is it but if you explain the usefulness and everything you expect to collect, he will understand and do its job.

One of the advantages of the data layer is that there are no constraints on the volume of data collected. It participates in what is called Data Driven Marketing, a form of marketing based on the knowledge and exploitation of user data.

STORING INFORMATION

The DL is automatically created once GTM tag fire. This DL is empty and ready to store data/information you put inside. You are not obliged to do so if all you need is already collected by GTM tag. But if you need to put additional / custom information (user ID, product ID, cart value, checkout date…) in the DL, you have two methods: adding a dataLayer[] snippet above the GTM tag or use dataLayer.push() command.

In the first method you will add dataLayer = [] code snippet above the GTM container code. This is used when you want ‘print/static’ data (page title, location, browser type…) when a page load on a website or application.

<script>dataLayer = [{'pageCategory': 'signup'}];</script><!-- Google Tag Manager -->...<!-- End Google Tag Manager -->

The second method is generally recommended and is about any type of events on a page load on a website or application. To use dataLayer.push() command method you will add a code snippet anywhere in your source code. To do so in GTM, you will create a Custom HTML Tag

<script>window.dataLayer = window.dataLayer || [];window.dataLayer.push({‘key0’: ‘value’,‘key1’: ‘value’,‘key2’: ‘value’,});</script>

DataLayer data can be used by GTM as variable value or as trigger to fire a tag. You see the power of the DL when you notice that it can serve independently the three main parts of GTM: Tag, Trigger and Variable.

Now that you added the dataLayer code snippet, key/value pairs are visible inside GTM but not in GA. To make them available there, you will link GA and GTM.

READING INFORMATION

1- DataLayer variable

Variable > User defined variable > New > Data Layer variable > Save

In the field ‘Data Layer Variable Name’ you put the key as it’s spell in the DL code snippet.

If you open Preview and Debug tool, you must now see the key/value information there. If it’s there, your DL contains your custom information and you can go to next step. If not, go back and check words spelling or ask your developer to check the source code.

Remember that Data Layer Variable Name is case sensitive. Leave version number unchanged.

You can then pass this variable information (key/value) to Google Analytics as a custom dimension or you could also use this variable in your trigger conditions.

2- GA custom dimension

Google Analytics by default cannot collect and store your custom variable. You have to create a custom dimension and push GTM variable inside GA.

GA Account > Property > Custom Definitions > Custom Dimensions > Create a custom dimension

In this short post, I touched on several notions about the Data Layer that will have to be deepened to reach a true mastery. It is a central element of data collection and many professionals do not use it because it remains very abstract until simple and concrete examples are found. The use of the Javascript language also puts off many marketers who do not understand programming.

To go further, there are several websites that will give you information, detailed tutorials, youtube videos to learn and use the data layer today in your career as a marketer or analyst.

If you are interested in CXL courses, you can find lessons about the DataLayer in GTM beginner course. You will find 3 videos in this 21 videos course where you will learn what is the DataLayer, storing and reading information in and from the DataLayer.