gtm-module icon indicating copy to clipboard operation
gtm-module copied to clipboard

Duplicate GTM initializing in SPA mode

Open Manfies opened this issue 5 years ago • 8 comments

Hi. If you try to run the nuxt application in SPA mode and open the page, you will get a double GTM submission. You can also see two identical scripts in head. The same thing happens when generating applications in the SPA mode.

Browser Dev Tools - Duplicated GTM scripts

Manfies avatar Feb 09 '20 22:02 Manfies

Thanks for report @Manfies. Trying to investigate more. Created a repro for vue-meta behaviour:

https://github.com/pi0/nuxt-meta-iife-bug

pi0 avatar Feb 10 '20 11:02 pi0

I see that this will block the usage of multiple containers...

reinos avatar Feb 17 '20 15:02 reinos

Hi I actually experienced this problem with @nuxtjs/google-tag-manager (which is now deprecated). I had a default value for specifying my GTM-staging id and an environment value specifying GTM-production. But when I loaded my site with all environment variables intact, I have production and staging GTM running.

I was wondering what is the difference between this repo and @nuxtjs/google-tag-manager. And whether this repo (based on this issue) could have inherited the problem from @nuxtjs/google-tag-manager. Hope you can help.

tintinthong avatar Mar 31 '20 10:03 tintinthong

@tintinthong This is a full rewrite using an injected snippet on the page. Also currently a guard is added to the snippet to prevent adding duplicate you can try it :)

pi0 avatar Mar 31 '20 10:03 pi0

Hi I'm also have the same issue - duplicated GTM https://take.ms/lwueD This happens while I'm revisiting pages. The configuration is the basic as in the docs:

buildModules: [   
  '@nuxtjs/gtm'
],
gtm: {
  id: 'GTM-IDHRERE'
}

package.json

"dependencies": {
  "@nuxtjs/gtm": "^2.3.0"
}

dminchev avatar Jun 11 '20 05:06 dminchev

@dminchev I've having the same behaviour. Tags seem to be accumulating per page. However, if you search for the GTM code in devtools, the code snippet its not repeated.

Could this be a detection bug on the Google Tag Assistant extension itself?

I'm saying this because of the way Nuxt works (where each page you visit is not thrown away - if you disable internet you can still visit the pages you've watched before, etc..), and what I believe to be the expectation of Google Tag Assistant (each page is a single unit).

Also, the data metrics don't seem to be affected.

urbgimtam avatar Jul 08 '20 11:07 urbgimtam

I think I've found it. In default.vue, when using the "keep-alive" attribute on <Nuxt> component, the pages remain on memory, thus triggering the multiple scripts. Removing "keep-alive" removed the extra detections on Google Tag Assistant.

urbgimtam avatar Jul 16 '20 11:07 urbgimtam

Hi I'm also have the same issue - duplicated GTM https://take.ms/lwueD This happens while I'm revisiting pages. The configuration is the basic as in the docs:

buildModules: [   
  '@nuxtjs/gtm'
],
gtm: {
  id: 'GTM-IDHRERE'
}

package.json

"dependencies": {
  "@nuxtjs/gtm": "^2.3.0"
}

Shouldn't we use it as modules and not buildModules? ReadMe suggests so too

alishahlakhani avatar Oct 09 '20 09:10 alishahlakhani