Giter Club home page Giter Club logo

Comments (16)

stephanvane avatar stephanvane commented on May 30, 2024 4

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).

issue

here are the steps used to create this repository.

  1. Create a new nuxt project
$ vue init nuxt-community/starter-template foo

$ yarn add @nuxtjs/google-analytics 
  1. Add the module to nuxt.config.js:
  modules: [
    // Simple usage
    ['@nuxtjs/google-analytics', {
      id: 'UA-12301-2'
    }]
  ],
  1. Add another page, so there can be navigation between them.

  2. (optional) Add mode: 'spa' to see that the issue is also there when SSR is disabled

  mode: 'spa'

from google-analytics-module.

MatteoGabriele avatar MatteoGabriele commented on May 30, 2024 3

hi @stephanvane thanks a lot for the effort, I will have a look as soon as possible

from google-analytics-module.

failpunk avatar failpunk commented on May 30, 2024 1

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.

manniL avatar manniL commented on May 30, 2024

Do you issue manual tracking in any created or beforeCreated hook?

from google-analytics-module.

kieusonlam avatar kieusonlam commented on May 30, 2024

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
image

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.

MatteoGabriele avatar MatteoGabriele commented on May 30, 2024

@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.

kieusonlam avatar kieusonlam commented on May 30, 2024

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.

MatteoGabriele avatar MatteoGabriele commented on May 30, 2024

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.

pschaub avatar pschaub commented on May 30, 2024

@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.

pi0 avatar pi0 commented on May 30, 2024

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.

MatteoGabriele avatar MatteoGabriele commented on May 30, 2024

@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.

failpunk avatar failpunk commented on May 30, 2024

I wound up just creating and using my own simple plugin because of the issue in #8.

from google-analytics-module.

ricardogobbosouza avatar ricardogobbosouza commented on May 30, 2024

@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.

pi0 avatar pi0 commented on May 30, 2024

@ricardogobbosouza set prepares the event not sending it.

from google-analytics-module.

ricardogobbosouza avatar ricardogobbosouza commented on May 30, 2024

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.

ricardogobbosouza avatar ricardogobbosouza commented on May 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.