Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
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 |
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} }]
- 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
The npm package usage-stats receives a total of 1,382 weekly downloads. As such, usage-stats popularity was classified as popular.
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
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.