$ga is missing from router middleware`s context
I'm trying to use $ga in a middleware, but it doesn't seem to contain it.
I tried using context.$ga and context.app.$ga but they are undefined.
I also tried putting '@nuxtjs/google-analytics' in both buildModules and modules in nuxt.config.js but didn't work either.
export default function (context) {
console.log(context.$ga)
console.log(context.app.$ga)
}
both logs are undefined.
i have the same issue
@DevineDecrypter @BenGoetemann did you guys solve it? This.$ga is undefined for me
No I used vue gtag instead. If you're using Nuxt 2 you have to use vue gtag v1. I didnt use it for Nuxt 3.
If your using Nuxt 2 you have to register it as plugin in your nuxt.config. This is the plugin code:
import Vue from 'vue';
import VueGtag from 'vue-gtag';
export default ({
app, env
}) => {
Vue.use(VueGtag, {
bootstrap: false,
config: {
id: env.ANALYTICS_KEY,
params: {
anonymize_ip: true
}
},
appName: 'your app name',
}, app.router);
}
... and then you can use it via this.$gtag inside your components.
Hope this helps!