Understanding how the Google Tag Manager Data Layer works is not an easy subject. But this core component of Google Tag Manager plays an important role; without the Data Layer, certain event tracking simply would not function. It allows us not only to capture interactions and use them as triggers, but also to collect additional data about these interactions or their context, which can then be exploited through Data Layer Variables.
It is quite normal to find this concept challenging at first. You are certainly not the only one struggling to master it. The advice is to start small, with a few events, and expand from there. As you practice more, you will find that your skills improve.
To make it easier, we have built several Data Layer plugins / addons for your CMS. You can download it for free in the corresponding store!
Key Points 🔑
- The Google Tag Manager Data Layer is essential for advanced event tracking; without it, much tracking would not be possible.
- Starting with Data Layer can be challenging, but by starting small and practicing, your skills improve.
- TAGGRS offers specific plugins and addons for various CMS platforms to facilitate the implementation of a Data Layer.
- For effective setup, it is essential to thoroughly test your Data Layer, Variables and Triggers in Preview Mode.
Table of Contents
Before you begin
Before we delve deeper into the Google Tag Manager Data Layer, it is important to know some key concepts:
- Google Tag Manager: Tool for Administering tags without direct code changes on your website.
- Variables: Save data used by tags and triggers within GTM.
- Tags: pieces of code that perform specific actions, such as collecting data or tracking conversions.
- Triggers: determine when and under what conditions a tag should be activated.
- Preview Mode: A GTM feature that allows you to test tags and triggers before they go live.
dataLayer.push(
): JavaScript function used to send data to Google Tag Manager’s Data Layer for tracking purposes.
Do I need a data layer?
Have you ever wondered if your website needs a Data Layer? If you want to measure basic interactions such as form submissions, which GTM can often detect directly (is retrieved with the Google Tag), a Data Layer may be unnecessary. This is particularly the case for standard B2B events, which can be Administered via GTM’s built-in Variables.
To determine which built-in events the Google Tag can already pick up automatically, go to GTM and under Variables look at Built-in Variables which you can enable by clicking Configure. Select the variables relevant to your tracking needs here.
Watch the video below to see how these built-in variables look in Google Tag Manager’s preview mode.
However, if you want to track more advanced events, such as e-commerce-related activities that are not recognized by GTM by default, adding a specific Data Layer on your website is necessary.
What is a Data Layer?
One of the most common mistakes made when configuring Server Side Tracking is not having a (proper) data layer. As a result, data may be collected incompletely or inaccurately, leading to unreliable analyses and insights.
A Data Layer structures all the data coming from your website, which can then be used in Google Tag Manager for variables, tags and triggers. In practice, this means that for every action on your website, such as a purchase, the Data Layer records this including specific information such as product name, price and quantity. Although often done via JavaScript, the Data Layer is more of a conceptual structure for saving data than an actual code fragment.
In summary, a Data Layer facilitates keeping your website data organized and accessible for analysis and marketing, eliminating the need to manually collect or enter data all the time.
How Google Tag Manager Uses the Data Layer
Google Tag Manager (GTM) uses the Data Layer to monitor actions on a Web site. For example, when a user adds a product to the shopping cart, the Data Layer captures this event. GTM then detects this activity through the Data Layer, leading to the activation of a specific trigger. This trigger is associated with a tag that is configured to fire when a product is added, collecting the appropriate data without requiring manual adjustments to the website code.
What does this data flow look like in practice?
To understand how the data flow works, let’s take the example of measuring a GA4 purchase on a website. The process begins when a user makes a purchase on the Web site. This action and its associated data are saved in a structured manner in the Data Layer. Within this Data Layer are Variables that capture specific details of the purchase, such as product information, price and quantity.
These variables are then used to set triggers. A trigger is a condition that determines when a tag should be activated. In this scenario, a trigger is set to respond to the purchase action, identified by the relevant variables from the Data Layer.
A specific tag can then be created and configured based on this trigger, such as a GA4 purchase tag. This tag is activated when the conditions of the trigger are met, or in other words, when a purchase occurs. This allows the purchase action to be accurately measured and recorded within GA4.
TAGGRS Data Layer Plugins / Addons
You can develop a datalayer manually, but this can take a lot of time. Furthermore, manually configuring a Data Layer and setting up variables, triggers and tags can be complex. For this reason, we at TAGGRS offer apps or plugins for various platforms that allow you to set up a fully functional Data Layer for your website with just a few clicks. These tools greatly simplify the process, allowing you to quickly and efficiently implement the tracking needed for your website.
What kind of Data Layer do I have?
Google has given freedom to users to determine the structure of their Data Layer, which has led to a diversity of Data Layers. This freedom offers a lot of flexibility, but it also brings a challenge: Because of the variety of configurations, the variables you need to extract from the Data Layer can vary depending on the setup.
This means that, despite GTM’s standardized approach, you may have to deal with different types of Data Layers, where not all variables are universal. At TAGGRS, we recognize this variation and have therefore developed specific templates in our Template Gallery to match the different types of Data Layers.
At TAGGRS, we also develop our own plugins and add-ons for each CMS platform, all of which are based on the GA4 protocol. In our configuration blogs, we often assume this standard. So by installing a TAGGRS plugin or add-on, you can assume that your Data Layer is correctly set up according to this protocol.
As for the content of your Data Layer, if you don’t find e-commerce-related data, it may mean that your Data Layer is not configured for this type of data collection. To determine what type of Data Layer you have, you can use GTM’s preview mode. Standard built-in data is shown here, and if you see .ecommerce
, for example, this indicates a Data Layer set up according to the GA4 protocol.
How should I read a data layer?
Reading a Data Layer involves understanding how to extract specific data points and turn them into actionable information in Google Tag Manager. Suppose you want to extract user information, such as a user ID stored as a direct value in the Data Layer. You can then create a Data Layer Variable in GTM by simply entering the name of the key, such as “userID. These direct values are easy to access because they are at the first level of the Data Layer.
However, if the data is nested within other keys, meaning they are part of a deeper structure, then a different approach is required. You must use the full path name, separated by periods, to locate the data. As an example, if the ‘userID’ is within an object ‘userAttributes’, use ‘userAttributes.userID’ to configure this variable in GTM.
Tip: Download our preset Expert GTM templates, where all variables per data layer are already set up properly for you.
From Data Layer to Variable
When data is pushed to the Data Layer, Google Tag Manager does not automatically recognize it (outside of the build in variables, for example). This means that this data is not directly usable within GTM. Your Data Layer can contain a wide range of information, from user data to page information, but without additional configuration, this data is not visible in the Variables section of the Preview and Debug tab, preventing you from using it directly in your tag management.
To access this valuable data, it is necessary to create a Data Layer Variable for these data points within GTM. You do this by creating a new Data Layer Variable and entering the exact name of the key you want to retrieve from the Data Layer.
It is important to remember that data can be saved in different structures within the Data Layer. Therefore, you should keep in mind some additional rules when accessing this data.
How to make sure tags are fired based on a trigger
Once we have set the variables, we need to create the corresponding triggers. To turn an “event” into an actual trigger that activates a tag, use a Custom Event Trigger in Google Tag Manager:
- Go to “Triggers” and click “New trigger.
- Choose the custom event type.
- Enter the exact value of the “event” key you set in your Data Layer push, note that this is case sensitive.
Testing Testing Testing Testing
Make sure your set up is tested. To effectively test your set up for your data layer:
- Check your Data Layer: Use tools such as the Google Tag Assistant or preview mode to verify that your Data Layer is present and contains the correct data.
- Variables and Triggers: Make sure your variables are extracted correctly from the Data Layer and that the triggers are set correctly.
- Use Preview Mode: Test your tags and triggers in GTM’s Preview Mode to see if they fire as expected.
- Server Preview Mode: For server side tracking, use Server Preview Mode to check if the server-side tags are working correctly.
Make sure each step is performed correctly for a reliable tracking setup. Also see our comprehensive guide to testing your Server Side tracking configuration.
Outro
This was it, the explanation of the Data Layer in Google Tag Manager. We talked about the basics of the Data Layer, its importance for effective event tracking, and how you can get started setting up variables, tags, and triggers yourself to take your data analysis to the next level. With the right tools and a little practice, you can fully harness the power of GTM and gain in-depth insights from your website data.
FAQ Google Tag Manager Data Layers
How do I fire a tag with a datalayer.push()?
For a tag to fire at the time of a dataLayer.push(), this action must contain a key named “event.” If this key is missing, only a message will appear in Preview and Debug mode, but the tag will not be activated.
What data should I add to the Data Layer?
The data you add depends on what you want to measure. For sales measurements, order ID, total amount, shipping costs, taxes and coupons are valuable. For tracking login activity, user ID and login method are useful.
Do I need a separate Data Layer for server side tracking?
No, for server side tracking you use the same Data Layer as for client-side tracking.
Are there standard names for events and parameters in the Data Layer?
No, you can name events however you want, such as “login,” “log in,” “log_in,” etc. Parameters can also be named freely, unless you are implementing specific data structures such as Enhanced Ecommerce via GTM, which have strict naming rules. For other situations, parameter names may vary at your discretion.
I need custom data, but find it difficult to go deep technically. What can I do?
You can send documentation and manuals to your developer and then check their implementation through GTM’s Preview and Debug mode to make sure everything is set up correctly. We at TAGGRS also offer implementation. For this you can fill out this contact form
About the author
Ate Keurentjes
Server Side Tracking Specialist at TAGGRS
Ate Keurentjes is a Server Side Tracking specialist at TAGGRS. He has experience with various Google Tag Manager concepts. Keurentjes has been editing and writing about the latest developments and trends in data collection / Server side tracking since 2023.