I'm making better performance and load time our online shop, and we use Google Tag Manager on it. But the script that includes google tag manager also loads Google Analytics (legacy ga.js
) and Universal Google Analytics (analytics.js
) by default. I don't need both of them, but if it's necessary I only need Universal Google Analytics.
So why is google tag manager including both scripts?
As a coding resume, this is the tag manager inclusion:
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXX');</script>
-
On network tab, it appears the inclusion and after it, it loads automatically both scripts:
-
If I analyze the Google Tag Manager script (gtm.js
) I see the following:
else if (!a) {
var N = c["60"] ? ".google-analytics.com/u/ga_debug.js" : ".google-analytics.com/ga.js";
a = !0;
u(x("https://ssl", "http://www", N, r), O, c["66"])
}
And this:
if (!a) {
var M = b["60"] ? "u/analytics_debug.js" : "analytics.js";
b[""] && !b["60"] && (M = "internal/" + M);
a = !0;
bb(x("https:", "http:", "//www.google-analytics.com/" + M, d && d.forceSSL), function() {
var a = $a();
a && a.loaded ||
b["66"]();
}, b["66"])
}
-
So google tag manager is including both scripts. I can assume Universal Google Analytics, but legacy ga.js
script why??
Can I avoid the inclusion of both or only legacy ga.js
scripts?
Thank you.
I started a bounty because I need an explanation of why this happens, and if it's possible a way to avoid this behavior.
If your Universal Analytics property is implemented with gtag. js, you can dual tag for your Google Analytics 4 property in one of the following ways: Use the GA4 Setup Assistant and select the option to "Enable data collection using your existing tags" (This option uses a feature called connected site tags)
Google Analytics allows querying of the data, whereas Google Tag Manager does not. In Google Analytics, you can query the data either via the reporting interface or via the API. However, you cannot query the data via GTM.
Universal Analytics hit types include page hits, event hits, ecommerce hits, and social interaction hits. In contrast, Google Analytics 4 data is event-based, with the principle that any interaction can be captured as an event.
Essentially, Google Tag Manager is just the middleman between the implementation on your website and the tracking tool (Google Analytics), where the data gets sent. I would recommend using both tools because they're both free and they can help your business in different ways.
GTM automatically loaded neither of these scripts.
The tags you have defined in your published container load the relevant script to fire if a previous tag firing hasn't loaded it.
For example, the first Tag loads classic GA only if it is fired, while the last Tag loads UA when it fires and is fired at every page load:
You can determine which of your Tags actually fire by putting your client into preview's debug mode, and if a script is still puzzling you can export your container and look through its definitions (or custom JS) to find the tags that relate to scripts:
"tagId": "7",
"name": "classic track event",
"type": "ga",
"tagId": "1",
"name": "page track",
"type": "ua",
As far as i tested my best hypothesis is that it ll only load ga.js
if your container needs it.
The only case i was able tu find is when you use a "Google Analytics classic" Tag (Which are the oldest version) instead of the "Universal Analytics" tag.
I've also tried creating and using dataLayer variables v1 but it doesn't seems to need ga.js
for this.
If you can find more cases please share them since this is actually pretty interesting and even when GTM has almost no effect on site performance it's something to have in mind.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With