JSPM

  • Created
  • Published
  • Downloads 19220
  • Score
    100M100P100Q125302F
  • License MIT

usage-stats

Package Exports

  • usage-stats

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (usage-stats) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

view on npm npm module downloads Build Status Dependency Status js-standard-style

usage-stats

A minimal, offline-friendly Google Analytics Measurement Protocol client for tracking usage statistics in node.js apps.

Synopsis

const UsageStats = require('usage-stats')
const usageStats = new UsageStats({
  appName: 'sick app',
  version: '1.0.0',
  tid: 'UA-98765432-1'
})

// start a new session
usageStats.start()

// user set an option..
usageStats.event('option', 'verbose-level', 'infinite')

// app is running in 'encoding' mode..
usageStats.screenView('encoding')

// finished - mark the session as complete
// and send stats (or store if offline).
usageStats.end().send()

List of stats sent

Beside tracking events and screenviews, the follow stats are collected each session.

  • App name
  • App version
  • User ID (a random UUID, generated once per OS user and stored)
  • Language
  • OS version
  • Terminal resolution (rows by columns)

API Reference

Example

const UsageStats = require('usage-stats')

UsageStats ⏏

Kind: Exported class

new UsageStats([options])

Param Type Description
[options] object
[options.appName] string App name
[options.version] string App version
[options.tid] string Google Analytics tracking ID

usageStats.start() ↩︎

Starts the session.

Kind: instance method of UsageStats
Chainable

usageStats.end() ↩︎

Ends the session.

Kind: instance method of UsageStats
Chainable

usageStats.disable() ↩︎

Disable the module. While disabled, all operations are no-ops.

Kind: instance method of UsageStats
Chainable

usageStats.enable() ↩︎

Re-enable the module.

Kind: instance method of UsageStats
Chainable

usageStats.event(category, action, [label], [value]) ↩︎

Track an event. All event hits are queued until .send() is called.

Kind: instance method of UsageStats
Chainable

Param Type Description
category string Event category
action string Event action
[label] string Event label
[value] string Event value

usageStats.screenView(name) ↩︎

Track a screenview. All screenview hits are queued until .send() is called.

Kind: instance method of UsageStats
Chainable

Param Type Description
name string Screen name

usageStats.send() ↩︎

Send queued stats using as few requests as possible (typically a single request - a max of 20 events/screenviews may be sent per request). If offline, the stats will be stored and re-tried on next invocation.

Kind: instance method of UsageStats
Chainable


© 2016 Lloyd Brookes <75pound@gmail.com>. Documented by jsdoc-to-markdown.