Skip to content

Knowledge BaseGoogle Tag Manager

What Is the dataLayer in Tag Management?

Definition

The dataLayer is a JavaScript array that a website pushes structured event data into, acting as a message queue between the site's code and a tag management system such as Google Tag Manager.

Each push — typically an object with an event name and related parameters, such as a purchase with its items and value — is read by GTM's triggers and variables, which decide which tags to fire and what data to pass them. It decouples the site's code from the tags themselves, so tracking logic can change in GTM without editing the site's source code.

Data Layer Variables
ecommerce.valueecommerce.transaction_id
  1. In practice

    How does the dataLayer work in practice?

    A page — or a Shopify theme, or a checkout script — executes window.dataLayer.push({...}) at the moment something worth tracking happens: a page view, an add-to-cart click, a completed purchase.

    GTM’s container, loaded on the page, listens for these pushes via its Custom Event trigger type and matching Data Layer Variables that pull specific fields, such as ecommerce.value or ecommerce.transaction_id, out of the pushed object. Because the dataLayer is a JavaScript array in the page’s global scope, any tag, script, or GTM container on the page can read from it, which is what makes it a shared, structured interface rather than a one-off variable.

  2. In practice

    A dataLayer.push example for purchase

    This fictional example belongs in the same page context as the web GTM container. Run it in a test environment when the action happens; do not send a purchase merely because a page loaded.

    window.dataLayer = window.dataLayer || [];
    window.dataLayer.push({ ecommerce: null });
    window.dataLayer.push({
      event: "purchase",
      ecommerce: {
        transaction_id: "ORDER_EXAMPLE",
        value: 100,
        currency: "EUR",
        items: [{ item_id: "SKU_EXAMPLE", price: 100, quantity: 1 }]
      }
    });

    The event name selects the Custom Event trigger. GTM variables read the order fields from that event. A queued object does not prove that a tag fired or that GA4 received a purchase. Keep the existing queue instead of replacing it after GTM loads.

    What you seeWhat to inspect
    No tag firesThe purchase trigger, its conditions and the consent state
    A field is missingecommerce.value and ecommerce.transaction_id on the triggering event
    A tag fires but no purchase is recordedThe outgoing request, destination property and receiving diagnostics

    A Shopify custom pixel runs in an isolated iframe. Its dataLayer is separate from the storefront window. Google does not support installing Google tags or GTM inside that custom-pixel sandbox and recommends the Google & YouTube app for its measurement. This example is not a Shopify checkout installation guide.

    Google: dataLayer · GA4 ecommerce · Shopify: sandbox · Google: Shopify custom pixel limits

  3. Not to be confused with

    The dataLayer is not GTM itself, and pushing to it does not automatically send data anywhere — it only makes data available for GTM, or any other listener, to pick up if a trigger is configured to react to it.

    It’s also not a single universal format: ecommerce dataLayer pushes commonly follow Google’s Enhanced Ecommerce / GA4 ecommerce object structure, but a site can push arbitrary object shapes, and mismatches between what a site pushes and what GTM’s variables expect to read are a common source of tags firing with missing or blank data.

  4. Where to check

    How to check

    In the browser console on any page, typing dataLayer returns the current array and every object pushed so far, which is the fastest way to confirm whether an expected event fired and what data it carried. GTM’s own Preview mode shows each dataLayer push in the summary panel alongside which tags, triggers, and variables reacted to it.

Daniil Maximkin

Hi, I’m Daniil.

I work with you from defining the problem to implementation and handover. You talk to the person who does the work. I work in English and Russian; written correspondence in Spanish with translation support.

What do you need to get working?

Describe your task

The first answer is free, within one working day. Or write directly: next@taskfordaniel.com