The data layer
Google Tag Manager functions best when deployed alongside a data layer. A data layer is a JavaScript object that is used to pass information from your website to your Tag Manager container. You can then use that information to populate variables and activate triggers in your tag configurations.
Developers should read the developer documentation for more information.
Rather than referencing variables, transaction information, page categories, and other important signals scattered throughout your page, Tag Manager is designed to easily reference information that you include in your data layer source code. Implementation of a data layer with variables and associated values, ensures that they will be available as soon as you need them to fire tags.
When you set up your website or mobile app to work with Tag Manager and a data layer, think about what categories of information the data layer should handle, such as:
- Product data: Product name, price, category
- Marketing campaign information: Traffic source, medium
- Transaction data: Cart value, checkout date
- Customer information: New or returning customer
Create a data layer variable
Data layer variables enable Tag Manager to read values from your data layer implementation and pass those values to tags, triggers, and other variables. A data layer object is made up of a list of key/value pairs. A key is a category of things – a book's category, title, or author. Each key could have different values. A book's title key could have a value of 'Ulysses', 'War and Peace', 'A Brief History of Time', etc.
Add data layer code to your web page
To set up your data layer, work with a developer to add the following snippet of code to the <head> section of your web page above your container snippet: