Knowledge Base
  • Chào mừng bạn tới trang hỗ trợ sản phẩm của chúng tôi !
  • Page Site Builder
    • Bắt đầu tạo một trang web
      • Thêm một section
        • Sao chép section
        • Cài đặt section
        • Di chuyển section
      • Thêm một page
      • Thêm kết nối SSL
  • HubSpot CRM
    • crm-setup
      • Get started with objects
    • contacts
      • Create contacts
      • A guide to your contacts home
      • Work with your contact records
      • HubSpot's default contact properties
      • Property field types in HubSpot
      • Set up your import files
      • Import data to checkbox properties
      • Manage your properties
      • Import contacts, companies, deals, tickets, products, or notes
      • View and analyze previous imports
      • Troubleshoot import errors
      • Deduplicate contacts, companies, deals, tickets, and products
    • companies
      • Create companies
      • A guide to your companies home
      • Work with your company records
      • HubSpot's default company properties
    • deals
      • Create deals
      • A guide to your deals home
      • Work with your deal records
      • HubSpot's default deal properties
    • tickets
      • Create tickets
      • Work with your ticket records
      • A guide to your tickets home
      • HubSpot's default ticket properties
  • Google Ads
    • Topic
      • Setup and basics
      • Measure results
      • Manage ads
      • Smart campaigns
      • Billing
      • Learn
      • Google Partners
      • Your guide to Google Ads
      • Google Ads basics
      • Create ads and campaigns
      • Choose where and when ads appear
      • Find out if your ad is running
      • Account administration and security
      • Glossary
      • Local Services ads
      • The Google Ads mobile app
      • Ads and approvals
      • Campaign settings
      • Budgets and bids
      • Keywords
      • Reach your audience
      • Target placements and topics
      • Multiple or large accounts
      • Connect your goals to data
      • Find and run reports
    • Google Ads Help
  • Google Analytics
    • answer
      • Get started with Analytics
      • Find your way around Analytics
      • Guided tours
      • Manage and configure Analytics
      • Hierarchy of organizations, accounts, users, properties, and views
      • Diagnostics messages
      • How to get support
      • Google Marketing Platform Partners
      • Introducing Google Marketing Platform
      • Organizations
      • Google Analytics Home
      • Search in Google Analytics
    • Topic
      • Set up (web)
      • Set up (mobile apps)
      • Universal Analytics (UA)
      • Glossary
      • Troubleshoot Analytics problems
      • Understand the Analytics account structure
      • Accounts
      • Properties
      • Reporting views
      • Reporting-view filters
      • User management
      • Common issues
      • Monitor account health and performance
      • Audience reports
  • Google Tag Manager
    • answer
      • Tag Manager overview
      • Considerations before you install
      • Setup and install Tag Manager
      • Tag Manager and gtag.js
      • Introducing Google Marketing Platform
      • The data layer
      • Components of Google Tag Manager
      • Supported tags
      • Conversion linker
      • Google Optimize
      • Custom tags
      • AMP & Tag Manager setup guide
      • Content experiments for mobile apps
      • Custom templates
      • Community Template Gallery
      • Google Marketing Platform Partners
      • Data Processing Amendment
    • Topic
      • Tags
      • Triggers
      • Variables
      • Google Analytics
      • Google Ads
      • Floodlight
      • Accounts
      • Workflow
      • Organization
      • Troubleshooting
Powered by GitBook
On this page
  • The data layer
  • Create a data layer variable
  • Additional resources

Was this helpful?

  1. Google Tag Manager
  2. answer

The data layer

Search

Clear search

Close search

Google apps

Main menu

Send feedback on...

This help content & information

General Help Center experience

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.

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

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:

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

Add information to the data layer with the dataLayer.push() command:

<a href="#" onclick="dataLayer.push({ 'bookCategory': 'fiction', 'bookTitle': 'Cien años de soledad', 'bookAuthor': 'Gabriel García Márquez' });">Book details</a>

Set up the data layer variable

Once you have the key that you would like to work with, you can proceed to create a data layer variable:

  1. Click Variables.

  2. Under User-Defined Variables, click New.

  3. Click Variable Configuration and select Data Layer Variable as the variable type.

  4. In the Data Layer Variable Name field, enter the key exactly as it was written in the code (e.g. bookTitle, not book title.)

  5. Save the variable.

  6. Repeat these steps for every data layer key that you would like to have available as a variable in Tag Manager.

  7. Publish the container.

Note: Data layer variables only work on a per-page basis. If you would like the data layer values to persist through multiple page views, you will need to add your own code to pass data layer values between pages.

Additional resources

Was this helpful?

How can we improve it?

PreviousIntroducing Google Marketing PlatformNextComponents of Google Tag Manager

Last updated 5 years ago

Was this helpful?

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 in Peace', 'A Brief History of Time', etc.

See the to learn more about data layer implementations.

In most cases you should leave the Data Layer Version set to the default value of Version 2. .

Data layer variables
developer documentation
Learn more
Components of Google Tag Manager
Developer documentation