Comparing version 0.1.2 to 0.1.3
@@ -5,5 +5,6 @@ 'use strict'; | ||
var Configstore = require('configstore'); | ||
var colors = require('colors'); | ||
var chalk = require('chalk'); | ||
var _ = require('lodash'); | ||
var inquirer = require('inquirer'); | ||
var providers = require('./providers'); | ||
@@ -19,6 +20,7 @@ | ||
this.trackingCode = options.trackingCode; | ||
this.trackingProvider = options.trackingProvider || 'google'; | ||
this.packageName = options.packageName || this.packageFile.name; | ||
this.packageVersion = options.packageVersion || this.packageFile.version; | ||
this.config = new Configstore('insight-' + this.packageName, { | ||
clientId: Math.floor(Date.now() * Math.random()) | ||
clientId: options.clientId || Math.floor(Date.now() * Math.random()) | ||
}); | ||
@@ -37,21 +39,15 @@ this._queue = {}; | ||
Object.defineProperty(Insight.prototype, 'clientId', { | ||
get: function () { | ||
return this.config.get('clientId'); | ||
}, | ||
set: function (val) { | ||
this.config.set('clientId', val); | ||
} | ||
}); | ||
// debounce in case of rapid .track() invocations | ||
Insight.prototype._save = _.debounce(function () { | ||
var qs = { | ||
v: 1, // GA API version | ||
t: 'pageview', // event type | ||
aip: 1, // anonymize IP | ||
tid: this.trackingCode, | ||
cid: this.config.get('clientId'), | ||
an: this.packageName, | ||
av: this.packageVersion, | ||
z: Date.now() // cache busting | ||
}; | ||
var cp = fork(path.join(__dirname, 'push.js')); | ||
cp.send({ | ||
queue: _.extend({}, this._queue), | ||
packageName: this.packageName, | ||
qs: qs | ||
}); | ||
cp.send(this._getPayload()); | ||
cp.unref(); | ||
@@ -63,4 +59,18 @@ cp.disconnect(); | ||
Insight.prototype._getPayload = function() { | ||
return { | ||
queue: _.extend({}, this._queue), | ||
packageName: this.packageName, | ||
packageVersion: this.packageVersion, | ||
trackingCode: this.trackingCode, | ||
trackingProvider: this.trackingProvider | ||
}; | ||
}; | ||
Insight.prototype.getRequest = function() { | ||
return providers[this.trackingProvider].apply(this, arguments); | ||
}; | ||
Insight.prototype.track = function () { | ||
if (this.config.get('optOut')) { | ||
if (this.optOut) { | ||
return; | ||
@@ -79,3 +89,3 @@ } | ||
Insight.prototype.askPermission = function (msg, cb) { | ||
var defaultMsg = 'May ' + this.packageName.cyan + ' anonymously report usage statistics to improve the tool over time?'; | ||
var defaultMsg = 'May ' + chalk.cyan(this.packageName) + ' anonymously report usage statistics to improve the tool over time?'; | ||
@@ -82,0 +92,0 @@ cb = cb || function () {}; |
'use strict'; | ||
var request = require('request'); | ||
var Configstore = require('configstore'); | ||
var async = require('async'); | ||
var _ = require('lodash'); | ||
var Insight = require('./insight'); | ||
var BASE_URL = 'http://www.google-analytics.com/collect/__utm.gif'; | ||
// Messaged on each debounced track() | ||
@@ -13,4 +11,4 @@ // Gets the queue, merges is with the previous and tries to upload everything | ||
process.on('message', function(msg) { | ||
var config = new Configstore('insight-' + msg.packageName); | ||
var qs = msg.qs; | ||
var insight = new Insight(msg); | ||
var config = insight.config; | ||
var q = config.get('queue') || {}; | ||
@@ -26,7 +24,3 @@ | ||
qs.dp = path; | ||
// queue time - delta (ms) between now and track time | ||
qs.qt = Date.now() - parseInt(id, 10); | ||
request.get(BASE_URL, {qs: qs}, function(error) { | ||
request(insight.getRequest(id, path), function(error) { | ||
if (error) { | ||
@@ -33,0 +27,0 @@ return cb(error); |
{ | ||
"name": "insight", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Understand how your tool is being used by anonymously reporting usage metrics to Google Analytics", | ||
@@ -30,11 +30,11 @@ "keywords": [ | ||
"dependencies": { | ||
"colors": "~0.6.0-1", | ||
"request": "~2.12.0", | ||
"chalk": "~0.2.0", | ||
"request": "~2.26.0", | ||
"configstore": "~0.1.0", | ||
"async": "~0.1.22", | ||
"lodash": "~1.0.0-rc.2", | ||
"inquirer": "~0.1.9" | ||
"async": "~0.2.9", | ||
"lodash": "~1.3.1", | ||
"inquirer": "~0.2.4" | ||
}, | ||
"devDependencies": { | ||
"mocha": "~1.7.4" | ||
"mocha": "~1.12.0" | ||
}, | ||
@@ -41,0 +41,0 @@ "engines": { |
# Insight [![Build Status](https://secure.travis-ci.org/yeoman/insight.png?branch=master)](http://travis-ci.org/yeoman/insight) | ||
Understand how your tool is being used by anonymously reporting usage metrics to [Google Analytics](http://www.google.com/analytics/) | ||
or [Yandex.Metrica](http://metrica.yandex.com/) | ||
@@ -17,2 +18,4 @@ *This module uses the [newly released Universal Analytics API](http://analytics.blogspot.com/2013/03/expanding-universal-analytics-into.html) from Google Analytics* | ||
*Google Analytics* | ||
```js | ||
@@ -35,5 +38,24 @@ var Insight = require('insight'); | ||
*Yandex.Metrica* | ||
```js | ||
var Insight = require('insight'); | ||
var insight = new Insight({ | ||
// Yandex.Metrica counter id | ||
trackingCode: 'XXXXXXXXX' | ||
trackingProvider: 'yandex' | ||
}); | ||
// ask for permission the first time | ||
if (insight.optOut === undefined) { | ||
return insight.askPermission(); | ||
} | ||
insight.track('foo', 'bar'); | ||
// recorded in Yandex.Metrica as `http://<package-name>.insight/foo/bar` | ||
``` | ||
or a [live example](https://github.com/yeoman/yeoman) | ||
## Documentation | ||
@@ -49,5 +71,15 @@ | ||
Your Google Analytics [trackingCode](https://support.google.com/analytics/bin/answer.py?hl=en&answer=1008080) | ||
Your Google Analytics [trackingCode](https://support.google.com/analytics/bin/answer.py?hl=en&answer=1008080) or | ||
Yandex.Metrica [counter id](http://help.yandex.com/metrika/?id=1121963). | ||
#### trackingProvider | ||
Type: `string` | ||
Default: `'google'` | ||
Tracking provider to use | ||
Possible values are `'google'` or `'yandex'` | ||
#### packagePath | ||
@@ -54,0 +86,0 @@ |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
9360
6
173
135
2
+ Addedchalk@~0.2.0
+ Addedansi-styles@0.2.0(transitive)
+ Addedasn1@0.1.11(transitive)
+ Addedassert-plus@0.1.5(transitive)
+ Addedasync@0.9.2(transitive)
+ Addedaws-sign@0.3.0(transitive)
+ Addedboom@0.4.2(transitive)
+ Addedchalk@0.2.1(transitive)
+ Addedcombined-stream@0.0.7(transitive)
+ Addedcookie-jar@0.3.0(transitive)
+ Addedcryptiles@0.2.2(transitive)
+ Addedctype@0.5.3(transitive)
+ Addeddelayed-stream@0.0.5(transitive)
+ Addedforever-agent@0.5.2(transitive)
+ Addedform-data@0.1.4(transitive)
+ Addedhas-color@0.1.7(transitive)
+ Addedhawk@1.0.0(transitive)
+ Addedhoek@0.9.1(transitive)
+ Addedhttp-signature@0.10.1(transitive)
+ Addedinquirer@0.2.5(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedlodash@1.3.1(transitive)
+ Addedmime@1.2.11(transitive)
+ Addednode-uuid@1.4.8(transitive)
+ Addedoauth-sign@0.3.0(transitive)
+ Addedqs@0.6.6(transitive)
+ Addedrequest@2.26.0(transitive)
+ Addedsntp@0.2.4(transitive)
+ Addedtunnel-agent@0.3.0(transitive)
- Removedcolors@~0.6.0-1
- Removedasync@0.1.22(transitive)
- Removedcolors@0.6.2(transitive)
- Removedinquirer@0.1.12(transitive)
- Removedlodash@1.0.2(transitive)
- Removedrequest@2.12.0(transitive)
Updatedasync@~0.2.9
Updatedinquirer@~0.2.4
Updatedlodash@~1.3.1
Updatedrequest@~2.26.0