From 1c4e7e2992df428f5ed8086ca6729436761c5fb1 Mon Sep 17 00:00:00 2001 From: Jeff Escalante Date: Tue, 21 Jun 2016 13:44:33 -0400 Subject: [PATCH 1/2] add basic analytics --- lib/index.js | 23 +++++++++++++++++------ package.json | 3 ++- readme.md | 4 ++++ test/index.js | 4 ++++ 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/lib/index.js b/lib/index.js index 5c50fba..7d2105c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -2,11 +2,13 @@ * @module CLI */ -const EventEmitter = require('events').EventEmitter +const EventEmitter = require('events') +const GA = require('universal-analytics') const ArgumentParser = require('argparse').ArgumentParser const reduce = require('lodash.reduce') const pkg = require('../package.json') -let Spike = require('spike-core') // this is a let because of test mocking +let Spike = require('spike-core') // mocked in tests +let analytics /** * @class CLI @@ -17,6 +19,9 @@ module.exports = class CLI extends EventEmitter { constructor () { super() + const uid = Spike.globalConfig().id // mocked in tests + analytics = new GA('UA-79663181-1', uid) + this.parser = new ArgumentParser({ version: pkg.version, description: pkg.description, @@ -41,13 +46,16 @@ module.exports = class CLI extends EventEmitter { if (typeof args === 'string') { args = args.split(' ') } args = this.parser.parseArgs(args) - const fn = require(`./${args.fn}`) - delete args.fn - // argparse uses `null` which doesn't get along with joi, so we remove // null values here args = reduce(args, (m, v, k) => { if (v) m[k] = v; return m }, {}) + // anonymous analytics for usage data + analytics.event({ ec: 'cmd', ea: args.fn, ev: JSON.stringify(args) }).send() + + const fn = require(`./${args.fn}`) + delete args.fn + // all CLI modules must return an event emitter of some sort // they should also wait to execute anything until nextTick const emitter = fn(Spike, args) @@ -59,7 +67,10 @@ module.exports = class CLI extends EventEmitter { emitter.on('info', this.emit.bind(this, 'info')) // instance-method-specific - emitter.on('compile', this.emit.bind(this, 'compile')) + emitter.on('compile', (res) => { + analytics.event({ ec: 'core', ea: 'compile' }).send() + this.emit('compile', res) + }) emitter.on('remove', this.emit.bind(this, 'success')) return this diff --git a/package.json b/package.json index 9a39230..d33004c 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,8 @@ "chalk": "^1.1.3", "inquirer": "^1.0.2", "lodash.reduce": "^4.4.0", - "spike-core": "^0.8.0" + "spike-core": "^0.8.0", + "universal-analytics": "^0.3.11" }, "devDependencies": { "ava": "^0.15.2", diff --git a/readme.md b/readme.md index 8b8eafc..2e1a2b6 100644 --- a/readme.md +++ b/readme.md @@ -110,3 +110,7 @@ module.exports = { Since the two configuration files are _merged_, you don't lose all your other settings from the `app.js` file, it just merges in any new ones from `app.production.js`. Very amaze! To change the environment, just pass `--env name` or `-e name` as an argument to the `compile` or `watch` commands. + +### Analytics + +Spike's CLI uses basic analytics in order to get more data about how developers are using Spike, so that we can improve this tool more accurately. Analytics are entirely anonymous and the information we collect is minimal. diff --git a/test/index.js b/test/index.js index 2d86ffa..29028c5 100644 --- a/test/index.js +++ b/test/index.js @@ -48,6 +48,10 @@ SpikeMock.template = { } } +SpikeMock.globalConfig = () => { + return { id: 'TEST' } +} + test.beforeEach((t) => { CLI.__set__('Spike', SpikeMock) cli = new CLI() From aa5ad6f850393a95e181bba046a05048666a9f05 Mon Sep 17 00:00:00 2001 From: Jeff Escalante Date: Tue, 21 Jun 2016 13:49:08 -0400 Subject: [PATCH 2/2] user id fix --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 7d2105c..83887a6 100644 --- a/lib/index.js +++ b/lib/index.js @@ -20,7 +20,7 @@ module.exports = class CLI extends EventEmitter { super() const uid = Spike.globalConfig().id // mocked in tests - analytics = new GA('UA-79663181-1', uid) + analytics = new GA('UA-79663181-1', uid, { strictCidFormat: false }) this.parser = new ArgumentParser({ version: pkg.version,