Using vue-ga, may be the simplest way to use the Google Analytics at the Vue SPA application using vue router.
There are now some plugins that use google analitics in vue's spa, but I think the old vue-ga is the simplest and easiest to use.
How to install
Just as follow:
yarn add vue-ga
How to use
Surprisingly easy! just add two lines to your index.js under the router folder:
Inporting the vue-ga,
import ga from 'vue-ga'
and using vue-ga
The completed form looks like this:
// ./router/index.js import VueRouter from 'vue-router' import ga from 'vue-ga' Vue.use(VueRouter) const router = new VueRouter() ga(router, 'UA-XXXXX-Y') export default router
That's it. I'm loving to use vue-ga.