vue-gtag
Github
v2
v2
  • Get started
  • Migration v1 to v2
  • Bootstrap options
  • Auto tracking
  • Multiple domain tracking
  • Plugin hooks
  • API
  • Opt-in/out
  • Global namespace
  • Access gtag instance directly
  • Debug
  • Plugin options
  • Methods
    • pageview
    • event
    • screenview
    • customMap
    • purchase
    • linker
    • set
    • time
    • config
    • exception
Powered by GitBook
On this page
  • Plugin bootstrapped
  • Before and after tracking

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");
PreviousMultiple domain trackingNextAPI

Last updated 4 years ago