dataLayer
dataLayer is the JavaScript array on a web page that the site uses to pass data, such as order details, to Google Tag Manager and the Google tag.
How it works
The page creates the array once, high in the code, before the Tag Manager container. The site then adds messages with dataLayer.push(): a message can name an event, such as purchase, and carry values. Tag Manager processes the messages one at a time, in order. It fires the tags whose triggers match the event, and its variables read the values.
For a store, the key message is the purchase. The backend knows the order number, amount and items, and writes them into the push on the thank-you page. The tags take the transaction ID, conversion value and item list from that push. The same push feeds the purchase event in Google Analytics 4.
Google designed its tags to read the dataLayer rather than collect details scattered across the page. Our guide to the purchase event in Google Tag Manager covers the setup.
Where you see it
- Browser console: type
dataLayerto see every message pushed so far. - Google Tag Assistant: shows the dataLayer at each event as you click through the site.
Example
Example store, not client data.
The tableware shop sells a dinner set, item ds-24, for 600. Its thank-you page pushes:
dataLayer.push({ ecommerce: null });
dataLayer.push({
event: "purchase",
ecommerce: {
transaction_id: "10452",
value: 600,
currency: "EUR",
items: [{ item_id: "ds-24", price: 600, quantity: 1 }]
}
});
The first line clears the previous ecommerce object, as in Google’s GA4 guide. A trigger on purchase fires the tags, and they read the value, 600, and order 10452 from the message.
Not to be confused with
- Google Tag Manager — the container with tags, triggers and variables. The dataLayer only holds data: Tag Manager reads what the site pushes into it.
Right and wrong readings
- Wrong: “A tag that fires when the thank-you page loads counts orders.” Right: without an order number, it counts page loads: a reload can fire it again for the same order. A
purchasepush carries the order number and amount, and Google Ads drops a second conversion with the same order number.
Sources
- The data layer — installation,
push, processing order, Tag Assistant. Checked 2 October 2026. - Measure ecommerce — the GA4
purchasepush. Checked 2 October 2026. - Use a transaction ID to minimize duplicate conversions — firing again on reload, duplicates dropped by ID. Checked 2 October 2026 (archived copy of 8 June 2026).