From fabed8fad30d36c0ffe42ed070f5495a7b7c1b14 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sun, 3 Aug 2014 16:12:07 -0400 Subject: [PATCH] Closes #47. Switch Analytics from Google Analytics to Segment.io --- .jshintrc | 5 ++++- lib/language-options.js | 49 +++++++++++++++++++++-------------------- package.json | 5 +++-- 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/.jshintrc b/.jshintrc index 10efb92..4b83f4a 100644 --- a/.jshintrc +++ b/.jshintrc @@ -15,5 +15,8 @@ "unused": true, "strict": true, "trailing": true, - "smarttabs": true + "smarttabs": true, + "globals": { + "atom": true + } } diff --git a/lib/language-options.js b/lib/language-options.js index b05d285..7dc362e 100644 --- a/lib/language-options.js +++ b/lib/language-options.js @@ -15,7 +15,7 @@ var beautifyPHP = require('./langs/php-beautify'); var beautifyPython = require('./langs/python-beautify'); var beautifyRuby = require('./langs/ruby-beautify'); var beautifyLESS = require('./langs/less-beautify'); -var NA = require('nodealytics'); +var Analytics = require('analytics-node'); var pkg = require('../package.json'); module.exports = { @@ -121,30 +121,31 @@ module.exports = { unsupportedGrammar = true; } - // Google Analytics - if (atom.config.get('atom-beautify.googleAnalytics')) { - NA.initialize('UA-52729731-2', 'https://atom.io/packages/atom-beautify', - function () { - // category, action, label, value - NA.trackEvent('grammar', grammar, function (err, resp) { - // console.log(err, resp); - // if (!err && resp.statusCode === 200) { - // console.log('Event has been tracked with Google Analytics'); - // } - }); - NA.trackEvent('version', pkg.version, function (err, resp) { - // console.log(err, resp); - // if (!err && resp.statusCode === 200) { - // console.log('Event has been tracked with Google Analytics'); - // } - }); - if (unsupportedGrammar) { - NA.trackEvent('unsupportedGrammar', grammar, function (err, resp) { - // - }); - } - }); + // Analytics + var analyticsWriteKey = 'u3c26xkae8'; + // Setup Analytics + var analytics = new Analytics(analyticsWriteKey); + if (!atom.config.get('atom-beautify._analyticsUserId')) { + var uuid = require('node-uuid'); + atom.config.set('atom-beautify._analyticsUserId', uuid.v4()); } + // Setup Analytics User Id + var userId = atom.config.get('atom-beautify._analyticsUserId'); + analytics.identify({ + userId: userId + }); + var version = pkg.version; + analytics.track({ + userId: atom.config.get('atom-beautify._analyticsUserId'), + event: 'Beautify', + properties: { + grammar: grammar, + version: version, + options: allOptions, + label: grammar, + category: version + } + }); }, diff --git a/package.json b/package.json index c138151..9bb8ba8 100644 --- a/package.json +++ b/package.json @@ -73,8 +73,9 @@ "strip-json-comments": "^0.1.3", "js-yaml": "^3.0.2", "temp": "^0.8.0", - "nodealytics": "0.0.6", - "prettydiff": "^1.0.23" + "prettydiff": "^1.0.23", + "node-uuid": "^1.4.1", + "analytics-node": "^1.0.2" }, "activationEvents": [ "beautify"