Google Tag Manager loading and installing more than once

colsen1991
8
colsen1991
commented a year ago

Reproduction link

https://www.skogfrua.no/

Steps to reproduce

Install Tag Assistant (TA) and visit the reproduction link (it's a live site in Norwegian, but it shouldn't matter for testing). Use TA to view status of containers being loaded. Navigate on the site and watch the number of installations go up, and TA giving a warning of multiple installations being detected. Every other or so page navigations, as well as reloading the site, bumps this number.

single after page load.jpg
multiple after navigating.jpg

What is expected ?

Google Tag Manager should only be loaded and installed once on page load(?), then run as normal on page navigations.

(?)*) This is my first time using GTA, not too sure about the specifics here. But seeing as the site uses nuxt generate, which loads the first proper HTML file, then runs as an SPA, correct?

What is actually happening?

GTM is fetched twice and the is installed several times over on page navigation and page reloads.

Additional comments?

An unrelated(?) issue is network tab showing GTM js being loaded after on page load and first on the first page navigation, but then nothing. Is this intentional and could it be related? However on consecutive page loads after page navigation number 1, it doesn't fetch it any more, but the number of installations keep going up.

My modules config:

[
    '@nuxtjs/pwa',
    '@nuxtjs/sitemap',
    [
      '@nuxtjs/google-analytics',
      {
        ua: 'UA-107229265-6',
        disabled: isDev || isStaging
      }
    ],
    [
      '@nuxtjs/google-tag-manager',
      {
        id: 'GTM-KSHV228',
        disabled: isDev || isStaging
      }
    ],
    [
      'nuxt-facebook-pixel-module',
      {
        pixelId: '327112147918767',
        disabled: isDev || isStaging
      }
    ]
  ]

Using nuxt generate for publishing and nuxt-link for internal navigation.

Side note: adding the generated script tag from Google to app.html head seems to work as expected (tested locally). Of course this would not give me the opportunity to track page views without custom code, but since I'm using GA module, which works fine for page view tracking, is this a good alternative/temp fix?

It should be mentioned that this is my first time ever installing GTM, so I'm not sure what consequences this might have for the site? I did test pageview, link click and history change tag triggers, and all working fine and only firing once.

Any input, insight etc. is greatly appreciated! Cheers!

bug
1
tronstoner
0
tronstoner
commented a year ago

@colsen1991 did you ever find a solution for your problem?

0
colsen1991
8
colsen1991
commented a year ago

@tronstoner I'm afraid not. The project fell away due to its own reasons, and I haven't had the need or time to look into it since. Hoping I get to some day.

0
tronstoner
0
tronstoner
commented a year ago

Ok, thanks anyway. I will probably investigate further…

0
colsen1991
8
colsen1991
commented a year ago

@tronstoner Cheers! Let me know if you find something, and I'll do the same once I get some spare time.

0
willi-dev
0
willi-dev
commented a year ago

i also have this problem, with nuxt universal..
google tag manager loaded twice when i change page / route…

0
ladislavsulc
0
ladislavsulc
commented a year ago

Hi, same here with Nuxt Universal/PWA: https://timework.netlify.com/ :(

Settings:

[
      '@nuxtjs/google-tag-manager',
      {
        id: 'GTM-N7CPSGZ',
        pageTracking: false,
        dev: true // set to false to disable in dev mode
      }
],

Verified by Tag Assistant extension. When changing routes, also fires again and again.

0
thejmill
0
thejmill
commented 9 months ago

We are also seeing this issue.

0
VinuRaj
0
VinuRaj
commented 9 months ago

Any solution to this issue?
We're also facing the same issue (multiple tag manager firing while going through routes) on the latest nuxt deployment.

0
arthurkarganyan
0
arthurkarganyan
commented 9 months ago

Solved by including tag manager manually into nuxtServerInit with

      if (!app.head.script.find(i => i.src && i.src.includes('www.googletagmanager.com'))) {
        app.head.script.push({
          src: `//www.googletagmanager.com/gtm.js?id=${gtmKey}&l=dataLayer`,
          async: true
        });
      }
0
admench
0
admench
commented 8 months ago

Solved by including tag manager manually into nuxtServerInit with

      if (!app.head.script.find(i => i.src && i.src.includes('www.googletagmanager.com'))) {
        app.head.script.push({
          src: `//www.googletagmanager.com/gtm.js?id=${gtmKey}&l=dataLayer`,
          async: true
        });
      }

@arthurkarganyan Does this solution entirely remove the need for the module? I.e. are you manually firing events using the normal google tag manager code rather than the nuxt integration?

0
machacek-iw
0
machacek-iw
commented 7 months ago

If you are loading gtm.js file only once then should not be a problem:
https://www.analyticsmania.com/post/multiple-installations-of-google-tag-manager-detected/

0
Informations
Bug ReportOpen
#c149 - Created a year ago