zaro

How to Setup a Data Layer?

Published in Data Layer Setup 3 mins read

To setup a data layer, follow these steps using a tool like Google Tag Manager:

Steps for Setting Up a Data Layer Variable

Here’s a breakdown of how to create and configure a data layer variable, which is fundamental to capturing data on your website:

  1. Navigate to Variables: In your Google Tag Manager workspace, find and click on Variables. This is where you manage all the variables used in your tags.

  2. Create a New User-Defined Variable: Under the "User-Defined Variables" section, click on the New button. This initiates the process of creating a custom variable.

  3. Select Variable Type: Click on Variable Configuration. From the list of available variable types, choose Data Layer Variable. This selection specifies that you will be capturing information from the data layer.

  4. Enter the Data Layer Variable Name (Key): In the Data Layer Variable Name field, enter the exact key name of the data you intend to retrieve from your data layer. For example, if your data layer pushes ecommerce.purchase.total, you would enter ecommerce.purchase.total here. Case sensitivity is important.

  5. Set Data Layer Version: Specify the data layer version you are using. Most modern implementations use Version 2, though some legacy systems might still utilize Version 1. Selecting the correct version ensures data compatibility.

Understanding the Data Layer Concept

The data layer itself is an object that stores information related to user interactions, transactions, and other events on your website. It sits between your site and tagging tools. This means, before setting up the variables, your website or application has to be pushing data into this data layer. This requires code to be written on the website. Examples could be code which pushes the product name, price, user ID, and many other custom values.

Practical Insights

  • Planning is Key: Before you start, make a list of all data points you need from the site.
  • Consistency is Crucial: Make sure the names (keys) of data pushed to your data layer are accurate and consistent across your site.
  • Testing: Before launching, test your data layer pushes and variables in the Google Tag Manager preview mode to ensure everything is working as expected.

Example Scenario

Let’s say your website pushes an item name to the data layer using the key product_name. To access that information, you would:

  • Create a new user-defined variable.
  • Select 'Data Layer Variable' as the type.
  • Enter product_name in the Data Layer Variable Name field.

Now, you can use this variable in your tags (like a Google Analytics event tag) to record the product name.