npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

app-meter

v1.0.1

Published

Application Insights wrapper for vue.js framework

Downloads

81

Readme

METER

Meter is a vuejs based plugin designed to track user activities, collect analytics using Microsoft's application-insights package over Azure dashboard. This wrapper plugin does a lot of underground work to organize and track data related to exceptions, route changes, page views, performance metrics, etc.. The below description will give you a walkthrough to install app-meter on your production-ready app to track any custom data, user activity you can think of and associate it with the logged-in user if required.

Why you should consider using Meter?

  1. Tracks request body of failed requests from client to server.
  2. Ability to enable/disable specific feature tracking through a configuration file.
  3. Intelligently detects device information like private browsing sessions.
  4. Keeps track of all page views using the router and time spent by a user on each page/route.
  5. Parses custom track event data in the required format during storage.
  6. Correlates all data records with user sessions using user login id if required.

Installation

$ npm install app-meter --save

Get started

main.js.

import Vue from 'vue';
import router from './router';
import axios from 'axios';
import Meter from 'app-meter';
import trackingConfiguration from 'path-to-your-tracking-configuration-file';

Vue.use(Meter, {
  id: 'XXXXXXXX--XXXX-XXXX-XXXXXXXXXXXX', // app-insights instrumentation key
  applicationName: 'Vue App', // application name
  router, // Required
  axios, // Optional. To track failed request's body.
  trackingConfiguration,
  // pass your tracking configuration file. This will help you to enable/disable tracking activities in an organized way.
  // isEnabled: false will be ignored from tracking activities
});

router: is required to track all user navigation across the application.

axios: is optional. But when supplied can track any failed ajax requests and also captures the request and response body to help in debugging process.

Sample trackingConfiguration file

trackingConfiguration.json

export default {
  'track-a001': {
    name: 'Login User',
    isEnabled: true,
  },
  'track-a002': {
    name: 'Update Cart',
    isEnabled: true,
  },
  'track-a003': {
    name: 'Store Password',
    isEnabled: false,
  },
};

Disabled events will not be tracked. This gives flexibility to add/remove custom track events anytime without modifying core code.

Tip

If at any point in time, you wish to discontinue tracking a specific event that saves massive amounts of data for cost-cutting you could just disable the event from this config file without having to modify the code.

SomeTemplate.vue

Example with custom track event directive - to be used in template
<div>
  <h2
    v-m-track-event="{
            name: 'track-a024',
            trigger: 'click',
            action: 'update',
            quoteType: 'mixed',
            component: $options.name
          }"
    class="mb-0"
  >
    Quotes
  </h2>
</div>

Example with custom track event method - to be used in script

SomeTemplate.vue

this.$meter.trackEvent({
  // decodes the name from your trackingConfiguration file. This name could be used to query your customEvent
  name: 'track-a020',
  // it's nice to have how the event was triggered
  trigger: 'auto',
  // to help filter records based on CRUD operations which occurred in your app
  action: 'read',
  // component from where the event originated
  component: $options.name,
  // custom data you would like to store
  value: {
    key: 'value',
  },
});

Set User Context

To tie all requests, events, pageView data to an authenticated user.

Set the authenticated user id and the account id once you have identified a specific signed-in user.

this.$meter.setUserContext({ authenticatedUserId, accountId, storeInCookie });

The method will only set the authenticatedUserId and accountId for all events in the current page view. To set them for all events within the whole session, you should either call this method on every page view or set storeInCookie = true.

| Parameter | Type | Description | | --------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------ | | authenticatedUserId | string | RequiredAn id that uniquely identifies a user of your app. No spaces, comma, semicolon, equals or vertical bar. | | accountId? | string | OptionalAn optional account id, if your app groups users into accounts. No spaces, comma, semicolon, equals or vertical bar. |

In the portal, this will add to the count of authenticated users. Authenticated users provide a more reliable count of the number of real users than the count of anonymous users.

The authenticated user id will be available as part of the context of the telemetry sent to the portal, so that you can filter and search on it. It will also be saved as a cookie and sent to the server, where the server SDK (if installed) will attach it to server telemetry.

Clear User Context

this.$meter.clearUserContext();

Clears the authenticated user id and the account id from the user context, and clears the associated cookie.