
August 13, 2021
Missing DOM Ready and Window Loaded events in GTM?
This will be a very quick guide, and it’s based on one of the recent posts in the GTM community on Facebook.
One of the members faced a situation where DOM ready (a.k.a. gtm.dom) and Window Loaded (a.k.a. gtm.load) were missing in the Data Layer although the Container Loaded event (gtm.js) worked just fine.
Simo Ahava’s eagle eyes spotted a weird thing that was implemented on a site. For some reason, an empty array was being pushed to the Data Layer like this (which is not a valid command for GTM):
If you want to push data to the Data Layer, it must be an object or a command array. And an empty array is neither of those.
So what must be done? You have to cooperate with a developer and ask him/her to remove the dataLayer.push that adds an empty array. Or disable a plugin that is doing so (if you are working with a popular website builder/ecommerce platform.
Unfortunately, there is no universal “go here, click this” answer. Websites are different and most of their codebase is different. So you should probably cooperate/consult with a person/company that is responsible for building that website.
Still missing DOM Ready and Window Loaded events?
If this tip did not help you, leave a comment below, and we’ll try to find a solution + update the guide. And if this indeed worked well, consider subscribing to my newsletter by getting one of these ebooks.

3 COMMENTS
This tip is exactly what I was looking for but did not seem to work on my current site. I was unable to find an empty array. Just wondering if you can see the issue. Also, there is additional coding for //CDATA within the Google Analytics script. I prefer to run GA through GTM but I inherited the site with this set up. Would you recommend removing the GA script or at a minimum the //CDATA? Thank you for all your help, Derek
If you import the script with a dynamic import, the CSP will prevent the preview mode from working, but the browser will not warn you in the console.
Sorry this was for another article: https://www.analyticsmania.com/post/google-tag-manager-preview-mode-not-working/#comment-30583