Skip to content

What Is a Data Layer?

Definition

A data layer is a JavaScript object on a website, usually named dataLayer, that holds structured information about the page and about user actions such as viewing a product, adding to cart or purchasing. Google Tag Manager and gtag.js read it to pass the same consistent values to analytics and advertising tools.

How a data layer works

Every marketing and analytics tool on a store wants the same facts: what page this is, which product is shown, what went into the cart, what was bought and for how much. Without a data layer, each tool scrapes those facts from the page in its own way, and each gets slightly different numbers. A data layer gives them one shared source. The site writes the facts once, in a fixed structure, and the tag manager hands them to every tool.

In Google's definition, the data layer is an object used by Google Tag Manager and gtag.js to pass information to tags[1]. In practice it is a JavaScript array, named dataLayer by default[1]. The site adds a message to it each time something happens, and a message with an event key, such as add_to_cart, is what lets Tag Manager fire tags on that event[1]. Google advises declaring it as high in the page as possible, above the container snippet, and never overwriting or re-assigning it once it exists[1].

The data layer is not a tool you buy. It is an agreement between the developers who fill it and the marketers who read it: which events exist, what each one is called, and which fields it carries. Tag Manager, GA4, Google Ads and Meta sit downstream of that agreement.

What goes into a data layer

PartWhat it holdsExample on a store
Event nameWhat just happenedview_item, add_to_cart, purchase
Page contextFacts about the page and sessionPage type, language, currency, logged-in or not
Ecommerce objectThe products involved and the moneyAn items array with ID, name, variant, price and quantity, plus value and currency
Consent stateWhat the visitor allowedWhether analytics and marketing tags may run

Most stores use Google's GA4 ecommerce events as the naming standard, even for tools other than GA4. Google documents events from view_item_list and view_item through add_to_cart, begin_checkout, add_payment_info and purchase to refund, represents products as an array of items, and recommends setting currency whenever an event carries a value[2].

The data layer on Shopify

A Shopify store has two places where data gets collected, and they work differently.

The storefront (home, collection, product and cart pages) is rendered by the theme. Shopify's reference theme, Dawn, creates no dataLayer[3], so a GTM data layer on these pages is something your theme code has to build.

The checkout is not open to theme code. checkout.liquid is unsupported for the information, shipping and payment steps, and it and Additional scripts were sunset on the Thank you and Order status pages on 28 August 2025[4]. Our post on Shopify Checkout Extensibility in 2026 covers what replaced them. Here Shopify provides its own event stream instead: customer events. These are actions in the customer's browser that pixels subscribe to, and pixels load automatically on the storefront, checkout, Thank you and Order status pages[5]. Shopify maintains 15 standard events, from page_viewed and product_viewed to checkout_started, payment_info_submitted and checkout_completed[6].

Pixels come in two kinds: app pixels installed by apps, and custom pixels that a developer adds under Customer events in the admin[5]. Both run in a sandbox, strict for app pixels and lax for custom pixels[7], and in regions that require consent they only run when the visitor has given the permissions the pixel needs[5]. Shopify documents running Google Tag Manager as a custom pixel: the pixel subscribes to a Shopify event and pushes it into dataLayer for GTM to read[8]. Shopify does not support the code in custom pixels, so you own it[9].

So on Shopify, "the data layer" is really two halves that must agree: your own dataLayer where the theme runs, and Shopify's customer events where it does not. For the full setup, with GTM, consent, the custom pixel and testing, follow our step-by-step guide on how to add a data layer to Shopify Plus.

Example: one order, followed through the data layer

Take a hypothetical store selling two linen shirts at €44.99 each. Here is what the data should look like at each step, if both halves follow the same rules:

StepSourceEventKey values
Product pageTheme dataLayerview_itemitem ID LS-BLUE-M, price 44.99, currency EUR
Add to cartTheme dataLayeradd_to_cartsame item ID, quantity 2, value 89.98
Checkout opensPixel, from checkout_startedbegin_checkoutsame item ID, value 89.98
Order placedPixel, from checkout_completedpurchaseorder ID, value 89.98, currency EUR

The test of a working data layer is that the item ID, price and currency never change between rows, whichever half sends them. If the theme sends the SKU and the pixel sends the variant ID, product reports in GA4 split one shirt into two. Then the totals must reconcile: if Shopify shows 400 orders for the month and GA4 shows 368 purchases, the 8% gap is worth investigating before anyone trusts the numbers for ad spend or for a CRO project.

Data layer vs Shopify customer events

Data layer (dataLayer)Shopify customer events
Who defines itYou: event names and fields are your choiceShopify: 15 standard events with fixed fields, plus custom events you publish
Where it runs on ShopifyTheme pagesStorefront, checkout, Thank you and Order status pages
Who reads itGoogle Tag Manager and gtag.jsApp pixels and custom pixels
Typical usePage context, product views, cart eventsCheckout steps and purchases

FAQ

Does Shopify have a data layer?

Not a GTM data layer. Dawn creates no dataLayer[3]. Shopify does publish its own customer events, such as product_viewed and checkout_completed, which pixels subscribe to[6]. Most setups combine the two.

Do I need Google Tag Manager to use a data layer?

No. Google's data layer is used by both Google Tag Manager and gtag.js[1]. In practice most stores use GTM, because it lets one data layer feed GA4, Google Ads, Meta and other tools.

Can I track Shopify checkout with theme code?

No. checkout.liquid is unsupported on the checkout steps, and Additional scripts were sunset on the Thank you and Order status pages[4]. Checkout tracking goes through pixels subscribed to customer events[5].

Is a data layer the same as a pixel?

No. A data layer holds the facts; a pixel is a script that sends facts to one platform, such as Meta or GA4. On Shopify, a custom pixel can also read customer events and push them into a dataLayer for GTM[8].

The bottom line

A data layer is a shared, structured record of what happens on a site, written once by the site and read by every tag. On Shopify it comes in two halves: a dataLayer that your theme fills on storefront pages, and Shopify's customer events that pixels use in the checkout. Clean analytics depend on both halves using the same names, IDs and currency, and on each event having exactly one sender.

Article sources

We use primary sources only: official documentation, product pages and laws. Each link was checked on the date shown.

  1. Google for Developers (Tag Platform). The data layer. Accessed 17th Nov 2026.
  2. Google for Developers (Google Analytics). Measure ecommerce (GA4). Accessed 17th Nov 2026.
  3. Shopify (GitHub). Dawn theme: layout/theme.liquid. Accessed 17th Nov 2026.
  4. Shopify. checkout.liquid. Accessed 17th Nov 2026.
  5. Shopify Help Center. Pixels overview. Accessed 17th Nov 2026.
  6. Shopify. Web Pixels API: Standard events. Accessed 17th Nov 2026.
  7. Shopify. Web Pixels API. Accessed 17th Nov 2026.
  8. Shopify Help Center. Create a Google Tag Manager custom pixel. Accessed 17th Nov 2026.
  9. Shopify Help Center. Custom pixels. Accessed 17th Nov 2026.

Need this on your store?

See the service

The checklist we run before touching a client's code

Get it by email, plus a few short notes over the next two weeks: what we see most often on Shopify stores and what actually fixes it.

No spam. Unsubscribe anytime. Privacy Policy