Limited-time sale on all Analytics Mania's courses!

Learn more
  • Courses
    • 🔥 SALE 🔥
    • Courses
    • Course bundles
  • Blog
  • Resources
    • Youtube channel
    • E-books and Guides
    • GTM Recipes
    • View All Resources
    • GTM Community
    • GA4 community
  • Services
  • About
    • About
    • Contact
  • Login
  • Courses
    • 🔥 SALE 🔥
    • Courses
    • Course bundles
  • Blog
  • Resources
    • Youtube channel
    • E-books and Guides
    • GTM Recipes
    • View All Resources
    • GTM Community
    • GA4 community
  • Services
  • About
    • About
    • Contact
  • Login

July 21, 2025

dataLayer.push not working? Here are some reasons and solutions

The data layer is a key component within Google Tag Manager for collecting and managing website data. The dataLayer.push method is the standard way to send information into this layer, making it available for you or your developers to interact with it.

However, is dataLayer.push not working on your end? This article will explore the common reasons why your dataLayer.push might not be working and provide some potential solutions. Let’s get into it!

 

Table of Contents

Here’s what you will learn in this article

  • The code has a typo
  • Renamed the data layer
  • The code on your site is overriding the data layer
  • Timing
  • iFrame
  • Other data layer resources
  • Final Words

 

 

The code has a typo

To begin debugging your data layer, enable Google Tag Manager’s preview mode. An easy way is to go to your GTM container and select “Preview” in the top-right.

Once enabled, open your browser’s developer tools by right-clicking on the page and selecting “Inspect,” then navigate to the Console tab.

In the console, you can test the dataLayer.push() functionality by typing: dataLayer.push({‘event’: ‘test’})

In the console, it does not matter whether you see “true” or “false” in this case. In Tag Assistant, you’ll see this event appear as an event.

This is the expected behaviour, but we want to understand what would cause unexpected behaviour. A very common reason is that, simply, you have a typo in your code. Some errors to look out for include:

  • Case Sensitivity: The code is case-sensitive, so you must ensure that you use the correct case, which is all lowercase, except for the “L”, e.g., “dataLayer”. If your code uses datalayer.push, it won’t work.
  • Missing curly brackets: You need to make sure your event information is all contained within the curly brackets and that you open and close them correctly, e.g., {‘event’: ‘test’}. You can review Google’s documentation on the syntax for sending an event through the data layer here.

The solution here? Double-check your dataLayer.push event. Have someone review it for you or run it through an AI tool like Gemini or ChatGPT to see if it picks up on any issues.

 

Renamed the data layer

Another possibility is that whoever installed GTM on your site may have renamed the data layer, possibly to maintain consistent naming conventions or avoid conflicts with existing JavaScript.

To find out if someone renamed the data layer when they installed GTM, head over to your GTM container. Click on your container ID, and you’ll see the GTM snippet that should be on every page of your site.

Inside that snippet, you’ll usually spot “datalayer” somewhere. But at any point during the GTM/GA4 setup, someone may have given this a different name.

To double-check, right-click on your site and select “View page source.”

Then, search for “gtm.js” to find the GTM code snippet. Check if you see “datalayer” or if it has been renamed. In this example, let’s say someone has renamed the customDataLayer.

If it has been renamed, your usual datalayer.push won’t work. You can test this in the Console tab of developer tools (right-click on your page > Inspect) by typing dataLayer.push({‘event’: ‘test’}) in the console. Go back to preview mode, and you’ll notice that we don’t see the event.

However, if you type customDataLayer.push({‘event’: ‘test’}) in the console (assuming it was renamed to customDataLayer), then return to preview mode, you will see the event.

So, your two options here are:

  1. Rename the data layer in the GTM code snippet back to just “dataLayer.”
  2. Or update all your data layer push events to use the custom data layer name.

 

The code on your site is overriding the data layer

If none of the reasons above seem to be the cause of your problems, some custom code on your website could be overriding the data layer. This can happen when the Google Tag Manager (GTM) container snippet loads and initializes the data layer correctly, but then some other code on your site also attempts to set the data layer. When this occurs, it can override GTM’s functionality, potentially setting the data layer as an empty array and causing problems with your tracking.

To explore this further, you can simply right-click on your site and choose “View page source.”

Then, search for “dataLayer =” (click control-F to open the search box). If you see window.dataLayer = [] anywhere (or something similar), you’ve found your issue! This code directly replaces the existing data layer with an empty array, which is definitely not what you want.

