Table of contents

Google Tag Manager Data Layer - Everything you need to know as a beginner

Google-Tag-Manager-Data-Layer-Everything-you-need-to-know-as-a-beginner

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 them for free in the corresponding store!

Key Points 🔑

  1. The Google Tag Manager Data Layer is essential for advanced event tracking; without it, much tracking would not be possible.
  2. Starting with the Data Layer can be challenging, but by starting small and practicing, your skills improve.
  3. TAGGRS offers specific plugins and addons for various CMS platforms to facilitate the implementation of a Data Layer.
  4. For effective setup, it is essential to thoroughly test your Data Layer, variables and triggers in Preview Mode.

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 managing tags without direct code modifications on your website.
  • Variables: Store 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 triggered.
  • 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 Web site 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 especially the case for standard B2B events, which can be managed 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. Here, select the variables relevant to your tracking needs.

Configure Built-In Variables GTM

Watch the video below to see what these built-in variables look like 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. This can result in incomplete or inaccurate data collection, leading to unreliable analytics and insights.

A Data Layer structures all 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 this is often done via JavaScript, the Data Layer is more of a conceptual structure for storing data than an actual code snippet.

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.

ga4-data-layer-gtm-preview-mode

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 the need for manual modifications to the Web site code.

Tag-Manager-Data-Layer-demoshop

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 Web site. The process begins when a user makes a purchase on the Web site. This action and its associated data are stored 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 triggered. In this scenario, a trigger is set to respond to the purchase action, identified by the relevant variables from the Data Layer.

Based on this trigger, a specific tag can then be created and configured, 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.

how-does-a-data-layer-works

TAGGRS Data Layer Plugins / Addons

You can develop a data layer manually, but this can be time-consuming. 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.

taggrs-lightspeed-data-layer-app

What kind of Data Layer do I have?

Google has given freedom to users to determine the structure of their Data Layer, which has resulted in 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 the standardized approach of GTM, you may encounter 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 rest assured that your Data Layer is set up correctly according to this protocol.

taggrs-ecommerc-advanced-shopify-template

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.

ga4-protocol-data-layer-example

How should I read a data layer?

Reading a Data Layer involves understanding how to extract specific data points and convert them into useful 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 dots, 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.

Screenshot 2024 03 29 at 14.01.54
Source: Analytics Mania

From Data Layer to Variable

When data is pushed to the Data Layer, Google Tag Manager does not automatically recognize it (outside of, for example, the build in variables). 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, so you cannot use 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.

DLV-ecommerce.currency

It is important to remember that data can be stored in different structures within the Data Layer. Therefore, you must consider some additional rules when accessing this data.

How to ensure tag is fired based on a trigger

Once we have set up the variables, we need to start creating the corresponding triggers in the process. To turn an "event" into an actual trigger that activates a tag, use a Custom Event Trigger in Google Tag Manager:

  1. Go to "Triggers" and click on "New trigger.
  2. Choose the custom event type.
  3. Enter the exact value of the "event" key you set in your Data Layer push, note that this is case sensitive.
create-custom-trigger-gtm

Testing Testing Testing Testing

Make sure your set up is tested. To effectively test your set up for your data layer:

  1. 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.
  2. Variables and Triggers: Make sure your variables are extracted correctly from the Data Layer and that the triggers are set correctly.
  3. Use Preview Mode: Test your tags and triggers in GTM's Preview Mode to see if they fire as expected.
  4. Server Side Tracking Mode: For server side tracking, use Server Preview Mode to check if the server-side tags are working correctly.

Make sure each step is done correctly for a reliable tracking setup. Also, check out 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 appears in Preview and Debug mode, but the tag is not triggered.

What data should I add to the Data Layer?

The data you add depends on what you want to measure. For sales metrics, 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 can 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

Recently published

magnifiercrossmenu linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram