{"name":"usage-stats","author":{"name":"Lloyd Brookes","email":"75pound@gmail.com"},"version":"0.2.0","description":"A minimal, offline-friendly Google Analytics Measurement Protocol client for tracking usage statistics in node.js apps.","repository":{"type":"git","url":"git+https://github.com/75lb/usage-stats.git"},"license":"MIT","main":"index","keywords":["google","analytics","measurement","protocol","tracking","usage","stats"],"engines":{"node":">=0.10.0"},"scripts":{"test":"test-runner es5/test/*.js","docs":"jsdoc2md -t jsdoc2md/README.hbs src/lib/*.js > README.md; echo","es5":"rm -rf es5 && babel --presets babel-preset-es2015 --no-comments src --out-dir es5","cover":"istanbul cover ./node_modules/.bin/test-runner src/test/*.js && cat coverage/lcov.info | ./node_modules/.bin/coveralls && rm -rf coverage; echo"},"dependencies":{"core-js":"^2.4.1","feature-detect-es6":"^1.3.1","mkdirp":"^0.5.1","node-uuid":"^1.4.7","req-then":"~0.3.4","typical":"^2.5.0"},"devDependencies":{"babel-preset-es2015":"^6.13.2","core-assert":"~0.2.0","coveralls":"^2.11.12","jsdoc-to-markdown":"^2.0.0-alpha.5","test-runner":"~0.1.12"},"standard":{"ignore":["es5"]},"gitHead":"78d0af8c9954b2518a513b008e0a7615b344871a","bugs":{"url":"https://github.com/75lb/usage-stats/issues"},"homepage":"https://github.com/75lb/usage-stats#readme","_id":"usage-stats@0.2.0","_shasum":"dfce61bbf45e1305239a9ed6c8e107a6fd575515","_from":".","_npmVersion":"3.10.5","_nodeVersion":"6.3.1","_npmUser":{"name":"75lb","email":"75pound@gmail.com"},"dist":{"shasum":"dfce61bbf45e1305239a9ed6c8e107a6fd575515","tarball":"http://registry-npm.ywwl.com/usage-stats/download/usage-stats-0.2.0.tgz","integrity":"sha512-NH2YPqWe2jIdVp/Uxl7CedvZxNbjinnvGYKwha48zRgeIiYrDs/LtNhCWI/bn8FhfI8GZ9QgipqHGoZDUk7jbg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD90jpCCE9EDIZaxHFw4TeCn7mgPY2taccpSiBLECx0rgIhAIfeRLDhcm9Gu5NftWxHG3Fa3N/WVcR7GNp97D/VrcL/"}],"size":9351,"noattachment":false,"key":"/usage-stats/-/usage-stats-0.2.0.tgz"},"maintainers":[{"name":"75lb","email":"75pound@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/usage-stats-0.2.0.tgz_1471472617399_0.8461228725500405"},"directories":{},"readme":"[![view on npm](https://badgen.net/npm/v/usage-stats)](https://www.npmjs.org/package/usage-stats)\n[![npm module downloads](https://badgen.net/npm/dt/usage-stats)](https://www.npmjs.org/package/usage-stats)\n[![Gihub repo dependents](https://badgen.net/github/dependents-repo/75lb/usage-stats)](https://github.com/75lb/usage-stats/network/dependents?dependent_type=REPOSITORY)\n[![Gihub package dependents](https://badgen.net/github/dependents-pkg/75lb/usage-stats)](https://github.com/75lb/usage-stats/network/dependents?dependent_type=PACKAGE)\n[![Node.js CI](https://github.com/75lb/usage-stats/actions/workflows/node.js.yml/badge.svg)](https://github.com/75lb/usage-stats/actions/workflows/node.js.yml)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](https://github.com/feross/standard)\n\n# usage-stats\n\nA minimal, offline-friendly [Google Analytics Measurement Protocol](https://developers.google.com/analytics/devguides/collection/protocol/v1/) client for tracking usage statistics in shell and javascript applications.\n\nThis is a low-level API client, it doesn't hold any opinion of how usage tracking should be done. If you're looking for a convention which leverages the power and flexibility of [Custom Metrics and Dimensions](https://support.google.com/analytics/answer/2709828?hl=en&ref_topic=2709827), take a look at [app-usage-stats](https://github.com/75lb/app-usage-stats). For the command line client see [usage-stats-cli](https://github.com/75lb/usage-stats-cli).\n\n## Synopsis\n\nThe most trivial example.\n\n```js\nconst UsageStats = require('usage-stats')\nconst usageStats = new UsageStats('UA-98765432-1', { an: 'example' })\n\nusageStats.screenView('screen name')\nusageStats.event('category', 'action')\nusageStats.send()\n```\n\nMore realistic usage in a server application:\n\n```js\nconst UsageStats = require('usage-stats')\nconst usageStats = new UsageStats('UA-98765432-1', {\n  an: 'encode-video',\n  av: '1.0.0'\n})\n\n// start a new session\nusageStats.start()\n\n// user set two options..\nusageStats.event('option', 'verbose-level', 'infinite')\nusageStats.event('option', 'preset', 'iPod')\n\ntry {\n  // Begin. Track as a screenView.\n  usageStats.screenView('encoding')\n  beginEncoding(options)\n} catch (err) {\n  // Exception tracking\n  usageStats.exception(err.message, true)\n}\n\n// finished - mark the session as complete\n// and send stats (or store if offline).\nusageStats.end().send()\n```\n\n## Protocol Parameters\n\nSee [here](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters) for the full list of Google Analytics Measurement Protocol parameters.\n\n### Sent by default\n\nAll parameters are send on demand, beside this list.\n\n* Operating System version (sent in the UserAgent)\n* [Client ID](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#cid) (a random UUID, generated once per OS user and stored)\n* [Language](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#ul) (`process.env.LANG`, if set)\n* [Screen resolution](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#sr) (terminal rows by columns, by default)\n\n## API Reference\n\n**Kind**: Exported class  \n* [UsageStats](#exp_module_usage-stats--UsageStats) ⏏\n    * [new UsageStats(trackingId, [options])](#new_module_usage-stats--UsageStats_new)\n    * [.dir](#module_usage-stats--UsageStats.UsageStats+dir) : <code>string</code>\n    * [.defaults](#module_usage-stats--UsageStats.UsageStats+defaults) : <code>Map</code>\n    * [.start([sessionParams])](#module_usage-stats--UsageStats+start) ↩︎\n    * [.end([sessionParams])](#module_usage-stats--UsageStats+end) ↩︎\n    * [.disable()](#module_usage-stats--UsageStats+disable) ↩︎\n    * [.enable()](#module_usage-stats--UsageStats+enable) ↩︎\n    * [.event(category, action, [options])](#module_usage-stats--UsageStats+event) ⇒ <code>Map</code>\n    * [.screenView(name, [options])](#module_usage-stats--UsageStats+screenView) ⇒ <code>Map</code>\n    * [.exception([options])](#module_usage-stats--UsageStats+exception) ⇒ <code>Map</code>\n    * [.send([options])](#module_usage-stats--UsageStats+send) ⇒ <code>Promise</code>\n    * [.debug()](#module_usage-stats--UsageStats+debug) ⇒ <code>Promise</code>\n    * [.abort()](#module_usage-stats--UsageStats+abort) ↩︎\n\n<a name=\"new_module_usage-stats--UsageStats_new\"></a>\n\n### new UsageStats(trackingId, [options])\n\n| Param | Type | Description |\n| --- | --- | --- |\n| trackingId | <code>string</code> | Google Analytics tracking ID (required). |\n| [options] | <code>object</code> |  |\n| [options.an] | <code>string</code> | App name |\n| [options.av] | <code>string</code> | App version |\n| [options.lang] | <code>string</code> | Language. Defaults to `process.env.LANG`. |\n| [options.sr] | <code>string</code> | Screen resolution. Defaults to `${process.stdout.rows}x${process.stdout.columns}`. |\n| [options.ua] | <code>string</code> | User Agent string to use. |\n| [options.dir] | <code>string</code> | Path of the directory used for persisting clientID and queue. Defaults to `~/.usage-stats`. |\n| [options.url] | <code>string</code> | Defaults to `'https://www.google-analytics.com/batch'`. |\n| [options.debugUrl] | <code>string</code> | Defaults to `'https://www.google-analytics.com/debug/collect'`. |\n\n**Example**  \n```js\nconst usageStats = new UsageStats('UA-98765432-1', {\n  an: 'sick app',\n  av: '1.0.0'\n})\n```\n<a name=\"module_usage-stats--UsageStats.UsageStats+dir\"></a>\n\n### usageStats.dir : <code>string</code>\nCache directory. Defaults to `~/.usage-stats`.\n\n**Kind**: instance property of [<code>UsageStats</code>](#exp_module_usage-stats--UsageStats)  \n<a name=\"module_usage-stats--UsageStats.UsageStats+defaults\"></a>\n\n### usageStats.defaults : <code>Map</code>\nA list of parameters to be to sent with every hit.\n\n**Kind**: instance property of [<code>UsageStats</code>](#exp_module_usage-stats--UsageStats)  \n**Example**  \n```js\nusageStats.defaults\n  .set('cd1', process.version)\n  .set('cd2', os.type())\n  .set('cd3', os.release())\n  .set('cd4', 'api')\n```\n<a name=\"module_usage-stats--UsageStats+start\"></a>\n\n### usageStats.start([sessionParams]) ↩︎\nStarts the [session](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#sc).\n\n**Kind**: instance method of [<code>UsageStats</code>](#exp_module_usage-stats--UsageStats)  \n**Chainable**  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| [sessionParams] | <code>Array.&lt;Map&gt;</code> | An optional map of paramaters to send with each hit in the sesison. |\n\n<a name=\"module_usage-stats--UsageStats+end\"></a>\n\n### usageStats.end([sessionParams]) ↩︎\nEnds the [session](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#sc).\n\n**Kind**: instance method of [<code>UsageStats</code>](#exp_module_usage-stats--UsageStats)  \n**Chainable**  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| [sessionParams] | <code>Array.&lt;Map&gt;</code> | An optional map of paramaters to send with the final hit of this sesison. |\n\n<a name=\"module_usage-stats--UsageStats+disable\"></a>\n\n### usageStats.disable() ↩︎\nDisable the module. While disabled, all operations are no-ops.\n\n**Kind**: instance method of [<code>UsageStats</code>](#exp_module_usage-stats--UsageStats)  \n**Chainable**  \n<a name=\"module_usage-stats--UsageStats+enable\"></a>\n\n### usageStats.enable() ↩︎\nRe-enable the module.\n\n**Kind**: instance method of [<code>UsageStats</code>](#exp_module_usage-stats--UsageStats)  \n**Chainable**  \n<a name=\"module_usage-stats--UsageStats+event\"></a>\n\n### usageStats.event(category, action, [options]) ⇒ <code>Map</code>\nTrack an event. All event hits are queued until `.send()` is called.\n\n**Kind**: instance method of [<code>UsageStats</code>](#exp_module_usage-stats--UsageStats)  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| category | <code>string</code> | Event category (required). |\n| action | <code>string</code> | Event action (required). |\n| [options] | <code>option</code> |  |\n| [options.el] | <code>string</code> | Event label |\n| [options.ev] | <code>string</code> | Event value |\n| [options.hitParams] | <code>Array.&lt;map&gt;</code> | One or more additional params to send with the hit. |\n\n<a name=\"module_usage-stats--UsageStats+screenView\"></a>\n\n### usageStats.screenView(name, [options]) ⇒ <code>Map</code>\nTrack a screenview. All screenview hits are queued until `.send()` is called. Returns the hit instance.\n\n**Kind**: instance method of [<code>UsageStats</code>](#exp_module_usage-stats--UsageStats)  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| name | <code>string</code> | Screen name |\n| [options] | <code>object</code> |  |\n| [options.hitParams] | <code>Array.&lt;map&gt;</code> | One or more additional params to set on the hit. |\n\n<a name=\"module_usage-stats--UsageStats+exception\"></a>\n\n### usageStats.exception([options]) ⇒ <code>Map</code>\nTrack a exception. All exception hits are queued until `.send()` is called.\n\n**Kind**: instance method of [<code>UsageStats</code>](#exp_module_usage-stats--UsageStats)  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| [options] | <code>object</code> | optional params |\n| [options.exd] | <code>string</code> | Error message |\n| [options.exf] | <code>boolean</code> | Set true if the exception was fatal |\n| [options.hitParams] | <code>Array.&lt;map&gt;</code> | One or more additional params to set on the hit. |\n\n<a name=\"module_usage-stats--UsageStats+send\"></a>\n\n### usageStats.send([options]) ⇒ <code>Promise</code>\nSend 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.\n\n**Kind**: instance method of [<code>UsageStats</code>](#exp_module_usage-stats--UsageStats)  \n**Fulfil**: <code>response[]</code> - array of responses. Each response has `data` and the original node `res`.  \n**Reject**: <code>Error</code> - Rejects with the first error encountered. The error is a standard node http error with a `name` of `request-fail` and a `hits` property showing what failed to send.  \n\n| Param | Type |\n| --- | --- |\n| [options] | <code>object</code> | \n| [options.timeout] | <code>number</code> | \n\n<a name=\"module_usage-stats--UsageStats+debug\"></a>\n\n### usageStats.debug() ⇒ <code>Promise</code>\nSend any hits (including queued) to the GA [validation server](https://developers.google.com/analytics/devguides/collection/protocol/v1/validating-hits), fulfilling with the result.\n\n**Kind**: instance method of [<code>UsageStats</code>](#exp_module_usage-stats--UsageStats)  \n**Fulfil**: <code>Response[]</code>  \n**Reject**: <code>Error</code> - Error instance includes `hits`.  \n<a name=\"module_usage-stats--UsageStats+abort\"></a>\n\n### usageStats.abort() ↩︎\nAborts the in-progress .send() operation, queuing any unsent hits.\n\n**Kind**: instance method of [<code>UsageStats</code>](#exp_module_usage-stats--UsageStats)  \n**Chainable**  \n\n* * *\n\n&copy; 2016-23 Lloyd Brookes \\<75pound@gmail.com\\>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).\n","publish_time":1471472619209,"deprecated":"Google no longer maintain the API used by this lib.","_cnpm_publish_time":1471472619209,"dist-tags":{"latest":"0.9.5","prev":"0.8.6"}}