Socket
Socket
Sign inDemoInstall

usage-stats

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

usage-stats

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


Version published
Weekly downloads
1.7K
increased by53.65%
Maintainers
1
Weekly downloads
 
Created
Source

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

usage-stats

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

Synopsis

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

// 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')

try {
  beginEncoding(options)
} catch (err) {
  // exception tracking
  usageStats.exception(err.message, true)
}

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

List of stats sent

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

  • App name
  • App version
  • Node.js version (sent as App ID)
  • User ID (a random UUID, generated once per OS user and stored)
  • Language (process.env.LANG, if set)
  • OS version (sent as App Installer ID)
  • Terminal resolution (rows by columns)

API Reference

Example

const UsageStats = require('usage-stats')

UsageStats ⏏

Kind: Exported class

new UsageStats(trackingId, [options])
ParamTypeDescription
trackingIdstringGoogle Analytics tracking ID (required).
[options]object
[options.name]stringApp name
[options.version]stringApp version
[options.lang]stringLanguage. Defaults to process.env.LANG.
[options.sr]stringScreen resolution. Defaults to ${process.stdout.rows}x${process.stdout.columns}.
[options.dir]stringPath of the directory used for persisting clientID and queue.

Example

const usageStats = new UsageStats('UA-98765432-1', {
  name: 'sick app',
  version: '1.0.0'
})

usageStats.dir : string

Absolute path of the temporary directory used for persisting clientID and queue.

Kind: instance property of UsageStats

usageStats._queuePath : string

The absolute path of the queue.

Kind: instance property of UsageStats

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

ParamTypeDescription
categorystringEvent category (required).
actionstringEvent action (required).
[label]stringEvent label
[value]stringEvent value

usageStats.screenView(name) ↩︎

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

Kind: instance method of UsageStats
Chainable

ParamTypeDescription
namestringScreen name

usageStats.exception(description, isFatal) ↩︎

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

Kind: instance method of UsageStats
Chainable

ParamTypeDescription
descriptionstringError message
isFatalbooleanSet true if the exception was fatal

usageStats.send([options]) ⇒ Promise

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
Fulfil: debug mode: { hits: {hits}, result: {validation result} }
Fulfil: live mode: { res: {res}, data: {Buffer} }

ParamTypeDescription
[options]object
[options.debug]booleanValidates hits, fulfilling with the result.

usageStats._getClientId() ⇒ string

Must return a v4 UUID.

Kind: instance method of UsageStats

usageStats._request(reqOptions, [data]) ⇒ Promise

The request method used internally, can be overridden for testing or other purpose. Takes a node-style request options object in. Must return a promise.

Kind: instance method of UsageStats
Fulfil: { res: <node response object>, data: <Buffer payload> }

ParamType
reqOptionsobject
[data]*

usageStats._dequeue([count]) ⇒ Array.<string>

Returns hits queued.

Kind: instance method of UsageStats

ParamTypeDescription
[count]numberNumber of hits to dequeue. Defaults to "all hits".

usageStats._enqueue(hits)

Kind: instance method of UsageStats

ParamType
hitsArray.<string>

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

Keywords

FAQs

Package last updated on 17 Aug 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc