Plugin hooks

Plugin bootstrapped

Will fire when the gtag script is successfully loaded

import { createApp } from "vue";
import App from "./App.vue";
import VueGtag from "vue-gtag";

createApp(App).use(VueGtag, {
  config: { id: "GA_MEASUREMENT_ID" },
  onReady () {
    // ready
  }
}).mount("#app");

This method will not be triggered if you have disabled the script loading

Before and after tracking

The auto-tracking feature of vue-gtag will fire a pageview or screenview after each route change and it is possible to add a hook right before and/or right after the page is tracked.

import { createApp } from "vue";
import { createRouter } from 'vue-router'
import App from "./App.vue";
import VueGtag from "vue-gtag";

const router = createRouter(...)

createApp(App).use(VueGtag, {
  config: { id: "GA_MEASUREMENT_ID" },
  onBeforeTrack () {
    // before!
  },
  onAfterTrack () {
    // after!
  }
}, router).mount("#app");

Last updated