insight-keen-io
Advanced tools
Comparing version 0.7.2 to 0.8.0
@@ -6,2 +6,10 @@ # Change Log | ||
## v0.8.0 - (2015-12-29) | ||
* Enhancements | ||
* [Core] Removing unnecessary dependencies; | ||
* Bug | ||
* [Core] Fixing to use queue and not '_data' to send analytics informations; | ||
## v0.7.2 - (2015-12-29) | ||
@@ -8,0 +16,0 @@ |
'use strict'; | ||
var path = require('path'); | ||
var spawn = require('child_process').spawn; | ||
var Configstore = require('configstore'); | ||
var assign = require('object-assign'); | ||
var debounce = require('lodash.debounce'); | ||
var path = require('path'); | ||
var spawn = require('child_process').spawn; | ||
var lodash = require('lodash'); | ||
var BPromise = require("bluebird"); | ||
var providers = require('./providers'); | ||
var BPromise = require("bluebird"); | ||
@@ -27,41 +26,19 @@ function InsightKeenIo (options) { | ||
var clientId = options.clientId || Math.floor(Date.now() * Math.random()); | ||
var config_store_name = 'InsightKeenIo-' + this.projectId; | ||
this.config = options.config || new Configstore(config_store_name, {clientId: clientId}); | ||
this._queue = {}; | ||
} | ||
Object.defineProperty(InsightKeenIo.prototype, 'clientId', { | ||
get: function () { | ||
return this.config.get('clientId'); | ||
}, | ||
set: function (val) { | ||
this.config.set('clientId', val); | ||
} | ||
}); | ||
// debounce in case of rapid .track() invocations | ||
InsightKeenIo.prototype._save = debounce(function (save_cb) { | ||
if (this.send_in_background) { | ||
var child = spawn('node', [path.join(__dirname, 'push.js')], { | ||
detached: true, | ||
stdio : [null, null, null, 'pipe'], | ||
}); | ||
InsightKeenIo.prototype._save = lodash.debounce(function() { | ||
var child = spawn('node', [path.join(__dirname, 'push.js')], { | ||
detached: true, | ||
stdio : [null, process.stdout, process.stdout, 'pipe'], | ||
}); | ||
// Send configs to child | ||
var pipe = child.stdio[3]; | ||
var buff = Buffer(JSON.stringify(this._getPayload())); | ||
pipe.write(buff); | ||
// Send configs to child | ||
var pipe = child.stdio[3]; | ||
var buff = Buffer(JSON.stringify(this._getPayload())); | ||
pipe.write(buff); | ||
child.unref(); | ||
this._queue = {}; | ||
return save_cb(0); | ||
} else { | ||
var requestPush = require('./request-push'); | ||
requestPush(this._getPayload(), save_cb); | ||
} | ||
child.unref(); | ||
this._queue = {}; | ||
}, 100); | ||
@@ -71,13 +48,9 @@ | ||
return { | ||
queue: assign({}, this._queue), | ||
queue: lodash.clone(this._queue), | ||
projectId: this.projectId, | ||
writeKey: this.writeKey, | ||
eventCollection: this._eventCollection, | ||
data: this._data, | ||
}; | ||
}; | ||
InsightKeenIo.prototype._getRequestObj = function () { | ||
InsightKeenIo.prototype.requestParams = function () { | ||
return providers[this.trackingProvider].apply(this, arguments); | ||
@@ -87,16 +60,22 @@ }; | ||
InsightKeenIo.prototype.track = function (eventCollection, data) { | ||
var deferred = BPromise.pending(); | ||
var self = this; | ||
return new BPromise.Promise(function(fulfill) { | ||
// timestamp isn't unique enough since it can end up with duplicate entries | ||
self._queue[Date.now() + ' ' + eventCollection] = { | ||
collection: eventCollection, | ||
event: data, | ||
}; | ||
// timestamp isn't unique enough since it can end up with duplicate entries | ||
this._eventCollection = eventCollection; | ||
this._data = data; | ||
this._queue[Date.now() + ' ' + eventCollection] = data; | ||
var resolve = function(result) { fulfill(result || 0); }; | ||
this._save(function (result) { | ||
deferred.fulfill(result); | ||
}); | ||
return deferred.promise; | ||
if (!self.send_in_background) { | ||
var requestPush = require('./request-push'); | ||
requestPush(self._getPayload(), resolve); | ||
} else { | ||
self._save(); | ||
resolve(); | ||
} | ||
}); | ||
}; | ||
module.exports = InsightKeenIo; |
@@ -15,6 +15,4 @@ 'use strict'; | ||
}; | ||
return options; | ||
} | ||
}; |
@@ -7,3 +7,3 @@ 'use strict'; | ||
var stream = new net.Socket({ fd: 3 }); | ||
let jstream = new JStream(); | ||
var jstream = new JStream(); | ||
@@ -14,4 +14,3 @@ stream.pipe(jstream).on('data', function(data) { | ||
stream.end(); | ||
process.exit(0); | ||
}); | ||
}); |
'use strict'; | ||
var lodash = require('lodash'); | ||
var request = require('request'); | ||
var async = require('async'); | ||
var assign = require('object-assign'); | ||
var async = require('async'); | ||
var InsightKeenIo = require('./'); | ||
var _ = require('lodash'); | ||
module.exports = function (msg, parent_callback) { | ||
var eventCollection = msg.eventCollection; | ||
var analyticsData = msg.data; | ||
var insight = new InsightKeenIo(msg); | ||
var config = insight.config; | ||
var queue = config.get('queue') || {}; | ||
assign(queue, msg.queue); | ||
config.del('queue'); | ||
var results = []; | ||
async.eachSeries(_.values(queue), function (item, cb) { | ||
var options = insight._getRequestObj(eventCollection, analyticsData); | ||
async.eachSeries(lodash.values(msg.queue), function (item, cb) { | ||
var options = insight.requestParams(item.collection, item.event); | ||
request(options, function (err, res, body) { | ||
if (err) { | ||
console.error(err); | ||
cb(err); | ||
return; | ||
return cb(err); | ||
} | ||
results.push(body); | ||
cb(); | ||
}); | ||
}, function (err) { | ||
if (err) { | ||
var queue2 = config.get('queue') || {}; | ||
assign(queue2, queue); | ||
config.set('queue', queue2); | ||
console.error(err); | ||
} | ||
parent_callback(results); | ||
}); | ||
}; |
{ | ||
"name": "insight-keen-io", | ||
"version": "0.7.2", | ||
"version": "0.8.0", | ||
"description": "Understand how your tool is being used by anonymously reporting usage metrics to an analtyics vendor, e.g. Google Analytics.", | ||
@@ -42,10 +42,5 @@ "keywords": [ | ||
"bluebird": "^2.9.27", | ||
"configstore": "^0.3.1", | ||
"jstream": "^0.2.8", | ||
"lodash": "^3.6.0", | ||
"lodash.debounce": "^3.0.1", | ||
"object-assign": "^2.0.0", | ||
"request": "^2.45.0", | ||
"satelize": "^0.1.1", | ||
"tough-cookie": "^0.12.1" | ||
"request": "^2.45.0" | ||
}, | ||
@@ -52,0 +47,0 @@ "devDependencies": { |
5
5481
111
- Removedconfigstore@^0.3.1
- Removedlodash.debounce@^3.0.1
- Removedobject-assign@^2.0.0
- Removedsatelize@^0.1.1
- Removedtough-cookie@^0.12.1
- Removedargparse@1.0.10(transitive)
- Removedconfigstore@0.3.2(transitive)
- Removedesprima@4.0.1(transitive)
- Removedgraceful-fs@3.0.12(transitive)
- Removedjs-yaml@3.14.1(transitive)
- Removedlodash._getnative@3.9.1(transitive)
- Removedlodash.debounce@3.1.1(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removednatives@1.1.6(transitive)
- Removedobject-assign@2.1.1(transitive)
- Removedos-homedir@1.0.2(transitive)
- Removedos-tmpdir@1.0.2(transitive)
- Removedosenv@0.1.5(transitive)
- Removedsatelize@0.1.2(transitive)
- Removedsprintf-js@1.0.3(transitive)
- Removedtough-cookie@0.12.1(transitive)
- Removeduser-home@1.1.1(transitive)
- Removeduuid@2.0.3(transitive)
- Removedxdg-basedir@1.0.1(transitive)