Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$ga is missing from router middleware`s context #123

Open
DevineDecrypter opened this issue Dec 2, 2021 · 3 comments
Open

$ga is missing from router middleware`s context #123

DevineDecrypter opened this issue Dec 2, 2021 · 3 comments

Comments

@DevineDecrypter
Copy link

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.

@BenGoetemann
Copy link

i have the same issue

@liuther9
Copy link

@DevineDecrypter @BenGoetemann did you guys solve it? This.$ga is undefined for me

@BenGoetemann
Copy link

BenGoetemann commented Feb 10, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants