Why gtag.js is loading 2 scripts instead of 1?

Viewed 157

When I install my gtag.js code in <head> I'm surprised that I have two scripts loaded. I don't understand why. One is from analytics and the other from googletagmanager: Scripts loaded

I cant find any info about that. Anybody knows why this happens?

2 Answers

Gtag.js is Google's "global" tag, a sort of scaled down tag manager that only serves Google scripts (and uses the same infrastructure as the tag manager proper, hence googletamanager.com as origin domain).

So gtag is the delivery and configuration mechanism, but to do any actual work, the assets for Google Analytics (Google Ads etc, whatever Google script you chose to implement via gtag.js) still have to be loaded.

The tag manager is a general utility used to load different resources for Google stuff. There are dozens of different resources, including adwords, surveys, A/B testing stuff, analytics, etc (see your tag manager dashboard). In your case, you are only using analytics, so the tag manager only loads the analytics code.

Furthermore, each asset is only loaded when a certain "trigger" happens. In most cases, the trigger for analytics is "Page Load", which is why you are seeing the two requests happen pretty much right next to each other. You could update the trigger to be something like a form submission, youtube video watch, etc... and you would only see the resource loaded when that trigger happens.

Related