Open drusellers opened 1 year ago
@drusellers try this 👇
import VueGtag from 'vue-gtag-next'
export default defineNuxtPlugin((nuxtApp) => {
const config = useRuntimeConfig()
nuxtApp.vueApp.use(VueGtag.default, {
property: {
id: config.public.googleAnalyticsId,
},
})
})
Actually, I would recommend some more changes:
which gives the following code
import { defineNuxtPlugin } from '#app'
export default defineNuxtPlugin((nuxtApp) => {
const t = ref(null)
onNuxtReady(async () => {
const VueGtag = await import('vue-gtag-next')
t.value = VueGtag
nuxtApp.vueApp.use(VueGtag.default, {
property: {
id: nuxtApp.$config.public.googleAnalytics.id
},
appName: 'Voorbereidingsplatform Demo',
isEnabled: false,
useDebugger: nuxtApp.payload.config.public.mode !== 'prod',
pageTrackerScreenviewEnabled: true,
});
VueGtag.trackRouter(useRouter())
if (VueGtag) console.log('vue-gtag plugin installed')
})
return {
provide: {
t
}
}
});
I'm using using a composable useTracking() with some reusable functions, such as disable() and enable() for GDPR compliance
Description
After following the instructions in the documentation, and the documentation of Nuxt 3, I have configured this plugin like so.
~/plugins/googleAnalytics.js
Expected behavior
There should be no warnings in the terminal
Actual behavior
shows up in the terminal
Environment
Run this command in the project folder and fill in their results:
npm ls vue-gtag-next
:Then, specify:
Reproducible Demo
... skipped