0

When I use the Google Analytics 4 script through Google Tag Manager it sets both the original analytics scripts and the gtag script. Like so:

<script type="text/javascript" async="" src="https://www.google-analytics.com/analytics.js"></script
<script type="text/javascript" async="" src="https://www.googletagmanager.com/gtag/js?id=MY_ID"></script>

Why is the analytics.js included and not just the gtag/js like Google suggests if I get the code snippet through GA?

1 Answer 1

1

Tags in Google Tag Manager are elements that simplify the configuration of scripts and which essentially translate into code. The Google Analytics Universal Tag translates into analytics.js library snippet, GA4 tag in gtag.js library snippet. This is whether they are used individually or together as they are distinct tags.

The documentation for inserting scripts in page shows how to do it in an optimized way only gtag.js but this does not mean that GTM output is wrong because also the Universal Analytics code can be inserted alone or with the analytics.js library or with that gtag.js (regardless of whether GA4 is present or not).

These are just two different ways of inserting scripts. Surely yours is an interesting question, however it is more a curiosity than an anomaly.

Not the answer you're looking for? Browse other questions tagged or ask your own question.