Yandex Metrika Plugin for Vue.js

1.8.3 · abandoned · verified Sun Apr 19

Vue Yandex Metrika is a utility package designed to integrate Yandex Metrika tracking into Vue.js applications. It simplifies the process of sending page view data to Yandex Metrika, offering both automatic tracking when integrated with Vue Router and manual tracking capabilities. The current stable version is v1.8.3, released in September 2019, indicating a lack of active development since then. Its primary differentiator is its direct integration with the Vue ecosystem, abstracting the raw Yandex Metrika API calls. It allows configuration of tracking ID, environment-based tracking (e.g., only in production), script source, debug mode, route ignoring, and other Yandex Metrika counter options, providing a convenient wrapper for web analytics in Vue projects. Given its last update in 2019, it primarily supports older Vue 2 applications and may not be compatible with Vue 3 without community efforts or significant adaptations.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the automatic page view tracking with Vue Router, configuring Yandex Metrika with a placeholder ID, environment-specific settings, debug mode, and additional Metrika options.

import Vue from 'vue';
import VueRouter from 'vue-router';
import VueYandexMetrika from 'vue-yandex-metrika';

const routes = [
  { path: '/', component: { template: '<div>Home Page</div>' }, name: 'home' },
  { path: '/about', component: { template: '<div>About Page</div>' }, name: 'about' },
  { path: '/contact', component: { template: '<div>Contact Page</div>' }, name: 'contact' }
];

const router = new VueRouter({ routes, mode: 'history' });

Vue.use(VueYandexMetrika, {
  id: process.env.VUE_APP_YANDEX_METRIKA_ID ?? '12345678',
  router: router,
  env: process.env.NODE_ENV,
  debug: process.env.NODE_ENV !== 'production',
  options: {
    clickmap: true,
    trackLinks: true,
    accurateTrackBounce: true,
    webvisor: true
  }
});

new Vue({
  router,
  template: `
    <div id="app">
      <router-link to="/">Home</router-link> |
      <router-link to="/about">About</router-link> |
      <router-link to="/contact">Contact</router-link>
      <router-view></router-view>
    </div>
  `
}).$mount('#app');

view raw JSON →