What Is A Data Layer In Google Tag Manager?

Fast Web Media

Google Tag Manager (GTM) is a piece of software that helps site owners organise their tracking more efficiently. It's designed to work better when deployed alongside customised data layers as they allow additional information to be passed on to GTM.

For more background on Google Tag Manager, check out our beginner’s guide to getting started with GTM.

What Is A Data Layer?

Data layers are JavaScript objects that can store and transmit data from a website to GTM before it is later sent to third-party platforms such as Google Analytics. Many metrics are automatically compiled by Google Analytics once you've linked it to your website, and these include simple measurements such as time on page and user location. For more in-depth analysis of data such as cart value and newsletter sign-ups, you’ll need to deploy more complex data layers yourself.

The easiest way to think about data layers is in comparison with the application layer and the experience layer. The experience layer is what a user sees when they visit your website (e.g. text and images), and the application layer is the code that runs your website and its functionalities such as videos and responsive display.

In essence, a data layer is a Javascript variable or object that collates information from the website and sends it to GTM. This is the reason data layers are coded in JavaScript, as this is a scripting language which allows for information to be sent and received. The following diagram shows how the relationship between data layers and GTM works:

Fast Web Media

A data layer is created as soon as the JavaScript snippet for GTM is placed into your website and can be edited using GTM.

The information contained in a data layer is varied depending on its purpose and can have simplistic values or multitudes of data points. The information is often related to characteristics of a page, for example, whether it's a blog post or a product page.

How Can Data Layers Be Used?

Marketers can use the information stored in a data layer to set up actions based on certain conditions, which is particularly useful for ecommerce sites. In some instances, this can be as simple as triggering a pop-up asking a user to subscribe to an email or call upon more complex mechanics such as triggering abandoned cart emails.

GTM can use the data stored in a data layer to gather particular pieces of data from your website and to analyse additional conditions and actions (e.g. account creations). With information to hand, more complex firing conditions can be implemented depending on the user. For example, if a user has added items to their cart, you can create simple responses to fire from the data layer to prompt the user to complete their transaction.

How Do I Push Data To My Data Layers?

Pushing data to an active data layer can be done by following these two steps:

  • Add the data layer above the GTM snippet
  • Deploy a dataLayer.push API call

If you aren’t comfortable adding the data layer directly to the source code (as the first step of this process requires), you can forgo this step, but it may mean that your website takes slightly longer to start pushing the data to Google Analytics.

The data layer snippet added directly to your website’s source code as per step one should look something like this:

<script> dataLayer.push({ 'event': 'newsletterRegistration' }); </script>

Here’s another example of a data layer with additional user details specified:

<script> dataLayer.push({ 'event': 'formSubmission', 'formSubmission.action': 'submit', 'formSubmission.formname': 'contact' }); </script>

The second step enables you to track additional information regarding a user’s actions on your site such as information on a product added to a cart. It allows you to perform more accurate analysis of your data by considering information such as the value of products added to a cart or the category of products added to a cart.

Fast Web Media

What Are Triggers And Variables?

You can add up to 10 lines of code here to create more complex triggers based on factors such as user location. If you are working with a developer to add this code to your website, ensure that the data is pushed at the right point. For example, if you are capturing data on form submission, the trigger should come after the form is submitted.

Once this is complete, you should use GTM's Preview Mode to test if the data layer has been coded successfully. To enable the data layer, head to the GTM Triggers tab and select “New”. Next, select “Custom Event” as the trigger type and ensure that the trigger is set to fire for “All Custom Events”.

Creating the trigger isn’t quite the final step, as you’ll also need to create a variable to collect the data when the trigger is fired. The easiest way to think of variables is as another stepping stone to push the data to Google Analytics once a condition has been met to set off the trigger; the data won’t be sent automatically without the variable. To create a new variable, head to the GTM Variables tab, click “new” and then enter the data layer variable name (e.g. “form.submission.action”).

You’ll be given a choice of data layer Version 1 or 2 at this point. To merge and edit pre-existing objects, choose Version 2. This option gives you more flexibility and is more familiar if you’ve used JavaScript before. Version 1 doesn’t let you access nested keys and is much more limited in this sense. Unless you have a particular brief, go for Version 2 when creating your data layer variable.


Being able to implement data layers into GTM is crucial for your website, especially if many pages have been created with goals that fall outside the traditional parameters of Google Analytics. By getting to grips with data layers, you can accrue valuable information regarding user behaviour on your website and take a step closer to fully understanding how people interact with your site.


We hope you enjoyed that

Related Articles