MatteoGabriele / vue-gtag

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

How to Use functions or/and Promises when initializing VueGtag config.id #51

Closed jfanals closed 4 years ago

jfanals commented 4 years ago

I am looking for a way to initialize VueGtag with the response of an API call.

I have tried setting it with a function/promise as the vue-analytics plugin but it is not working... https://github.com/MatteoGabriele/vue-analytics/blob/master/docs/installation.md#use-functions-orand-promises

The solution that seems to be working is to initialize the VueGtag after the API response

  axios.get('api_endpoint').then(response => {
    const gtag_id = response.data
    Vue.use(VueGtag, {
      config: {
        id: gtag_id
      }
    })
  })

I am not sure this is the best way. Do you have any other suggestions?

Thank you

MatteoGabriele commented 4 years ago

I would try to bootstrap the plug-in like this

https://matteo-gabriele.gitbook.io/vue-gtag/custom-installation#bootstrap-later

And make sure to read the section after this one in case u need to pass something from the API call