Vue-gtag is a Global Site Tag (gtag.js) plugin designed specifically for Vue 3 applications, facilitating the integration of Google Analytics, Google Ads, and Google Marketing Platform tracking. Currently at stable version 3.7.0, the library maintains an active release cadence, with frequent minor updates and bug fixes, often addressing dependency updates or small API refinements. It distinguishes itself by providing a deeply integrated, Vue-idiomatic API, including both a global plugin for straightforward application-wide setup and a composable `useGtag()` for fine-grained control within components. Key features include automatic pageview tracking when integrated with `vue-router` (now supporting both v4 and v5), comprehensive consent management functionalities, and support for all standard `gtag.js` commands (`event`, `config`, `set`). The library aims to simplify the often complex setup of Google tracking, allowing developers to leverage Google's robust analytics platform with minimal boilerplate in their Vue projects.
npm install vue-gtagVerified import paths — ran on the pinned version, not inferred.
Demonstrates `vue-gtag` installation with Vue Router for automatic pageview tracking and manual event sending via the `useGtag` composable.
Refer to the official vue-gtag documentation for Vue 3 migration guides. Update plugin initialization from `Vue.use()` to `app.use()` and replace `this.$gtag` with `useGtag()` composable.
To enable automatic pageview tracking, ensure `vue-router` (v4 or v5) is installed and imported, then include `router` in your `VueGtag` plugin options: `app.use(VueGtag, { ..., router })`.Carefully implement the `consent` option during plugin initialization or use the `consent.update()` method from `useGtag` in response to user choices. Ensure default consent states are set correctly according to regional regulations.
Communicate this limitation to stakeholders. While there's no direct fix within `vue-gtag`, server-side tracking (e.g., Google Tag Manager Server-Side) can mitigate some effects of client-side ad blocking.
Always use `import` statements for `vue-gtag` in modern Vue CLI, Vite, or Nuxt 3 projects. If encountering issues in Node.js environments (like SSR), verify your build configuration supports ESM.
Double-check that the `id` property within the `config` object of your `VueGtag` options is a valid GA4 Measurement ID (e.g., 'G-XXXXXXXXXX'). Use environment variables for production IDs.
Ensure `app.use(VueGtag, ...)` is called before any components that use `useGtag()`. If using SSR, ensure `useGtag` calls are within `onMounted` or `nextTick` hooks to guarantee browser context.
Always use `import { useGtag } from 'vue-gtag'` for the composable. For the main plugin, use `import VueGtag from 'vue-gtag'` (default export).Verify the `id` in `VueGtag` options matches your GA4 Measurement ID. Check browser console for `gtag.js` network errors. Inspect consent settings. Temporarily disable ad blockers for testing.
Ensure `import VueGtag from 'vue-gtag'` is present and correct at the top of your `main.ts` (or equivalent entry file). Double-check for typos.