app-usage-stats
Advanced tools
Comparing version 0.2.1 to 0.3.0
@@ -24,8 +24,6 @@ 'use strict'; | ||
function AppUsageStats(tid, appName, options) { | ||
function AppUsageStats(tid, options) { | ||
_classCallCheck(this, AppUsageStats); | ||
if (!appName) throw new Error('an appName is required'); | ||
options = options || {}; | ||
options.name = appName; | ||
@@ -50,3 +48,3 @@ var _this = _possibleConstructorReturn(this, (AppUsageStats.__proto__ || Object.getPrototypeOf(AppUsageStats)).call(this, tid, options)); | ||
key: 'hit', | ||
value: function hit(dimension, metric) { | ||
value: function hit(dimension, metric, options) { | ||
this.unsent.add({ dimension: dimension, metric: metric }); | ||
@@ -56,3 +54,3 @@ | ||
if (Date.now() - this._lastSent >= this.sendInterval) { | ||
return this.send(); | ||
return this.send(options); | ||
} else { | ||
@@ -225,3 +223,3 @@ return Promise.resolve([]); | ||
key: 'send', | ||
value: function send() { | ||
value: function send(options) { | ||
var _this4 = this; | ||
@@ -233,3 +231,3 @@ | ||
this._lastSent = Date.now(); | ||
return _get(AppUsageStats.prototype.__proto__ || Object.getPrototypeOf(AppUsageStats.prototype), 'send', this).call(this).then(function (responses) { | ||
return _get(AppUsageStats.prototype.__proto__ || Object.getPrototypeOf(AppUsageStats.prototype), 'send', this).call(this, options).then(function (responses) { | ||
_this4.sent.add(toSend); | ||
@@ -236,0 +234,0 @@ return responses; |
@@ -40,3 +40,3 @@ 'use strict'; | ||
runner.test('.hit(dimensions, metrics)', function () { | ||
var usage = new TrackUsage(tid, 'testsuite'); | ||
var usage = new TrackUsage(tid); | ||
usage.hit({ name: 'method1', interface: 'cli' }, { option1: 1, option2: 1 }); | ||
@@ -43,0 +43,0 @@ usage.hit({ name: 'method1', interface: 'api' }, { option1: 1, option3: 1 }); |
@@ -40,3 +40,3 @@ 'use strict'; | ||
runner.test('.hit(dimensions, metrics)', function () { | ||
var usage = new TrackUsage(tid, 'testsuite'); | ||
var usage = new TrackUsage(tid); | ||
usage.hit({ name: 'method1', interface: 'cli' }, { option1: 1, option2: 1 }); | ||
@@ -78,3 +78,3 @@ usage.hit({ name: 'method1', interface: 'api' }, { option1: 1, option3: 1 }); | ||
runner.test('._convertToHits()', function () { | ||
var usage = new TrackUsage(tid, 'testsuite', { | ||
var usage = new TrackUsage(tid, { | ||
dimensionMap: { | ||
@@ -116,3 +116,3 @@ name: 'screenview', | ||
runner.test('.save() and .load(): this.stats correct', function () { | ||
var usage = new TrackUsage(tid, 'testsuite', { dir: 'tmp/test' }); | ||
var usage = new TrackUsage(tid, { dir: 'tmp/test' }); | ||
usage.hit({ name: 'one' }, { metric: 1 }); | ||
@@ -130,3 +130,3 @@ usage.hit({ name: 'one' }, { metric: 1 }); | ||
runner.test('.saveSync() and .loadSync(): this.stats correct', function () { | ||
var usage = new TrackUsage(tid, 'testsuite', { dir: 'tmp/test' }); | ||
var usage = new TrackUsage(tid, { dir: 'tmp/test' }); | ||
usage.hit({ name: 'one' }, { metric: 1 }); | ||
@@ -143,3 +143,3 @@ usage.hit({ name: 'one' }, { metric: 1 }); | ||
runner.test('.hit(): auto-sends after given interval', function () { | ||
var usage = new TrackUsage(tid, 'testsuite', { sendInterval: 200, dir: 'tmp/test' }); | ||
var usage = new TrackUsage(tid, { sendInterval: 200, dir: 'tmp/test' }); | ||
return Promise.all([usage.hit({ name: 'one' }, { metric: 1 }).then(responseCount(0)), usage.hit({ name: 'one' }, { metric: 1 }).then(responseCount(0)), delay(210).then(unsentCount(usage, 1)).then(function () { | ||
@@ -151,3 +151,3 @@ return usage.hit({ name: 'one' }, { metric: 1 }).then(responseCount(1)).then(sentCount(usage, 1)).then(unsentCount(usage, 0)); | ||
runner.test('.send(): this.stats correct after', function () { | ||
var usage = new TrackUsage(tid, 'testsuite', { dir: 'tmp/test' }); | ||
var usage = new TrackUsage(tid, { dir: 'tmp/test' }); | ||
usage.hit({ name: 'one' }, { metric: 1 }); | ||
@@ -160,3 +160,3 @@ usage.hit({ name: 'one' }, { metric: 1 }); | ||
runner.test('.send(): this.stats correct after ongoing hits', function () { | ||
var usage = new TrackUsage(tid, 'testsuite', { dir: 'tmp/test' }); | ||
var usage = new TrackUsage(tid, { dir: 'tmp/test' }); | ||
usage.hit({ name: 'one' }, { metric: 1 }); | ||
@@ -173,3 +173,3 @@ usage.hit({ name: 'one' }, { metric: 1 }); | ||
runner.test('.send(): multiple invocations', function () { | ||
var usage = new TrackUsage(tid, 'testsuite', { dir: 'tmp/test' }); | ||
var usage = new TrackUsage(tid, { dir: 'tmp/test' }); | ||
usage.hit({ name: 'one' }, { metric: 1 }); | ||
@@ -176,0 +176,0 @@ usage.hit({ name: 'one' }, { metric: 1 }); |
{ | ||
"name": "app-usage-stats", | ||
"author": "Lloyd Brookes <75pound@gmail.com>", | ||
"version": "0.2.1", | ||
"description": "app-usage-stats", | ||
"version": "0.3.0", | ||
"description": "A convention for tracking javascript application usage", | ||
"repository": "https://github.com/75lb/app-usage-stats.git", | ||
@@ -20,7 +20,7 @@ "license": "MIT", | ||
"array-back": "^1.0.3", | ||
"babel-preset-es2015": "^6.14.0", | ||
"babel-preset-es2015": "^6.16.0", | ||
"feature-detect-es6": "^1.3.1", | ||
"home-path": "^1.0.3", | ||
"test-value": "^2.1.0", | ||
"usage-stats": "^0.6.0" | ||
"usage-stats": "^0.7.0" | ||
}, | ||
@@ -27,0 +27,0 @@ "devDependencies": { |
@@ -10,2 +10,4 @@ [![view on npm](http://img.shields.io/npm/v/app-usage-stats.svg)](https://www.npmjs.org/package/app-usage-stats) | ||
## app-usage-stats | ||
A convention for tracking javascript application usage. | ||
**Example** | ||
@@ -19,7 +21,7 @@ ```js | ||
* [AppUsageStats](#exp_module_app-usage-stats--AppUsageStats) ⏏ | ||
* [new AppUsageStats(tid, appName, [options])](#new_module_app-usage-stats--AppUsageStats_new) | ||
* [new AppUsageStats(tid, [options])](#new_module_app-usage-stats--AppUsageStats_new) | ||
* [.unsent](#module_app-usage-stats--AppUsageStats.AppUsageStats+unsent) : <code>Array.<object></code> | ||
* [.sent](#module_app-usage-stats--AppUsageStats.AppUsageStats+sent) : <code>Array.<object></code> | ||
* [.queuePath](#module_app-usage-stats--AppUsageStats.AppUsageStats+queuePath) : <code>string</code> | ||
* [.hit(dimension, metric)](#module_app-usage-stats--AppUsageStats+hit) | ||
* [.hit(dimension, metric, [options])](#module_app-usage-stats--AppUsageStats+hit) | ||
* [.save()](#module_app-usage-stats--AppUsageStats+save) | ||
@@ -29,3 +31,3 @@ * [.saveSync()](#module_app-usage-stats--AppUsageStats+saveSync) | ||
* [.loadSync()](#module_app-usage-stats--AppUsageStats+loadSync) | ||
* [.send()](#module_app-usage-stats--AppUsageStats+send) | ||
* [.send([options])](#module_app-usage-stats--AppUsageStats+send) | ||
@@ -38,3 +40,3 @@ <a name="exp_module_app-usage-stats--AppUsageStats"></a> | ||
#### new AppUsageStats(tid, appName, [options]) | ||
#### new AppUsageStats(tid, [options]) | ||
@@ -44,3 +46,2 @@ | Param | Type | Description | | ||
| tid | <code>string</code> | Google Analytics tracking ID | | ||
| appName | <code>string</code> | App name | | ||
| [options] | <code>object</code> | | | ||
@@ -71,3 +72,3 @@ | [options.dimensionMap] | <code>object</code> | A custom dimension name to ID Map. | | ||
#### stats.hit(dimension, metric) | ||
#### stats.hit(dimension, metric, [options]) | ||
Track a hit. The magic dimension `name` will be mapped to a GA screenView. | ||
@@ -81,2 +82,4 @@ | ||
| metric | <code>Array.<object></code> | metric-value maps | | ||
| [options] | <code>object</code> | | | ||
| [options.timeout] | <code>number</code> | A maxium wait period in ms, after which any pending requests will be aborted. | | ||
@@ -109,3 +112,3 @@ <a name="module_app-usage-stats--AppUsageStats+save"></a> | ||
#### stats.send() | ||
#### stats.send([options]) | ||
Send and reset stats. | ||
@@ -115,4 +118,10 @@ | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| [options] | <code>object</code> | | | ||
| [options.timeout] | <code>number</code> | A maxium wait period in ms, after which any pending requests will be aborted. | | ||
* * * | ||
© 2016 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown). |
@@ -11,2 +11,3 @@ 'use strict' | ||
/** | ||
* A convention for tracking javascript application usage. | ||
* @module app-usage-stats | ||
@@ -25,3 +26,2 @@ * @example | ||
* @param {string} - Google Analytics tracking ID | ||
* @param {string} - App name | ||
* @param [options] {object} | ||
@@ -32,6 +32,4 @@ * @param [options.dimensionMap] {object} - A custom dimension name to ID Map. | ||
*/ | ||
constructor (tid, appName, options) { | ||
if (!appName) throw new Error('an appName is required') | ||
constructor (tid, options) { | ||
options = options || {} | ||
options.name = appName | ||
super(tid, options) | ||
@@ -68,4 +66,6 @@ | ||
* @param {object[]} - metric-value maps | ||
* @param [options] {object} | ||
* @param [options.timeout] {number} - A maxium wait period in ms, after which any pending requests will be aborted. | ||
*/ | ||
hit (dimension, metric) { | ||
hit (dimension, metric, options) { | ||
this.unsent.add({ dimension, metric }) | ||
@@ -76,3 +76,3 @@ | ||
if (Date.now() - this._lastSent >= this.sendInterval) { | ||
return this.send() | ||
return this.send(options) | ||
} else { | ||
@@ -183,4 +183,6 @@ return Promise.resolve([]) | ||
* Send and reset stats. | ||
*/ | ||
send () { | ||
* @param [options] {object} | ||
* @param [options.timeout] {number} - A maxium wait period in ms, after which any pending requests will be aborted. | ||
*/ | ||
send (options) { | ||
this._convertToHits() | ||
@@ -190,3 +192,3 @@ const toSend = clone(this.unsent.stats) | ||
this._lastSent = Date.now() | ||
return super.send() | ||
return super.send(options) | ||
.then(responses => { | ||
@@ -193,0 +195,0 @@ this.sent.add(toSend) |
@@ -40,3 +40,3 @@ 'use strict' | ||
runner.test('.hit(dimensions, metrics)', function () { | ||
const usage = new TrackUsage(tid, 'testsuite') | ||
const usage = new TrackUsage(tid) | ||
usage.hit({ name: 'method1', interface: 'cli' }, { option1: 1, option2: 1 }) | ||
@@ -43,0 +43,0 @@ usage.hit({ name: 'method1', interface: 'api' }, { option1: 1, option3: 1 }) |
@@ -40,3 +40,3 @@ 'use strict' | ||
runner.test('.hit(dimensions, metrics)', function () { | ||
const usage = new TrackUsage(tid, 'testsuite') | ||
const usage = new TrackUsage(tid) | ||
usage.hit({ name: 'method1', interface: 'cli' }, { option1: 1, option2: 1 }) | ||
@@ -82,3 +82,3 @@ usage.hit({ name: 'method1', interface: 'api' }, { option1: 1, option3: 1 }) | ||
runner.test('._convertToHits()', function () { | ||
const usage = new TrackUsage(tid, 'testsuite', { | ||
const usage = new TrackUsage(tid, { | ||
dimensionMap: { | ||
@@ -120,3 +120,3 @@ name: 'screenview', | ||
runner.test('.save() and .load(): this.stats correct', function () { | ||
const usage = new TrackUsage(tid, 'testsuite', { dir: 'tmp/test' }) | ||
const usage = new TrackUsage(tid, { dir: 'tmp/test' }) | ||
usage.hit({ name: 'one' }, { metric: 1 }) | ||
@@ -142,3 +142,3 @@ usage.hit({ name: 'one' }, { metric: 1 }) | ||
runner.test('.saveSync() and .loadSync(): this.stats correct', function () { | ||
const usage = new TrackUsage(tid, 'testsuite', { dir: 'tmp/test' }) | ||
const usage = new TrackUsage(tid, { dir: 'tmp/test' }) | ||
usage.hit({ name: 'one' }, { metric: 1 }) | ||
@@ -160,3 +160,3 @@ usage.hit({ name: 'one' }, { metric: 1 }) | ||
runner.test('.hit(): auto-sends after given interval', function () { | ||
const usage = new TrackUsage(tid, 'testsuite', { sendInterval: 200, dir: 'tmp/test' }) | ||
const usage = new TrackUsage(tid, { sendInterval: 200, dir: 'tmp/test' }) | ||
return Promise.all([ | ||
@@ -178,3 +178,3 @@ usage.hit({ name: 'one' }, { metric: 1 }).then(responseCount(0)), | ||
runner.test('.send(): this.stats correct after', function () { | ||
const usage = new TrackUsage(tid, 'testsuite', { dir: 'tmp/test' }) | ||
const usage = new TrackUsage(tid, { dir: 'tmp/test' }) | ||
usage.hit({ name: 'one' }, { metric: 1 }) | ||
@@ -190,3 +190,3 @@ usage.hit({ name: 'one' }, { metric: 1 }) | ||
runner.test('.send(): this.stats correct after ongoing hits', function () { | ||
const usage = new TrackUsage(tid, 'testsuite', { dir: 'tmp/test' }) | ||
const usage = new TrackUsage(tid, { dir: 'tmp/test' }) | ||
usage.hit({ name: 'one' }, { metric: 1 }) | ||
@@ -206,3 +206,3 @@ usage.hit({ name: 'one' }, { metric: 1 }) | ||
runner.test('.send(): multiple invocations', function () { | ||
const usage = new TrackUsage(tid, 'testsuite', { dir: 'tmp/test' }) | ||
const usage = new TrackUsage(tid, { dir: 'tmp/test' }) | ||
usage.hit({ name: 'one' }, { metric: 1 }) | ||
@@ -209,0 +209,0 @@ usage.hit({ name: 'one' }, { metric: 1 }) |
@@ -1,1 +0,1 @@ | ||
1474932161456 | ||
1475181746868 |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
52623
119
+ Addedusage-stats@0.7.0(transitive)
- Removedusage-stats@0.6.0(transitive)
Updatedbabel-preset-es2015@^6.16.0
Updatedusage-stats@^0.7.0