MatteoGabriele / vue-gtag

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

How to opt out after opt in #44

Closed surfgreendev closed 4 years ago

surfgreendev commented 4 years ago

Hi!

at first, thanks for your work on this plugin.

I've implemented vue-gtag with the boostraping strategy. GDPR also requires that users can opt out afterwords. So far I've implemented and optOut method to disable tracking, but can still see page tracking via GTM/GA Debug Chrome Plugin.

Is this the correct way to go for?

optOut() {
      setOptions({
        enabled: false,
      });

      this.SET_COOKIE_CONSENT_LAYER_DECLINED();
      bootstrap();
    },

Furthermore, is there a way where I can get the current configure options of vue-gtag within a component, e.g. to check if its enabled?

Thanks in advance and happy new year!

Carl

MatteoGabriele commented 4 years ago

hi @surfgreendev thanks for everything to opt out you just need to call this.$gtag.optOut() no additional code is required The bootstrap it's literally only when you start the plugin, especially if you want to enable after a cookie banner, but when you have that already sort it out, you just call the opt out method and that's it.

hope it fixes it

in case is doesn't, please provide a small reproduction of you issue creating a small app in a public repo with the bare reproduction of your setup so that I can have a look at it.

ps: happy new year to you too :)

fejj182 commented 4 years ago

Just to note that after you call this.$gtag.optOut() it will work initially, but if the page is refreshed then analytics will continue to run.

This is because the window property

window['ga-disable-GA_MEASUREMENT_ID'] = true;

has to be called at the beginning of every page load. Therefore after you call this.$gtag.optOut() you should persist this (for example using a cookie in the localStorage) and then set enabled:false in the initial Vue.use() if the cookie is present.

https://developers.google.com/analytics/devguides/collection/gtagjs/user-opt-out