If you are using VueRouter inside your application, you can simply pass the VueRouter instance as the third parameter of the app.use method and the plugin will start tracking all your pages automatically
import { createApp } from"vue";import { createRouter, createWebHashHistory } from'vue-router';import VueGtag from"vue-gtag";import App from"./App.vue";import Home from"./Home.vue";import About from"./About.vue";constrouter=newVueRouter({ history:createWebHashHistory(), routes: [ { name:'Home', path:'/', component: Home }, { name:'About', path:'/about', component: About }, ]});constapp=createApp(App);app.use(router);app.use(VueGtag, { config: { id:"GA_MEASUREMENT_ID", },}, router); // <----- add your router hereapp.mount("#app");
By default, the tracking system uses pageviews with the following template
{ page_path:'/',// route path value page_location:'http://localhost:8080/'// window.location.href}
Enable screenviews
To be able to use screenview you need to first enable the feature and pass the app name using the plugin global settings