Vue 2 add gtag for GA4

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!

Leave a Reply

Your email address will not be published. Required fields are marked *