GTM

Google Tag Manager Data Layer: How GTM Data Layer Helps You Improve Your Analytics Strategy

Introduction

Capturing web analytics data about how users interact with your website may be one of the most crucial tasks that your business can perform. By tracking visitors’ behavior, web analytics can reveal highly valuable information such as:

  • How users arrive at your site
  • What user demographics are
  • What kind of content attracts the most users
  • When are the most popular times for users to access your site

It’s no surprise, then, to read the results of a 2017 survey by IT research firm Forrester: 73 percent of companies use web analytics as the key component of their digital intelligence initiatives.

Considering the outsize importance of web analytics for your business, you might well ask: what is the best tool for web analytics? Many of the top marketing websites have found that one of the best web analytics tools for their purposes is Google Tag Manager.

Google Tag Manager is a “tag management system”: a free tool for managing the JavaScript and HTML tags that websites use for tracking, analytics, and advertising. GTM, as it’s often called, makes it easier to insert and manage the marketing tags such as lines of code or tracking pixels that are used to discreetly observe user behavior. According to the technology profiler tool BuiltWith, Google Tag Manager is used by at least 3.8 million websites worldwide.

According to the GTM user guide, Google Tag Manager “functions best when deployed alongside a data layer.” But what is a data layer in Google Tag Manager, and what are the benefits of data layers in GTM? This article has all the answers.

What is a Data Layer in GTM?

A “data layer” is a term for a JavaScript object that is used to pass information from your website to Google Tag Manager.

More specifically, a data layer (also known as a dataLayer object) is a JavaScript array that stores variables consisting of key-value pairs. These pairs may contain information such as:

  • The web page’s title, URL, and category
  • The user’s ID and transaction history
  • The transaction’s ID, price, and quantity

The following code snippet represents an empty data layer in JavaScript:

<script>   dataLayer = []; </script>

The creation of this empty data layer is enclosed within two <script> HTML tags, so that the JavaScript code can be embedded into the text of your web page.

Data Layers in Google Tag Manager

Now that we’ve given a brief definition of data layers, how are data layers used in Google Tag Manager?

Data layers are essential to how Google Tag Manager works. If you don’t plan to work with custom data, GTM will create a data layer automatically under the hood, even if you don’t explicitly instantiate one yourself. Google Tag Manager then uses the information within the data layer both internally and externally with other analytics tools such as Google Ads and Google Analytics.

The following code snippet represents a data layer with two key-value pairs:

<script>   dataLayer = [{     'pageCategory': 'signup',     'visitorType': 'high-value'   }]; </script>

Based on the information contained within this data layer, we can see that the current web page functions as a signup page, and that the visitor has been marked as “high-value.”

Declaring the data layer explicitly, as seen above, should be done when you want to add information as the page loads. The data layer should be declared as high as possible within the code of your website in order to avoid bugs and errors. However, in most cases it is preferable to update the data layer using the push() method, as we discuss later.

In Google Tag Manager, the variables within the data layer object are persistent only as long as the user remains on the current web page. Variables relevant across multiple pages, such as user data, must be declared for the data layer in each page of your website and use a consistent naming scheme.

Data layers in Google Tag Manager can also use special variables called “events” that are triggered when a user performs a particular action, such as clicking a link or a button.

The following code snippet demonstrates how the “button1-click” event is triggered within GTM when the user clicks on a button:

<a href="#" name="button1" onclick="dataLayer.push({'event': 'button1-click'});" >Button 1</a>

The push() method allows you to dynamically update the data layer with new information based on user behavior.

Improve Your Analytics Strategy with Data Layers

We’ve discussed some of the technical details of data layers in Google Tag Manager—but how can you improve your web analytics strategy using data layers?

Data layers make it easier to track custom pieces of information regarding user behavior on your website. The data that you collect using a data layer can be analyzed in order to segment your customer base or run personalization campaigns.

On an abstract level, the data layer represents a structured package of information that is potentially valuable to help you fulfill your business requirements and objectives. These non-technical goals must be translated into JavaScript code in the form of the data points within the data layer.

The variables within a data layer should be as generic, consistent, and future-proof as possible. After all, you might use your data layer not only with Google Tag Manager, but also with other analytics tools. The data layer should be treated as a living, breathing entity that may evolve in response to changing business requirements.

When creating a data layer for any non-trivial use case, you should first draft a governance document that outlines how it will be used within your business. Who has ownership of the data layer in terms of business and technical requirements? What are the variables in the data layer, and what is the process for changing or updating them? Questions such as these should be answered in your governance document.

Conclusion

Data layers store valuable information such as user IDs and actions that can help you improve your digital marketing strategy. Knowing how to use data layers in Google Tag Manager appropriately is an essential skill for digital marketing initiatives.

This article has just scratched the surface of what you should know about data layers in Google Tag Manager. Need more advice about web marketing and analytics? We can help. Get in touch with a member of the ironFocus team to learn how you can get the most out of your marketing and sales funnel.

Category
Tags

No responses yet

    Leave a Reply

    Your email address will not be published. Required fields are marked *