-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warning: New Google Analytics 4 properties break the expected behavior of this plugin and cause double page views. #406
Comments
Any news? |
Bump.. Any update on this bug? |
Is v1 of vue-gtag compatible with GA4? I'm still using Vue2 and would like to use this with the new Google Analytics 4. |
Is this still an issue? Is vue-gtag compatible with Google Analytics 4? |
Thanks, @miketromba, for your feedback, and sorry for responding to you so late. I will try to look into this, but if any of you know a solution already, don't hesitate to drop it here, and maybe we can fix it and fix it sooner. |
I am assuming you are using vue-gtag v2 |
I have based my implementation on google's documentation https://developers.google.com/analytics/devguides/collection/gtagjs/pages there's no specification of being GA4 compatible or not |
I might have found the cause on this line. https://github.com/MatteoGabriele/vue-gtag/blob/master/src/api/pageview.js#L38-L40 |
@MatteoGabriele would love to test but would need the patch for the legacy version using Vue 2. |
Here's a small plugin that provides basic tracking functions of gtag.js with GA4 properties- without needing any 3rd party libraries. The heavy lifting is done by GA4's default auto-tracking behavior. It works well on my end, but I suggest you test to make sure it works well in your own project. Note: if you're not using nuxt, the plugin logic is the same, just adjust the code to work in your vue environment. Nuxt 3 GA4 plugin
|
Am using the Vue 2 version and it does seem to work with GA4 as well so not having a lot of issues. Thanks for sharing @miketromba . Perhaps @MatteoGabriele can put it to use. |
miketromba for nuxt 3 code dosesn't work at all and has a lot of console warnings related with |
@nomtek-sgolus That might be because it's trying to run on the server side (if you're using SSR) - I have my file named |
Got it, and yep - it works now 👍 |
Does this allow the use of |
@notflip The $gtag property is just a normal gtag.js object, so you can see all of the possibilities in Google's official docs: Gtag.js - https://developers.google.com/tag-platform/gtagjs |
Yes, it's fixed the double pageview issue. Can you add it to the v1 as well, please? |
What code are you using to implement vue-gtag? Thanks! Will test with you |
Description
First of all, thank you for all your hard work on this plugin Matteo! I really appreciate it.
When creating new Google Analytics properties, they now default to Google Analytics version 4 (GA4). The problem is: the default behavior of GA4 properties is incompatible with this plugin right now, and causes unwanted and unexpected behavior.
I spent a lot of time this morning pulling my hair out trying to understand why random page view events were being sent even without auto-tracking enabled... I learned that it is caused by the default behavior of new GA4 properties.
By default, when gtag.js is installed, GA4 properties automatically send page view events on page loads and even page changes based on browser history events, as shown with this data stream setting:
This totally clashes with the behavior of this plugin, causing there to be lots of double page views, and is very confusing to those who miss this! (I assume many developers will fall into this trap)
Suggestion
I do not have a specific suggestion right now on how to make this library GA4-compatable, but I highly recommend temporarily updating the documentation in the meantime to include a big warning that the plugin is not ready for GA4 and will cause duplicate page views.
I think this will save developers a lot of time!
The text was updated successfully, but these errors were encountered: