MatteoGabriele / vue-gtag

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

How can I let the module to load script on receiving Google ID from API (so initially it has disableScriptLoad: true)? #260

Closed TitanFighter closed 3 years ago

TitanFighter commented 3 years ago

Hi.

My site receives some settings from API. Some settings may include Google ID, some not, so in the 2nd case no reason to load script, so because of this I do the next:

Vue.use(VueGtag, {
  disableScriptLoad: true
})

Then I check if settings include Google ID:

import { setOptions, bootstrap } from 'vue-gtag'

...
  mounted () {
    if (this.settings.gaMeasurementId) {
      setOptions({
        config: { id: this.settings.gaMeasurementId }
      })

      bootstrap()
    }
  },

and this does not work. Is there a way to load script and bootstrap it in this case?

Thank you.

MatteoGabriele commented 3 years ago

you need to pass bootstrap: false as well in your plugin options