Skip to content

Glossary

Data layer

By CartKernel ยท Last reviewed

Definition

Data layer is the structured JavaScript object, on most stores the window.dataLayer array that Google Tag Manager reads, into which the storefront pushes page details and ecommerce events such as view_item, add_to_cart, begin_checkout and purchase, each carrying an items array. Tags read from the data layer instead of scraping the page, so the same purchase data feeds GA4, Google Ads and Meta consistently and survives a theme redesign.

A purchase push, laid out field by field

event
purchase
ecommerce.transaction_id
1084 (the store's order number, sent once per order)
ecommerce.value
148.00 (the order total, stated consistently with or without shipping across every platform)
ecommerce.currency
CAD
ecommerce.items[0].item_id
SKU-4412-BLK-M
ecommerce.items[0].item_name
Merino crew sweater
ecommerce.items[0].price
74.00, with quantity 2
ecommerce.items[0].item_category
Knitwear, with item_brand and item_variant alongside

Illustrative values in the GA4 recommended shape. The tag manager reads these keys and maps them to GA4 event parameters, so the same object drives the Google Ads purchase conversion and the Meta Purchase event with matching content_ids.

Why it matters

The data layer matters because every conversion report starts with it. If the purchase push carries the wrong total, GA4, Google Ads and Meta all report the wrong revenue and no amount of attribution work fixes it downstream. A clean data layer also separates tracking from design: a new theme or a new app can change the page while the events keep the same names and keys, so history stays comparable. For a store spending on ads, the items array is what powers dynamic remarketing and Performance Max product signals, and the item_id has to match the Merchant Center id for those to work. Getting it right once saves a rebuild every time the storefront changes.

Where it goes wrong

  • Pushing purchase on the thank-you page without clearing the ecommerce object first, so a reload or a second order in the same session carries stale items
  • item_id values that do not match the id in Merchant Center, usually a Shopify variant ID on one side and a SKU on the other, which breaks dynamic remarketing and product-level reporting
  • Order totals that include tax and shipping on one platform and exclude them on another, which makes Shopify, GA4 and Google Ads disagree by a margin that looks like an attribution problem
  • Relying on theme scripts for checkout events on Shopify, where the checkout does not run theme code and the purchase must come from a custom pixel or a server-side source

Questions about data layer

Is a data layer required to use Google Tag Manager on an ecommerce site?

Not strictly. Tags can read values from page elements or from URL patterns, but that ties tracking to the layout. A data layer gives every tag one authoritative set of values for the order and its items, which is why Google's GA4 ecommerce documentation and most platform integrations are built around it.

How does Shopify handle the data layer at checkout?

Shopify's checkout does not load theme JavaScript, so a data layer pushed by the theme stops at the cart. The supported path is the Web Pixels API: a custom pixel subscribes to standard events such as checkout_completed and forwards them, either into a tag manager loaded inside the pixel sandbox or directly to a tagging endpoint. The Google and YouTube channel app also sends conversion data to Google on its own.

What should the items array contain for GA4 ecommerce?

At minimum item_id and item_name for each line, then price, quantity, item_brand, item_category and item_variant where the store has them. Keep item_id identical to the product identifier in your feed, use the unit price rather than the line total, and include currency at the event level so GA4 can convert.

Find the leak.

A free Growth Analysis ranks what your store should fix first, by revenue at stake.