Adding google-analytics to your vue application

I am using Google’s global site gags (gtags) on my framework7+vue application to collect data. The gtag official documentation has an easy to use example. Anyway, I prefer vue-gtag library.

  • install vue-gtag npm install vue-gtag
  • Add following to your vue app. Usually you have to edit src/js/app.js file or equivalent file where vue is being initialized.
// Init google analytics
import VueGtag from "vue-gtag";
Vue.use(VueGtag, {
   config: { id: "UA-180198765-1" }
});

where id key in config dictionary is your tracking id.

Official documentation here https://matteo-gabriele.gitbook.io/vue-gtag/

Footnotes

  • [vue-gtag] Ops! Something happened and gtag.js couldn't be loaded.

Ad-blocker?


Leave a Reply