Vue Gtag Next

1.14.0 · abandoned · verified Sun Apr 19

vue-gtag-next is a plugin designed for Vue 3 to integrate Google's Global Site Tag (gtag.js), enabling event data collection for services like Google Analytics and Google Ads. The package's current stable version is 1.14.0, last released in October 2020. According to its README from that period, it explicitly stated "it's not production ready" and was developed when "Vue 3 is not out yet." This indicates that development ceased early in Vue 3's lifecycle, and the package has not received updates to keep pace with subsequent Vue 3 releases or changes in gtag.js. Its release cadence has effectively stopped. While it aimed to provide a convenient wrapper for gtag.js within a Vue 3 application, its unmaintained status and early development phase mean it lacks long-term support and may have compatibility issues with current Vue 3 versions, making it a potentially risky choice for modern applications compared to actively maintained alternatives.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart initializes the VueGtagNext plugin with a Google Analytics ID and demonstrates sending both a page view event and a custom event from a Vue 3 component using the Composition API's `useGtag` hook.

import { createApp } from 'vue';
import VueGtagNext, { useGtag } from 'vue-gtag-next';

const App = {
  template: `
    <div>
      <h1>Google Analytics Demo</h1>
      <button @click="sendPageView">Send Page View</button>
      <button @click="sendEvent">Send Custom Event</button>
    </div>
  `,
  setup() {
    const { event } = useGtag();

    const sendPageView = () => {
      event('page_view', {
        page_title: 'Home Page',
        page_path: '/',
      });
      console.log('Page view sent!');
    };

    const sendEvent = () => {
      event('button_click', {
        event_category: 'engagement',
        event_label: 'Call to Action',
        value: 1,
      });
      console.log('Custom event sent!');
    };

    return { sendPageView, sendEvent };
  },
};

const app = createApp(App);

app.use(VueGtagNext, {
  property: {
    id: process.env.VUE_APP_GA_ID ?? 'G-XXXXXXXXXX' // Replace with your actual GA ID
  },
  enabled: true, // Enable or disable tracking
  bootstrap: true, // Inject gtag.js script automatically
});

app.mount('#app');

view raw JSON →