March 25, 2021
Window Loaded Trigger in Google Tag Manager: Quick Guide
When a page loads (and you have enabled GTM preview and debug mode), you will see 3 standard events: Page view, DOM Ready and Window Loaded (if you see just 2, this is bad, and you should read this guide to fix the issue).
What do they mean? In this blog post, I’ll quickly explain what Window Loaded event is and why you should care about it.
I’ll do that in the shape of FAQ (frequently asked questions).
What is Window Loaded trigger in GTM?
Window Loaded event appears in the preview mode (and in Data Layer) when the page has fully loaded, including any embedded resources (like images and scripts). In other words, it fires when not only the website content is ready but also when things like 3rd party scripts are loaded as well.
You can find this trigger by going to Triggers (in GTM interface) > New > Trigger Configuration > Window Loaded. If you want to use that one any page, leave all other settings as they are and save the trigger.
If you want to use this trigger only on certain pages, you can choose Some Window Loaded Events and then enter the condition, e.g. Page Path contains /product/ (this is obviously just an example, you’ll need to come up with a condition that fits your needs).
When should I use the Window Loaded trigger?
There are many cases, for example, when you want to track a chat widget on a site, and that widget’s script is loaded quite late. First, you need to make sure that the widget has loaded and only then start tracking it. Window Loaded might be a good option for that: you can fire a Custom HTML tag (the listener for that chat widget) only when the Window Loaded event has fired (meaning that 3rd party scripts are also loaded).
In other cases, I’d use this trigger when I need to fire a tag that does not require 100% precision and does not need to start measuring as soon as the visitor lands on a page. Retargeting scripts (which will eventually die due to privacy enhancements in the market) are good examples. I don’t need to fire that script as soon as the page starts loading (a.k.a. Pageview trigger). It’s totally fine to fire the script later on Window Loaded (or even MUCH later — just to be sure that a visitor had at least a theoretical chance to view my site’s content).
Or, most importantly, if you want to reduce the implications on page loading speed.
Does Window Loaded improve my page loading speed?
As I have mentioned in my research on how Google Tag Manager affects page loading speed, scripts that are added to a page will always have some negative impact.
However, with GTM, you can manage the timing when the tag fires. According to my findings, the later a tag is fired, the lesser impact it does on page loading speed.
If you move all your tags from Pageview to Window Loaded, there will be some improvement (although not as huge as you might expect).
P.S. if you are looking for a much more significant improvement in page speed (however, this will greatly delay the moment when you tag fires), read this chapter of my page speed research. Also, feel free to check this.
Will I lose data if I delay a tag to fire on Window Loaded?
Yes (but to some extent). The more you delay the tag in GTM, the higher the chances of missing data. Why? Because if your page loads super slowly, some visitors will not wait for the entire page to load and will leave. In that case, the tag that fires on Window Loaded will not have a chance to fire.
That is why I said in the first half of this blog post that usually, Window Loaded is used to fire tags that do not require 100% precision.
- For example, some retargeting scripts can easily be delayed to Window Loaded if I plan to retarget visitors who have had a least a short glimpse of my site. If they leave the site before it even manages to load, what’s the point of retargeting them? Although, in reality, I’d delay that tag even more.
- GA Pageview tag, on the other hand, requires precision because I want to know how many people/devices visited my site, and I expect that number to be as precise as possible. That’s why I’d fire the GA pageview tag on a Page View event.
So what is the potential data loss if we compare a tag that fires on Pageview vs Window Loaded?
I did an experiment in the past and set a GA3 tag to fire on 3 different triggers:
- Page view
- DOM Ready
- Window Loaded
All events were set as non-interaction hits. After a while, these were the total event numbers from the GA reports:
As you can see in the report, there is a slight decrease in every step/delay. However, don’t use my example blindly. If your website is super heavy and Window Loaded fires after only 15 seconds (or even more), your drop-off might be much more significant.
You should definitely not overlook this trigger. If you are aware of how various scripts affect the page loading speed, you should definitely delay some of your tags at least to Window Loaded.
Also, if you plan to track certain website elements that are loaded with a certain delay, Window Loaded trigger might be a solution for that too. If you have a certain listener (implemented via Custom HTML tag), firing it on Window Loaded will greatly increase the chances of having more accurate tracking data.
Got questions? Post them below.