MatteoGabriele / vue-gtag

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

Using in Nuxt 3 project. `page_view` works, but `event` doesn't #516

Open YosefMets opened 1 year ago

YosefMets commented 1 year ago

Environment *

npm ls vue-gtag: vue-gtag@2.0.1

npm ls vue: vue@3.2.45

Description *

import VueGtag from 'vue-gtag'

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.use(VueGtag, {
    config: {
      id: 'XXX-XXXXXX',
    },
  }, nuxtApp.$router)
})

page_view works. Then I try use event in the setup:

import { event } from 'vue-gtag'

const addToCart = () => {
  event('add_to_cart', {...});
}

Expected behavior

When I'm adding item to cart nothing's happened in the Googlу Analytics. There is also no new request in the "Network". But in window.dataLayer added a new data ['event', 'add_to_cart', {…}, ...]

What am I doing wrong?

dizao commented 1 year ago

@YosefMets Hey bro, maybe u need to use query instead event.

import { query} from 'vue-gtag'

const addToCart = () => { query('event','add_to_cart', {...}); }

howard-tzw commented 1 year ago

I meet the same problem, nothings happened in the GA Events

Update: Now I no longer have this issue