Skip to content

Commit

Permalink
Closes #47. Switch Analytics from Google Analytics to Segment.io
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavin001 committed Aug 3, 2014
1 parent dc4339b commit fabed8f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 27 deletions.
5 changes: 4 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@
"unused": true,
"strict": true,
"trailing": true,
"smarttabs": true
"smarttabs": true,
"globals": {
"atom": true
}
}
49 changes: 25 additions & 24 deletions lib/language-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
}
});

},

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit fabed8f

Please sign in to comment.