Fortunitus Check your tracking

The data layer explained with a real purchase example

The data layer is a list on your web page where the website writes what just happened (a purchase, a form sent, a product added to cart) together with the details. Google Tag Manager reads that list and passes the details to GA4, Google Ads or Meta. This guide follows one real purchase through every step.

Short answer: the data layer is a JavaScript array called window.dataLayer. The website adds messages to it with dataLayer.push(), for example {event: 'purchase', ecommerce: {value: 24.90, currency: 'EUR', …}}. In Google Tag Manager, a Custom Event trigger reacts to the event name, Data Layer Variables read the values, and a tag sends them to GA4 or an ad platform. The website owns the data, Tag Manager only reads it.

Why the data layer exists

Tag Manager can read things it sees on the page, such as the page address or a clicked button. It cannot reliably read things only your website knows: the order number, the order value, which products were bought, whether the visitor is logged in. Scraping those from the page text breaks as soon as someone changes the design.

The data layer solves this. The website writes the facts into one agreed place, in an agreed format, and every tag reads from there. Google describes it as an object used by Google Tag Manager and gtag.js to pass information to tags.

How a purchase travels, step by step

Four steps: the website pushes a purchase event into dataLayer, a Custom Event trigger notices it, Data Layer Variables read ecommerce.value, currency and items, the GA4 tag sends the purchase.

To show this with real screens rather than drawings, we built a small demo shop with its own Tag Manager container and its own GA4 property, so the test orders do not mix with any real data. Here is the product page after clicking Add to cart and Buy now:

Demo shop product page for a ceramic coffee mug at 24.90 euros with Add to cart and Buy now buttons and the message Thank you! Order T-1042.
The demo shop. 1: the two buttons, each pushes a message into the data layer. 2: the confirmation for order T-1042.

Step 1: the website pushes the purchase

When the order is confirmed, the website runs this code. In a real shop the values come from the order, here they are written out:

dataLayer.push({ ecommerce: null });  // clear the previous ecommerce object
dataLayer.push({
  event: 'purchase',
  ecommerce: {
    transaction_id: 'T-1042',
    currency: 'EUR',
    value: 24.90,
    tax: 4.32,
    shipping: 0,
    items: [{
      item_id: 'MUG-350',
      item_name: 'Ceramic coffee mug',
      item_category: 'Kitchen',
      price: 24.90,
      quantity: 1
    }]
  }
});

Three details matter:

  • The event name (event: 'purchase') is what Tag Manager reacts to. Without it, the values are stored but no trigger fires.
  • Clearing ecommerce first is what Google's ecommerce guide does in every example. Otherwise values from an earlier step, such as the cart, can leak into the purchase.
  • Numbers are numbers. 24.90, not '24,90' with a comma. Text values with commas are a common reason purchases arrive without revenue.

Step 2: see it in Tag Assistant

Connect Tag Assistant to the site, make the purchase, click the purchase event on the left and open the Data Layer tab. You see exactly what the website wrote:

Tag Assistant Data Layer tab for the purchase event showing the ecommerce object with currency EUR, the item MUG-350, shipping 0, tax 4.32, transaction_id T-1042 and value 24.9.
1: the Data Layer tab. 2: the ecommerce object, as the website pushed it.

If something is missing here, the problem is on the website, not in Tag Manager. Send this screenshot to whoever built the shop.

Step 3: Data Layer Variables read the values

A Data Layer Variable is a Tag Manager variable that reads one key from the data layer. The name is the path to the value, with dots between levels: ecommerce.value, ecommerce.currency, ecommerce.transaction_id.

Google Tag Manager variable DLV - ecommerce.value of type Data Layer Variable with the name ecommerce.value and Version 2.
1: the variable type, Data Layer Variable. 2: the path to the value, ecommerce.value.

To create one: Variables → New → Variable Configuration → Data Layer Variable, type the path, keep Version 2 and save. The Variables tab in Tag Assistant then shows what each variable read on every event:

Tag Assistant Variables tab on the purchase event: DLV - ecommerce.currency EUR, DLV - ecommerce.items array with one item, DLV - ecommerce.transaction_id T-1042, DLV - ecommerce.value number 24.9.
1: the Variables tab. 2: the four Data Layer Variables and their values on the purchase event. Note that the value has the type number.

A variable that shows undefined means the path is wrong (a typo, or a missing ecommerce. in front) or the website did not send that key.

Step 4: the tag sends it

For GA4 ecommerce you do not need to map every field by hand. In the GA4 event tag, set the event name to purchase, open More settings → Ecommerce, tick Send Ecommerce data and choose Data Layer as the source. Fire it with a Custom Event trigger on purchase:

Tag Assistant details of the GA4 - purchase tag: Send Ecommerce data true, Data source dataLayer, firing trigger CE - purchase with _event equals purchase, and a Purchase hit sent to G-YDB8WCJ51P.
1: Send Ecommerce data from the data layer. 2: the Custom Event trigger that matched. 3: the Purchase hit sent to the demo GA4 property.

And here is the result a minute later in the demo property's Realtime report:

GA4 Realtime report of the demo property: event count by event name including add_to_cart 1 and purchase 1, and purchase listed under key events.
1: the add_to_cart and purchase events received. 2: purchase counted as a key event.

Common data layer mistakes

MistakeWhat happensFix
No event key in the pushValues are stored, but no trigger firesAlways push an event name with the data
Price as text with a comma, '24,90'Revenue missing or wrong in GA4 and ad platformsSend a number with a dot: 24.90
Not clearing ecommerce between stepsProducts from the cart appear in the purchasePush {ecommerce: null} before each ecommerce event
dataLayer = [...] instead of dataLayer.push()Overwrites the list and breaks Tag ManagerCreate it with window.dataLayer = window.dataLayer || [], then only push
Purchase pushed on every visit to the thank-you pageDuplicate purchases when the page is refreshedPush once per order and always send transaction_id
Wrong variable pathVariable shows undefinedCopy the exact path from the Data Layer tab

Shopify, WooCommerce and other platforms

You rarely write the purchase push yourself on a shop platform. WooCommerce plugins such as GTM4WP and Shopify's customer events can generate the GA4 ecommerce data layer for you. The checks in this guide stay the same: open Tag Assistant, buy something cheap or use a test order, and look at the Data Layer tab. If the structure matches the example above, Tag Manager can use it.

Check your own setup

The free tracking checker shows which GA4, GTM, Google Ads, Meta and cookie banner tags your site loads and what is inside your GTM container.

Run the checker

Frequently asked questions

What is a data layer?

A JavaScript array, window.dataLayer, where the website writes information such as events and order details. Google Tag Manager reads it and passes the information to tags like GA4, Google Ads or Meta.

What does dataLayer.push do?

It adds a new message to the data layer. If the message contains an event key, Tag Manager processes it as an event, and triggers and tags can react to it.

How do I see the data layer on a website?

Connect Google Tag Assistant to the site and open the Data Layer tab on any event, or type dataLayer in the browser developer console to see the raw array.

What is a Data Layer Variable in GTM?

A Tag Manager variable that reads one value from the data layer by its path, for example ecommerce.value. Tags and triggers can then use that value.

Why is my data layer variable undefined?

Usually the path is wrong, the website did not send that key, or the variable is read on an event that happened before the value was pushed.

Check your own setup in 20 seconds

Run any website through the free tracking checker: GA4, Google Tag Manager, Google Ads, Meta Pixel, cookie banner and what sits inside the GTM container.