
Security News
Security Community Slams MIT-linked Report Claiming AI Powers 80% of Ransomware
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.
usage-stats
Advanced tools
A minimal, offline-friendly Google Analytics Measurement Protocol client for tracking usage statistics in node.js apps.
A minimal, offline-friendly Google Analytics Measurement Protocol client for tracking usage statistics in node.js applications.
const UsageStats = require('usage-stats')
const usageStats = new UsageStats('UA-98765432-1', {
  name: 'sick app',
  version: '1.0.0'
})
// start a new session
usageStats.start()
// user sets an option..
usageStats.event('option', 'verbose-level', 'infinite')
try {
  // register a hit on 'encoding mode'
  usageStats.screenView('encoding')
  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()
Beside tracking events, exceptions and screenviews, the follow stats are collected each session.
process.env.LANG, if set)Example
const UsageStats = require('usage-stats')
| Param | Type | Description | 
|---|---|---|
| trackingId | string | Google Analytics tracking ID (required). | 
| [options] | object | |
| [options.name] | string | App name | 
| [options.version] | string | App version | 
| [options.lang] | string | Language. Defaults to process.env.LANG. | 
| [options.sr] | string | Screen resolution. Defaults to ${process.stdout.rows}x${process.stdout.columns}. | 
| [options.dir] | string | Path of the directory used for persisting clientID and queue. | 
| [options.url] | string | Defaults to 'https://www.google-analytics.com/batch'. | 
| [options.debugUrl] | string | Defaults to 'https://www.google-analytics.com/debug/collect'. | 
Example
const usageStats = new UsageStats('UA-98765432-1', {
  name: 'sick app',
  version: '1.0.0'
})
Starts the session.
Kind: instance method of UsageStats
Chainable
Ends the session.
Kind: instance method of UsageStats
Chainable
Disable the module. While disabled, all operations are no-ops.
Kind: instance method of UsageStats
Chainable
Re-enable the module.
Kind: instance method of UsageStats
Chainable
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 (required). | 
| action | string | Event action (required). | 
| [label] | string | Event label | 
| [value] | string | Event value | 
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 | 
Track a exception. All screenview hits are queued until .send() is called.
Kind: instance method of UsageStats
Chainable
| Param | Type | Description | 
|---|---|---|
| description | string | Error message | 
| isFatal | boolean | Set true if the exception was fatal | 
PromiseSend 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} }] - array of responses
| Param | Type | Description | 
|---|---|---|
| [options] | object | |
| [options.debug] | boolean | Validates hits, fulfilling with the result. | 
© 2016 Lloyd Brookes <75pound@gmail.com>. Documented by jsdoc-to-markdown.
FAQs
A minimal, offline-friendly Google Analytics Measurement Protocol client for tracking statistics in shell and javascript applications
We found that usage-stats demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.

Research
/Security News
Socket researchers found 10 typosquatted npm packages that auto-run on install, show fake CAPTCHAs, fingerprint by IP, and deploy a credential stealer.