kregus
kregus

Reputation: 1108

Google Tag Manager loads Analytics.js multiple times

When I check my page source, I see multiple instances of analytics.js within my Google Tag Manager code block, see:

enter image description here

Similar results in my network tab:

enter image description here

This is how I implemented GTM in my Joomla template code (a copy/paste from the GTM backend):

<!-- Google Tag Manager -->
<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-K5XJCWX');</script>
<!-- End Google Tag Manager -->

Can anyone tell me what is going on here, and how I can stop analytics.js from being loaded multiple times?

Thanks so much!

Upvotes: 2

Views: 2401

Answers (3)

kregus
kregus

Reputation: 1108

When I commented the Tag Manager code block, analytics.js did not load at all, so it had to be a GTM tag that was causing this.

When I looked, I saw one tag for Google Optimize, and after checking, it turns out that the container ID of Google Optimize is GTM-W9SLVSL.

enter image description here

Still hoping to find a way to not load analytics.js multiple times, while still using Google Optimize.

Upvotes: 0

Eike Pierstorff
Eike Pierstorff

Reputation: 32760

You have two different GTM instances. In your first screenshot, one is loaded in the third line from the top (GTM-W9SLVSl), the other one in the third line from the bottom (GTM-W9SLVSL).

I assume that both instances have a Google Analytics tag configured.

If you did not do this deliberately, then quite probably some third party extension loads their own instance. Developers of extensions sometimes do this to track how their extension is used (the legality of that is debatable).

Upvotes: 0

jsd
jsd

Reputation: 31

Check out the 'Initiator' tab in "Network" tab screenshot as it looks like analytics.js is being called from a couple different places. i.e. - gtm.js?id... and js?id....

You should be able to click each initiator row and see exactly where it's being called from.

Upvotes: 3

Related Questions