MatteoGabriele / vue-gtag

Global Site Tag plugin for Vue (gtag.js)

Home Page:https://matteo-gabriele.gitbook.io/vue-gtag/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Uncaught TypeError: Cannot set properties of undefined (setting '$gtag')

MOAB7698 opened this issue · comments

hi
i want use this to nuxt
i created gtag.js

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

Vue.use(VueGtag, {
  config: { id: 'G-XXXXXXXXXX' },
})

and in nuxt.config i use

  plugins: [
    {
      src: '@/plugins/gtag.js',
      ssr: true,
    }
]

but i get this error
Uncaught TypeError: Cannot set properties of undefined (setting '$gtag')

I use vue 2

Hi @MOAB7698, I had the same issue. It looks like if you are using Vue 2 you need to install one of the previous versions of vue-gtag. There is actually an open PR to make this clearer in the Vue 2 compatible docs which can be found here:

https://github.com/MatteoGabriele/vue-gtag/pull/442/files

The relevant part being this line which shows which version is compatible with Vue 2:

npm install vue-gtag@1.16.1

That's correct. Default version is now for vue 3. you should install vue-gtag@legacy for vue 2