A better approach is to update this code to window.dataLayer = window.dataLayer || []. In simple terms, this tells the code to check if a dataLayer container already exists on the page. If it does, the code will use it. However, if the dataLayer isn’t there yet, this line of code will create a brand-new, empty dataLayer array.

This makes sure that whenever you attempt to add information to the dataLayer later using dataLayer.push(), there will always be a valid container for that data, preventing errors that might occur if the container didn’t exist.

Subscribe and Get the Ebook - Server-side tagging

Timing

Your code might be facing the challenge of being in the wrong place at the wrong time. When a dataLayer.push code is placed before the GTM container snippet, it can lead to problems because you’re attempting to send information to the data layer before it has actually been created.

To figure out if this is the issue you’re having, open the developer tools. You can do this by right-clicking on the page and selecting “Inspect,” then navigating to the “Console” tab.

Right away, will see any error that says “dataLayer is not defined.” This error indicates that some code tried to push data to the data layer, but the data layer object wasn’t available at that time.

You have two solutions to resolve this problem:

  • Solution 1: The most straightforward solution is to talk to the developers to relocate the data layer event code below the GTM container snippet. This makes sure that the data layer is properly initialized before any information is pushed to it.
  • Solution 2: If you need the dataLayer.push event to be activated as soon as possible, you need developers to add an additional line of code before your dataLayer.push event(s):
window.dataLayer = window.dataLayer || [];
dataLayer.push({'event': 'test'});

This code snippet says: “If a data layer already exists, use it. If not, create an empty data layer” (like the solution in the previous chapter). This approach helps to make sure that even if the GTM container hasn’t fully loaded and initialized the data layer, there will be an empty data layer available to receive the pushed event, preventing the “dataLayer is not defined” error.

 

iFrame

If your website has a parent page that embeds an iframe (think of it as a website within a website), and you’re using dataLayer.push events inside that iframe, but you’ve only installed Google Tag Manager (GTM) on the parent page, then GTM on the parent page won’t be able to access those data layer pushes.

Not sure if you’re dealing with an iframe? An easy way to find out is to right-click on the potential iframe (a.k.a. where the action you’re trying to capture with a dataLayer.push event is), and if you see Reload frame as an option, it is an iframe.

To capture the information from dataLayer.push within the iframe, you need to implement additional measures to send communication between the parent page and the iframe. This typically involves using cross-document messaging (also known as postMessage()), which you can read more about here.

You can also learn more about tracking iframes in my Intermediate-Advanced GTM course.

 

Other data layer resources

While these issues can be frustrating, they shouldn’t take away from how much working with the data layer can benefit your analytics. To further deepen your understanding and enhance your troubleshooting skills (for when you encounter issues in the future, because, let’s be real, it’ll happen), check out some of my other articles on working with the data layer:

  • Google Tag Manager Data Layer Tutorial with Examples
  • How to Pull Data from Data Layer: Google Tag Manager Tutorial
  • Data Layer Variable in Google Tag Manager

dataLayer.push not working? Here are some reasons and solutions: Final Words

While many factors can impact data layer functionality, in my experience, the most common culprits are typically a typo in the code or code on your site accidentally overriding the data layer. Addressing these issues will often resolve the vast majority of dataLayer.push problems you encounter.

If you had an issue with a dataLayer.push event that you resolved differently from the ones I’ve listed, share your experience in the comments below!

Subscribe and Get the Ebook - JavaScript for Google Tag Manager
Julius Fedorovicius
In Google Tag Manager Tips
0 COMMENTS

Leave a comment Cancel reply

Your email address will not be published. Required fields are marked *


 

Hi, I'm Julius Fedorovicius and I'm here to help you learn Google Tag Manager and Google Analytics. Join thousands of other digital marketers and digital analysts in this exciting journey. Read more
Analytics Mania
  • Google Tag Manager Courses
  • Google Tag Manager Recipes
  • Google Tag Manager Resources
  • Google Tag Manager Community
  • Login to courses
Follow Analytics Mania
  • Subscribe to newsletter
Recent Posts
  • Top 22 Benefits of Google Analytics 4
  • Track HubSpot Forms with Google Tag Manager and Google Analytics 4
  • dataLayer.push not working? Here are some reasons and solutions
Analytics Mania - Google Tag Manager and Google Analytics Blog | Privacy Policy
Manage Cookie Settings