What is a data layer? How the GTM dataLayer works, and where tracking breaks
A data layer is the dataLayer JavaScript array that passes page data to Google Tag Manager tags. It breaks on push order, stale ecommerce and string values.
A data layer is the window.dataLayer JavaScript object that Google Tag Manager and gtag.js use “to pass information to tags” (Google Tag Platform, updated November 6, 2026, accessed November 29, 2026). Your site writes to it with dataLayer.push(), and GTM reads what arrived to decide which tag fires and with what value. When the data goes in wrong, GA4 records the error as fact, because the tag doesn’t check what’s inside by default.
Data layer: “a JavaScript object that temporarily stores data about user interactions with a website or app.” Data Layer variables in Google Tag Manager “access the stored data and use them in your tags” (Tag Manager Help glossary, accessed November 29, 2026).
I wrote this entry with Google’s documentation open next to it, all of it read on November 29, 2026. Google’s developer page states two limits that explain most of what follows: “Only one dataLayer object is supported per page,” and each variable in it “will persist only as long as the visitor remains on the current page” (Google Tag Platform).
How does the GTM dataLayer actually work?
Four rules, all from that same developer page:
- It’s created before the container. The code is
window.dataLayer = window.dataLayer || [];, placed “as high up in the source code as possible, above the container snippet.” If a value has to be available when the page loads, itsdataLayer.push()“needs to be above the Tag Manager container code as well.” - An event is a key named
event. The syntax isdataLayer.push({'event': 'event_name'}), and variables travel in the same object. Push a variable that already exists and “the existing value will be overwritten by the new value.” - The queue runs in order. “Tag Manager processes messages on a first-in, first-out basis,” one at a time, and an event’s tags fire before the next message. A push made inside a Custom HTML tag goes to the back of the queue, so “any updated data layer values are not guaranteed to be available for the next event.” Google’s documented fix is to give the push an event name and listen for it with a Custom Event trigger.
- It lasts one page. Anything that matters across the site, like visitor type, has to be pushed again on every page, under the same name.
On the GTM side, the reader is the Data Layer variable type. In version 2, the default, a dot means nesting: ecommerce.value reads the value field inside ecommerce (Tag Manager Help, accessed November 29, 2026).
How is the data layer different from a variable, a tag and a GA4 event?
Four pieces that tend to get the same name in a meeting. The table separates who writes each one and how long it lasts.
dataLayer | Data Layer variable | GA4 tag in GTM | GA4 event | |
|---|---|---|---|---|
| What it is | JavaScript array on the page | A read of one dataLayer key | Rule that builds and sends the event | Record the property receives |
| Written by | Site code, the platform or an app | Whoever configures the container | Whoever configures the container | Google, from the tag |
| Lives in | The browser, on the open page | The published container | The published container | GA4 reports |
| Lasts | Until the page changes | Until the container changes | Until the container changes | The property’s retention period |
| Typical failure | Value in the wrong format | Name spelled differently from the push | Duplicate firing | Revenue that doesn’t match the order |
Sources: Google Tag Platform and Tag Manager Help, accessed November 29, 2026.
Where does the data layer break tracking?
In five places. None of them shows up as an error in GTM: the tag fires, GA4 receives it, and the number comes out wrong.
1. The push happens in the wrong order
Google names two ordering mistakes. The first is rebuilding the array with dataLayer = [...], which “will overwrite any existing values.” The second is pushing, after the container, a value a page-load tag needed to read. The page also warns that the name is case-sensitive: “If you try to push a variable or event without the proper casing, the push won’t work.” A datalayer.push() with a lowercase “l” goes nowhere (Google Tag Platform).
2. The ecommerce object never gets cleared
Every GA4 ecommerce example for GTM starts with the same line: dataLayer.push({ ecommerce: null });, commented “Clear the previous ecommerce object” (Google Analytics, Measure ecommerce, updated October 14, 2026). The page doesn’t say why.
The likely reason is in data-layer-helper, a library Google publishes on GitHub. Its README describes the same “abstract data model” the GTM page mentions, and says two objects under the same key are merged recursively, and so are two arrays. Under that rule, an items array of three products from a collection page, followed by a purchase with one product, would leave the last two collection items in the object. Google doesn’t say the GTM container runs that code; read this as inference.
In practice, clear ecommerce before every ecommerce push, no exceptions.
3. The value arrives as a string
GA4’s events reference types value as number and says that “if you set value then currency is required for revenue metrics to be computed accurately” (Google Analytics, recommended events, updated September 16, 2026). Yet the JSON example on Google’s own dataLayer page shows value : "120", in quotes. Copy the example and you send a string.
The bigger risk is a price scraped from the storefront with its thousands separator. In JavaScript, when parseFloat “encounters an invalid character, it returns the number represented up to that point” (MDN, updated November 16, 2026). In a synthetic example, the price 1,299.00, with the dollar sign already stripped, becomes 1, one dollar, if someone converts it with parseFloat. Leave the sign in and parseFloat("$1,299.00") returns NaN, which isn’t a number at all. GA4’s docs don’t say what the property does with a string value; DebugView shows what actually arrived.
The same reference adds one more rule for purchase: value is the sum of price times quantity across items, and “Don’t include shipping or tax.” Those go in shipping and tax.
4. The purchase runs through a sandbox, or never fires
On Shopify, GTM runs as a custom pixel inside a sandbox, and “pixels that Google Tag Manager loads still run within the Shopify sandbox” (Shopify Help Center, accessed November 29, 2026). Three documented consequences:
- The event name isn’t
purchase. Shopify’s tutorial subscribes tocheckout_completedand pushes it to thedataLayerunder that name, so GTM needs its own trigger and mapping to GA4 (Shopify GTM tutorial). valuegets mapped to a total that includes tax. The tutorial mapsevent.data?.checkout?.totalPrice?.amountto GA4’svalue. Shopify definestotalPriceas “the sum of all the prices of all the items in the checkout, including duties, taxes, and discounts,” whilesubtotalPriceis “the price at checkout before duties, shipping, and taxes” (Shopifycheckout_completed). Use the tutorial as written and GA4 receives avalueits own reference says shouldn’t include tax. The broader definitional gap is in why Shopify and GA4 revenue never match.- Debugging is harder. Shopify says Tag Assistant’s “Troubleshoot tag” feature “isn’t compatible with custom pixels,” and that page URLs in the Lax sandbox “include a sandbox version and not exactly reflect the main window’s URL.”
Off Shopify, the old failure still applies: the dataLayer lives on one page, so purchase depends on someone loading the confirmation page. Hosted payment pages and buy-now-pay-later redirects break that, as covered in redirect payments that break the GA4 purchase.
5. The purchase counts twice, or not at all
GA4’s validation guide says to use gtag.js or GTM, “but not both,” because “using both options will double count certain events.” It also says that if the same ecommerce event fires twice with the same transaction_id, “Google Analytics will only collect the first event and ignore the second event” (Google Analytics, validate ecommerce, updated October 9, 2024). A transaction_id reused across different orders turns that deduplication into deleting real orders.
How do you check your store’s data layer?
Five checks that fit in an afternoon:
- In the browser console, type
window.dataLayeron a product page, the cart and the confirmation page. Each push shows up as an object, in arrival order. - Confirm there’s an
{ecommerce: null}right before every ecommerce event. - In the
purchaseobject, check the type:typeofonvalueshould returnnumber, with no shipping or tax folded in. - Open GTM preview mode with Tag Assistant, which Google says lets you “inspect the status of your data layer at any point in a chain of events.” On Shopify, the GTM tutorial points to the Shopify Pixel Helper to confirm that events “are being added to the sandbox without errors.”
- Compare one day of
transaction_idvalues in GA4 against order numbers in Shopify or your OMS. An order with nopurchaseis a purchase that never fired; apurchasewith no order is often a test order or one canceled later.
Step 5 is the only one that sizes the problem in dollars.
What is a data layer not?
It isn’t a database. Nothing survives the page change, and it doesn’t replace the order record.
It isn’t the “data layer” in the architecture sense, the one that serves answers to an AI agent. That other meaning is covered in what a trusted data layer for AI agents is.
It isn’t a semantic layer. The dataLayer carries whatever value the page had; a semantic layer defines what counts as revenue (what goes into a semantic layer).
It isn’t read by server-side GTM. A server container receives HTTP requests through clients, which Google describes as “adapters between the software running on a user’s device and your server container” (Google Tag Platform, updated July 30, 2026). A wrong dataLayer in the browser reaches the server already packaged, a point whether server-side tagging is worth it develops.
When does this start to matter for a store?
When GA4 revenue and Shopify revenue drift apart and the conversation stalls on “which number is right.” The breaks above don’t all push the same way: an uncleared ecommerce can inflate items, a tax-inclusive value and double tagging inflate revenue, and a badly converted value and a purchase that never fires shrink it. Added together, they partly cancel out and hide the real size of the error.
That’s why the order record comes before the event. At Precisian, GA4 and the ecommerce platform arrive through automated ingestion into a per-client isolated data lake, on our infrastructure, and the definition of revenue becomes a versioned rule in the semantic layer instead of a mapping buried in a pixel.
What does this article not cover?
It doesn’t walk through building a container from scratch or list every GA4 recommended event.
It doesn’t cover consent mode, which changes what tags can store even with a correct dataLayer. Google says consent updates should be processed “before any queued items in the data layer” (Google Tag Platform); consent mode and modeled data shows what GA4 fills in with estimates. Who can change the container is covered in the Google Tag Manager MCP.
It doesn’t confirm the merge rule inside the GTM container, because Google documents it only in the data-layer-helper library.
If GA4 closes the month with revenue that doesn’t match your order system, start by matching one day of transaction_id values against paid orders. See this article’s question answered on a real lake, with no contract commitment.