Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

insight

Package Overview
Dependencies
Maintainers
2
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

insight - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

lib/providers.js

50

lib/insight.js

@@ -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 () {};

14

lib/push.js
'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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc