nuxt-community / firebase-module

🔥 Easily integrate Firebase into your Nuxt project. 🔥
https://firebase.nuxtjs.org
MIT License
640 stars 98 forks source link

[Analytics] Google Tag Manager script is included twice when analytics is true #254

Closed patrickxchong closed 4 years ago

patrickxchong commented 4 years ago

Version

@nuxtjs/firebase: 6.0.1 firebase: 7.15.5 nuxt: 2.13.2

Reproduction Link

https://nuxt-fire-demo.herokuapp.com/

Steps to reproduce

Open the demo app at https://nuxt-fire-demo.herokuapp.com/ and check the html there. One can see both <script type="text/javascript" async="" src="https://www.googletagmanager.com/gtag/js?id=G-XT6PVC1D4X&amp;l=dataLayer&amp;cx=c"></script> and <script src="https://www.googletagmanager.com/gtag/js?l=dataLayer" async=""></script>

Alternatively, download the Google Analytics Debugger to see that googletagmanager is initialized twice.

What is Expected?

Only the second script tag should be present. (based on https://firebase.google.com/docs/analytics/get-started)

What is actually happening?

Google Tag Manager is downloaded twice, which wastes bandwidth and also causes the the initial page_view event to be loaded twice when page_view events are sent via a middleware in Vue router. (will be happy to make a repo to reproduce it if necessary).

The double page_view events are fired shortly between each other and are recorded as two separate events in Firebase Analytics as shown below. image

lupas commented 4 years ago

Hey @patrickxchong

Thanks a lot for the nicely described issue, and please excuse the rather late response. I can see that it indeed adds two script tags, but that is also the case in a simple Vue Firebase app, see Sandbox, and I assume in all other Firebase SDK Web Apps, too.

So I think this is either expected behaviour or an issue in the Firebase JS SDK.

I myself couldn't reproduce two separate events getting triggered, could you check if that is always the case for you and if so, provide a sandbox for it?

PS: This module does not much more than initializing analytics with firebase.analytics(), so am leaning towards the fact that this issue is not necessarily nuxt/firebase related. But I could be wrong.

patrickxchong commented 4 years ago

Thank you for looking into this @lupas. I agree with your analysis. I'm sorry that I didn't check whether it's something related to the Firebase JS SDK first. This has went down in my priority list but I'll look into this again on the firebase side in a few weeks. Closing this issue for now.