How to successfully detect and track Optimize anti-flicker snippet timeout using Google Analytics?
I noticed that the dataLayer
variable hide["GTM-XXXXXX"]
is true
when it times out and false
if it doesn't.
The problem is that there is no event tied to this variable change. How would you go about tracking timeouts?
My goal is to send an event to Google Analytics every time the snippet times out.
This is the solution I ended up with. Works perfectly.
1. Create a new Custom Javascript function variable in GTM
function () {
if ( window.dataLayer.hide ) {
return window.dataLayer.hide["GTM-xxxxxxx"]; // Your Optimize container ID
}
}
2. On DOM Ready, check its value
If the value is true
, the snippet has timed out. And when it's false
, it managed to run before your maximum timeout duration.