This is for vue 2
First: install ‘vue-gtag’ . this should be Ver 1. And it works with GA4 too.
IMPORTANT: add @legacy
npm install vue-gtag@legacy
Second: Update main.js
NOTE: use “vue-router” to automatically log “pages”
import Vue from "vue";
import App from "./App.vue";
import router from "./router";
// vue-gtag
import VueGtag from 'vue-gtag'
Vue.use(VueGtag, {
config: {
id: 'G-xxxxxxxxx'
}
}, router)
new Vue({
router,
render: (h) => h(App),
}).$mount("#app");
DONE!