Quietly, a new feature has been slipped into the Yireo GoogleTagManager2, called Wait for user interaction . Disabled by default. Here is the gist of why should enable it.
Waiting for user interaction
Some things are better copied from others. Since the Yireo GoogleTagManager2 version 3 has been released (with GA4 support), there have been more and more releases with numerous fixes and features. However, on April 22nd 2023, I joined the excellent MageTitans Manchester where John Hughes went through an insane slideset on performance. And one of those slides was about improving GoogleTagManager performance by delaying JavaScript execution.
I implemented this in version 3.4.0 (without a fuzz, well, this blog being the fuzz): When the feature is being enabled, the code waits for user interaction before actually sending events down the rabbit hole. Underneath, the browser events keydown
, mouseover
, scroll
, touchstart
and wheel
allow for detecting the user interaction. Actually, the weirder part is that when the feature is disabled, the load
event is added as well (which fires ... well always).
Why enable it?
Why should you enable this feature? Well, simply because the performance increases. Because the gtm.js
file of Google will only be loaded after user interaction (and only if there actually is a user to interact with things), the user experience goes up. And because the Core Web Vitals are testing for the same thing, the scores go up as well. Which is nice.
Why disable it by default?
However, note that the default is to have the feature disabled. Why? Well, this actually has less to do with the greatness of the feature (which is great and featurish) but more with the fact that there was a time where this feature did not exist and there is a time where this feature did exist. From the moment that you enable the feature, it could be that your statistics are showing a different picture than before. You are dropping robots from analytics, for instance, unless these JS-based robots also do a bit of scrolling. This could be decreasing your overall traffic in GA, while actually in real-life it would remove the fluff.
Already I've fought with Google zealots that were interpreting the documentation of Google in such a way, that it showed off their recital skills more than their understanding of real-life e-commerce. But because a merchant might be stuck in the middle, I'd rather leave it up to the merchant and their SEO experts to decide upon whether or not this feature is a benefit.
Feel free to change my mind on this.
Enable it!
So, the end conclusion is that this feature is way cool and that if you care for performance, you should try to enable it. For fresh shops, it should be enabled. For existing shops, you should enable it and then burn the SEO experts over it. And blame John.
About the author
Jisse Reitsma is the founder of Yireo, extension developer, developer trainer and 3x Magento Master. His passion is for technology and open source. And he loves talking as well.