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

[Question] how to set "enable" property to true from within component? #173

Closed moritzlaube closed 4 years ago

moritzlaube commented 4 years ago

Dear Matteo,

thanks for having developed this plugin! I want to use it with Gridsome on a german website where I have to think about GDPR. When initializing the plugin I will set the enabled property to false like described in your documentation:

import Vue from "vue";
import VueGtag from "vue-gtag";

Vue.use(VueGtag, {
  config: { id: "UA-1234567-1" },
  enabled: false
});

Yet, how am I able to access this property from a component within my app to set it to true again? Thanks for helping me out here.

Best, Moritz

MatteoGabriele commented 4 years ago

oh sorry, didn't know I forgot to add it to the doc. you should be able to access the method like this

export default {
  methods: {
    enableTracking () {
      this.$gtag.optIn()
    }
  }
}

I am working on the next version of this plugin for vue 3 and it will be sure to make the all doc better