2

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!

kregus
  • 1,003
  • 10
  • 18

3 Answers3

3

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.

jsd
  • 31
  • 2
  • There are also two different GTM ids (K5XJCW in the first call, W9SLVSL in the second). Maybe some extension or 3rd party widget is loading it's own GTM instance. – Eike Pierstorff Dec 09 '19 at 09:13
  • My own GTM ID is `K5XJCW`, no idea where the other one comes from. Can't find a reference anywhere in the code, and the `Initiator` is `VM142`, which apparently "*has no special meaning. It's a dummy name to help us to distinguish code which are not directly tied to a file name, such as code created using `eval` and friends.*" according to [this answer](https://stackoverflow.com/a/17373477/1800213). So no clear lead, but will keep digging. – kregus Dec 09 '19 at 15:04
0

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).

Eike Pierstorff
  • 31,996
  • 4
  • 43
  • 62
0

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.

kregus
  • 1,003
  • 10
  • 18
  • I'm experiencing a similar issue: implementation is done using the Google guide (https://support.google.com/optimize/answer/6314801?hl=en). This setup requires the Google Optimize (GO) tag to be loaded *before* the Google Analytics (GA) tags (via tag seq), thus implying the GA tag will be loaded *after* the GO tag. Hence the GO has no triggers, I'm guessing. But, looking at the chain in Network tab for Devtools, I can see the GO JS as a child link from the GA JS.. I'm so lost.. Is this actually default for this behaviour; does anybody know? – ravb79 Mar 27 '20 at 13:07