Google Analytics for Vue.js


To add Google Analytics to your hosting site using Vue.js, set tracking code on each page if you need.

It'll be messy if you do that without thinking.

vue-analytics package is beneficial for measuring pages.

vue-analytics

Requirements

  • Vue ^2.0.0
  • Google Analytics Tracking ID

Installation

Install the library using npm.

% npm install vue-analytics

Implementation

Enable auto page tracking with few implementation.

import Vue from 'vue'
import VueAnalytics from 'vue-analytics'

import router from './path-to-router'

/* or meke `router`
import VueRouter from 'vue-router'

const router = new VueRouter({
  router: // ...
})
*/
                                         
Vue.use(VueAnalytics, {
  id: '[YOUR-GOOGLE-ANALYTICS-TRACKING-ID]',
  router
})

The code is the easiest way to track your pages. vue-analytics can be customized in several ways, refer to other resources.

Other Resources.

Please read the following link if you want to know more tracking!