Git Product home page Git Product logo

insight's Introduction

Insight Build Status

Understand how your tool is being used by anonymously reporting usage metrics to Google Analytics or Yandex.Metrica

This module uses the newly released Universal Analytics API from Google Analytics

Analytics dashboard example

Displaying metrics from Yeoman which makes use of Insight.

analytics screenshot

Example usage

Google Analytics

var Insight = require('insight');
var pkg = require('./package.json');

var insight = new Insight({
	// Google Analytics tracking code
	trackingCode: 'UA-XXXXXXXX-X',
	packageName: pkg.name,
	packageVersion: pkg.version
});

// ask for permission the first time
if (insight.optOut === undefined) {
	return insight.askPermission();
}

insight.track('foo', 'bar');
// recorded in Analytics as `/foo/bar`

Yandex.Metrica

var Insight = require('insight');
var pkg = require('./package.json');

var insight = new Insight({
	// Yandex.Metrica counter id
	trackingCode: 'XXXXXXXXX'
	trackingProvider: 'yandex',
	packageName: pkg.name,
	packageVersion: pkg.version
});

// ask for permission the first time
if (insight.optOut === undefined) {
	return insight.askPermission();
}

insight.track('foo', 'bar');
// recorded in Yandex.Metrica as `http://<package-name>.insight/foo/bar`

or a live example

Documentation

Insight(settings)

trackingCode

Type: string
Required

Your Google Analytics trackingCode or Yandex.Metrica counter id.

trackingProvider

Type: string
Default: 'google'

Tracking provider to use
Possible values are 'google' or 'yandex'

packageName

Type: string
Required

Requires you to also specify packageVersion

packageVersion

Type: string
Default: '0.0.0'

Requires you to also specify packageName

config

Type: object
Default: An instance of configstore

If you want to use your own configuration mechanism instead of the default configstore-based one, you can provide an object that has to implement two synchronous methods:

  • get(key)
  • set(key, value)

Instance methods

.track(keyword, [keyword, ...])

Accepts keywords which ends up as a path in Analytics.

.track('init', 'backbone') becomes /init/backbone

.askPermission([message, callback])

Asks the user for permission to track and sets the optOut property. You can also choose to set this manually.

askPermission screenshot

Optionally supply your own message and callback. The callback will be called with the arguments error and optOut when the prompt is done, and is useful for when you want to continue the execution while the prompt is running.

.optOut

Returns a boolean whether the user has opted out of tracking. Should preferably only be set by a user action, eg. a prompt.

License

BSD license and copyright Google

insight's People

Contributors

sindresorhus avatar passy avatar addyosmani avatar danielchatfield avatar paulirish avatar kevva avatar rogeriopvl avatar arikon avatar sboudrias avatar floatdrop avatar

Watchers

Sven Lito avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.