Opt-out from Google Analytics

It is possible to opt-out from Google Analytics by simply setting the disabled property to true.The disabled property accepts also a function, a promise or a function that returns a promise, but it needs to return a boolean.

Take in mind that when using a promise, the plug-in won’t start tracking until it’s resolved, because the opt-out needs to happen before trackers or queues are initialized.

If you are using more then one domain name, all of them will be disabled from tracking.

if you need to disable tracking just for development, is better to use the sendHitTask property in the debug object. Read more here

  1. import Vue from 'vue'
  2. import VueAnalytics from 'vue-analytics'
  3. // boolean
  4. Vue.use(VueAnalytics, {
  5. id: 'UA-XXX-X',
  6. disabled: true
  7. })
  8. // function
  9. Vue.use(VueAnalytics, {
  10. id: 'UA-XXX-X',
  11. disabled: () => {
  12. return true
  13. }
  14. })
  15. // promise
  16. Vue.use(VueAnalytics, {
  17. id: 'UA-XXX-X',
  18. disabled: Promise.resolve(true)
  19. })
  20. // function that returns a promise
  21. Vue.use(VueAnalytics, {
  22. id: 'UA-XXX-X',
  23. disabled: () => {
  24. return Promise.resolve(true)
  25. }
  26. })

It is also possible to disable tracking from everywhere at any time using the disable method.

  1. export default {
  2. methods: {
  3. disableTracking () {
  4. this.$ga.disable()
  5. // from now on analytics is disabled
  6. },
  7. enableTracking () {
  8. this.$ga.enable()
  9. // from now on analytics is enabled
  10. }
  11. }
  12. }

or

  1. Vue.$ga.disable()
  2. Vue.$ga.enable()