Comments (16)
Hi,
I created a repository where this issue is reproduced. The issue is happening in the most basic nuxt-app possible, so it seems like it affects all users.
The repository can be found here: https://github.com/stephanvane/reproduction-issue-14
Using the official Google Analytics Debugger, you can see that on the initial page-load, the page is tracked twice, it tracks the correct page and the root path (even when you're on an other page http://localhost:3000/page1).
When navigating between pages, it's working as intended (tracking only once per click).
here are the steps used to create this repository.
- Create a new nuxt project
$ vue init nuxt-community/starter-template foo
$ yarn add @nuxtjs/google-analytics
- Add the module to
nuxt.config.js
:
modules: [
// Simple usage
['@nuxtjs/google-analytics', {
id: 'UA-12301-2'
}]
],
-
Add another page, so there can be navigation between them.
-
(optional) Add
mode: 'spa'
to see that the issue is also there when SSR is disabled
mode: 'spa'
from google-analytics-module.
hi @stephanvane thanks a lot for the effort, I will have a look as soon as possible
from google-analytics-module.
Setting pageviewOnLoad: false
prevents a double page hit on a SSR load. With this on by default GA is logging double pageviews on the first site hit...this will screw all your analytics. This is very dangerous as you can't ever change this.
from google-analytics-module.
Do you issue manual tracking in any created
or beforeCreated
hook?
from google-analytics-module.
No I did not do any manual tracking.
Everything I did is add this to nuxt.config.js
modules: [
'@nuxtjs/google-analytics'
],
'google-analytics': {
id: 'UA-38944667-7'
},
I found that it send page view for /
every route I go
The solution that work for me right now is adding this to the nuxt.config.js
'google-analytics': {
id: 'UA-38944667-7',
autoTracking: {
pageviewOnLoad: false
}
}
from google-analytics-module.
@kieusonlam the default behavior of the plugin within the nuxt module is to automatically track your routes by default.
If you don't want this to happen at all, you can turn that off and do it manually.
here the link to the documentation https://github.com/MatteoGabriele/vue-analytics/blob/master/docs/page-tracking.md#disable-page-auto-tracking
from google-analytics-module.
Thanks @MatteoGabriele for the suggestion I happy with pageviewOnLoad: false
solution. I think this module should set it to false by default.
from google-analytics-module.
I disagree :)
Sending the first hit of the currently loaded page it's normal and even suggested in the Google Analytics developer documentation.
There are too many different use cases, someone wants it on page load, someone doesn't.
from google-analytics-module.
@failpunk I don't understand why there would be a double page hit on a SSR load.
The server will not load the Google Analytics code on server-side according to this code line:
https://github.com/nuxt-community/analytics-module/blob/master/lib/module.js#L16
from google-analytics-module.
We were using vue-analytics with alibaba.ir and i can confirm this bug was happening. (Double page hits on initial load) So we forced to temporary switching to original GA.
I think the reason is that router.afterEach
will be called on initial load and also vue-analytics sends a page hit on init by default.
/cc @MatteoGabriele
from google-analytics-module.
@pi0 I'm sorry but I've created a new nuxtjs project, added the plugin, the domain ID and started refreshing and going around without having this issue
without a reproduction, I can't do that much
from google-analytics-module.
I wound up just creating and using my own simple plugin because of the issue in #8.
from google-analytics-module.
@MatteoGabriele The problem is not here?
https://github.com/MatteoGabriele/vue-analytics/blob/master/src/lib/page.js#L30
set('page', page)
query('send', 'pageview', ...args)
Set and send the same page, that is, tracked twice
from google-analytics-module.
@ricardogobbosouza set
prepares the event not sending it.
from google-analytics-module.
The only thing I saw is that it executes these two commands
Running command: ga("set", "page", "/")
Running command: ga("send", "pageview", "/")
But I think that's okay. For me it works in both spa and universal mode.
from google-analytics-module.
As it's been some time, I think this has been solved.
@MatteoGabriele I think we can close this
from google-analytics-module.
Related Issues (20)
- Disable Google Analytics for 404 pages generated by error.vue of layout component HOT 1
- Pageviews / Landing Pages are "not set"
- Custom Dimension for Pageview
- docs error?
- asyncID with multiple id does not seem to work HOT 2
- Google Ads says that my Google Analytics account is misconfigured and is underreporting visitors
- Content Security Policy
- Dependency Dashboard
- Any plans to support GA4? HOT 12
- $ga is missing from router middleware`s context HOT 3
- docs(setup): add typescript instructions HOT 1
- Multiple Google Analytic ID's
- Add support for nuxt 3 HOT 22
- Passing uid with event tracking
- Anonimize IP HOT 1
- Universal Analytics will no longer process new data in standard properties beginning 1 July 2023 HOT 3
- Measurement ID instead of Tracking ID
- Nuxt 3 GA4 timeline? HOT 11
- CORS issue
- Nuxt 3 Support HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from google-analytics-module.