Vue Application Insights Integration

1.0.7 · abandoned · verified Sun Apr 19

vue-application-insights is a JavaScript plugin designed to integrate Microsoft Azure Application Insights telemetry into Vue.js 2 applications. It provides a straightforward `Vue.use()` interface for initialization, accepting an Azure Application Insights instrumentation key and optionally integrating with Vue Router for automatic page view tracking. The plugin exposes the Application Insights client instance as `$appInsights` on Vue components, enabling developers to easily track custom events, metrics, exceptions, and traces within their application logic. The package, currently at version 1.0.7, appears to be targeting Vue 2 exclusively, with its last significant update several years ago, indicating it is likely abandoned in favor of newer, Vue 3-compatible alternatives like `vue3-application-insights`. Its primary utility lies in simplifying the setup of the Application Insights JavaScript SDK within the Vue 2 ecosystem, abstracting away manual script loading and initialization.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up `vue-application-insights` with Vue Router for automatic page view tracking and how to trigger a custom event from a Vue component using `$appInsights`.

import Vue from 'vue';
import VueRouter from 'vue-router';
import VueAppInsights from 'vue-application-insights';

Vue.use(VueRouter);

const router = new VueRouter({
  mode: 'history',
  routes: [
    { path: '/', component: { template: '<div>Home Page <button @click="custom_action">Track Custom Action</button></div>' } },
    { path: '/about', component: { template: '<div>About Page</div>' } }
  ]
});

Vue.use(VueAppInsights, {
  id: process.env.VUE_APP_APPINSIGHTS_KEY ?? 'YOUR_INSTRUMENTATION_KEY_HERE',
  router,
  baseName: '(My Vue 2 App)',
  trackInitialPageView: true
});

new Vue({
  router,
  methods: {
    custom_action() {
      this.$appInsights.trackEvent({
        name: "custom_action",
        properties: { value: 'ok', source: 'quickstart' }
      });
      console.log('Custom action event tracked!');
    }
  },
  render: h => h({ template: `
    <div>
      <router-link to="/">Home</router-link> |
      <router-link to="/about">About</router-link>
      <router-view></router-view>
    </div>`})
}).$mount('#app');

view raw JSON →