Analytics and Tracking

dataLayer.push

Also called data layer push

The JavaScript command a website uses to send events and details into the data layer for Google Tag Manager to act on.

Quick facts: dataLayer.push

Category
Analytics and Tracking
Also called
data layer push
Level
Advanced
Affects
Tag Manager triggers, GA4 events, ecommerce tracking, ad platform conversions
Where to see it
Google Tag Manager preview mode, Tag Assistant, browser developer console, GA4 DebugView
In this article4
  1. How dataLayer.push works
  2. Why it matters
  3. Common mistakes
  4. How to act on it

dataLayer.push is the line of JavaScript a website uses to hand information to Google Tag Manager: that a form was sent, which product was added to the basket, or what an order was worth. Each push adds a small message to the data layer, and Tag Manager reads those messages to decide which tags to fire and what to send.

How dataLayer.push works

The data layer is a list that lives in the page. Tag Manager watches it. When the site calls dataLayer.push with an object, such as event set to quote_request and service set to boiler_repair, Tag Manager receives that message straight away.

Two parts of a push do different jobs:

  • The event key is the name of what happened. A custom event trigger in Tag Manager listens for that exact name and fires tags when it arrives.
  • The other keys are details. Data layer variables in Tag Manager read them, so a GA4 tag can send the service name, form name or order value as event parameters.

A push without an event key still stores its details, but no trigger fires on it. That suits information you want available later, such as a page type or a logged-in status set before Tag Manager loads.

The data layer should be declared before the Tag Manager snippet with the familiar “window.dataLayer = window.dataLayer || []” line. That line creates the list only if it does not exist yet, so pushes made earlier are kept rather than wiped.

Why it matters

Tracking that relies on clicks and page structure breaks whenever a developer renames a button or redesigns a form. A push from the site’s own code says plainly what happened, so it survives redesigns and gives cleaner data. It is the difference between guessing that a click on a blue button probably meant a booking and being told that a booking for a 30-minute consultation was confirmed.

For shops, ecommerce events such as add_to_cart and purchase are almost always passed this way, with the product details in an ecommerce object. Google recommends pushing ecommerce set to null just before each new ecommerce push, so details from one event do not leak into the next.

Common mistakes

  • Resetting the list with “dataLayer = []” after Tag Manager has loaded, which breaks the connection and silently stops tags firing.
  • Getting the name wrong. JavaScript is case-sensitive, so “datalayer.push” or “DataLayer.push” will not reach Tag Manager.
  • Mismatched event names between the developer’s code and the Tag Manager trigger, such as form_submit in one and formSubmit in the other.
  • Personal data in the push. Email addresses, phone numbers or names should not be pushed for analytics. Under UK GDPR that is personal data you would then be sending on, and GA4’s terms forbid it.
  • Pushing before the page knows the answer, for example sending a form event on submit before the server has confirmed it went through.

How to act on it

Agree a short specification with your developer: each event name, when it fires and which keys it carries. A measurement plan is the natural home for it. Keep names lower case with underscores, and match GA4’s recommended event names where one exists.

Test with Tag Manager’s preview mode. Every push appears in the left-hand list, and you can open each one to see its keys and which tags fired. If a push is there and a tag did not fire, the trigger is wrong; if the push is missing, the site code is.

Specifying and testing the data layer is part of setting up tracking in my performance marketing work, because paid campaigns are only as good as the events they optimise towards.

Do and do not

Do

  • Write an event specification before the developer starts
  • Use lower-case names with underscores, matching GA4 recommended events
  • Clear the ecommerce object before each ecommerce push

Do not

  • Reassign dataLayer to an empty list after Tag Manager loads
  • Push names, emails or phone numbers for analytics
  • Fire a success event before the server confirms success

Questions people ask about this

Do I need a developer to use dataLayer.push?

Usually, yes, because the push has to be added to the website's own code at the moment something happens. Many shop platforms and form plugins already push events for you, so check what exists before asking for new work. Your part is to specify the event names and details you need, then test them in Tag Manager's preview mode.

What is the difference between dataLayer.push and gtag?

gtag sends data straight to Google products such as GA4 and Google Ads. dataLayer.push hands information to Google Tag Manager, which then decides what to send and where. If you manage tags in Tag Manager, dataLayer.push is the cleaner route, because one push can feed GA4, Google Ads and Meta tags at once.

Can I push an email address to the data layer for enhanced conversions?

Enhanced conversions do use hashed customer data, but that data should be handled specifically for that purpose and only with the right consent and privacy notice in place. Do not push email addresses or phone numbers into the data layer for general analytics. Anything in the data layer is readable by every tag on the page.

Related terms

Found this useful?

Share it, or ask an AI to summarise it

Back to the glossary

Knowing the term is the easy part

Applying it to your own site and budget is the work. Book a call and I will tell you what actually applies to you.