MatteoGabriele / vue-gtag

Global Site Tag plugin for Vue (gtag.js)
https://matteo-gabriele.gitbook.io/vue-gtag/
MIT License
873 stars 67 forks source link

Disable AutoTracking not working #526

Open totomaze opened 1 year ago

totomaze commented 1 year ago

Please fill in at least the mandatory (*) questions below, or I will immediately close this issue without reading. Thanks

Environment *

Run this command in the project folder and fill in their results:

npm ls vue-gtag: `-- vue-gtag@1.16.1

npm ls vue: +-- vue@2.6.11

Then, specify:

  1. Operating system: windows 10
  2. Browser and version: Chromium 109.0.5414.119

    Description *

What are you reporting? Vue.use(VueGtag, { pageTrackerPrependBase: false, pageTrackerEnabled: false, pageTrackerScreenviewEnabled: false,

config: {
    id: process.env.VUE_APP_ANALYTICS_KEY
}

})

I tried to stop sending a page view after a change of route, but nothing works, It send a page view at each route change I am working with history mode

Expected behavior

Tell us what you think should happen. I was hoping the nothing will be send on a route change

Actual behavior

Tell us what actually happens.

A query is sent to GA on every route change. I am not sure if I am missing something in the config to stop the auto page tracker

Reproducible Demo in case of a bug report

Please take the time to create a new app that reproduces the issue or at least some code example Vue.use(VueGtag, { pageTrackerPrependBase: false, pageTrackerEnabled: false, pageTrackerScreenviewEnabled: false, config: { id: process.env.VUE_APP_ANALYTICS_KEY } })

The router is in history mode

Demonstrable issues gets fixed faster.

ArthurOnly commented 5 months ago

I faced the same problem today and solved this way:

The problem

I noticed that when i reload my page with

app.use(VueGtag, {
  pageTrackerEnabled: false,
  config: { 
    id: 'xxx',
    params: {
      send_page_view: false,
    },
  },
});

The page view events continued to be sent. I removed the Gtag config from this lib and directly used the default gtag config in my index.html that load the SPA. Even with this, events continued to be sent.

Solution

The solution I found is to change an analytics configuration (datastream) like mentioned here https://support.google.com/tagmanager/thread/51544115/spa-page-view-tracking-sends-event-twice?hl=en. This configuration makes the app send events automatically when history changes. So, the app stops sending events and I manually send with

event('page_view',{
    page_title: `xxxx',
    page_path: to.path,
    page_location: window.location.href,
    page_referrer: from.path,
   ...other params
  })