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

$gtag undefined typescript #166

Closed mcat56 closed 4 years ago

mcat56 commented 4 years ago

In main.js :

import Vue from 'vue'
import App from './App.vue'
import store from './Store'
import VueGtag from 'vue-gtag'
import router from './Router'

Vue.config.productionTip = false

Vue.use(VueGtag, {
    config: {
        id: 'my-ID'
        }
    }
)

new Vue({
    store,
    router,
    render: h => h(App)
}).$mount('#app')

In component:

        this.$gtag.event('openModal', {
            eventCategory: 'modal',
            eventLabel: 'openModal'
        })

When I run test suite where only my previous tests that were all passing are running (no tests directly calling vue-gtag, the following error occurs:

 TypeError: Cannot read property 'event' of undefined
mcat56 commented 4 years ago

Resolved - in jest-setup.js:

import Vue from 'vue'
import VueGtag from 'vue-gtag'

Vue.use(VueGtag, {
  config: {
      id: xx-xxx-xxx
  }
})
omaisali commented 4 years ago

Resolved - in jest-setup.js:

import Vue from 'vue'
import VueGtag from 'vue-gtag'

Vue.use(VueGtag, {
  config: {
      id: xx-xxx-xxx
  }
})

didn't get you. How to resolve this