Skip to content

Commit 70effb9

Browse files
committed
Added Google Analytics
Google Analytics helps keep track of how the package is used. This gives valuable information on what parts of the package to focus efforts on. All collected data is fully anonymous. It can also be opted out of if desired.
1 parent bd3df0e commit 70effb9

13 files changed

+111
-1
lines changed

.jshintrc

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
"devel": true, // Define globals that are usually used for debugging: console, alert, etc.
2121
"globals": { // Define globals that are not defined per default
2222
"window": false,
23+
"navigator": false,
24+
"XMLHttpRequest": false,
2325
"document": false,
2426
"atom": false,
2527
"module": false,

README.md

+17
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,20 @@ to cycle through the errors (in the order they appear, first on stderr then on s
117117

118118
Often, the first error is the most interesting since other errors tend to be secondary faults caused by that first one.
119119
To jump to the first error you can use `cmd-alt-h` (OS X) or `ctrl-alt-h` (Linux/Windows) at any point to go to the first error.
120+
121+
## Analytics
122+
123+
The `atom-build` package uses google analytics to keep track of which features are in use
124+
and at what frequency. This gives the maintainers a sense of what parts of the
125+
package is most important and what parts can be removed.
126+
127+
The data is fully anonymous and can not be tracked back to you in any way.
128+
This is what is collected
129+
130+
* Build triggered, succeeded or failed.
131+
* Which build tool was used.
132+
* Visibility of UI components.
133+
134+
If you really do not want to share this information, you can opt out by disabling
135+
the [metrics package](https://atom.io/packages/metrics). This will disable all analytics
136+
collection, including the one from `atom-build`.

lib/GoogleAnalytics.js

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
'use strict';
2+
3+
var _ = require('lodash');
4+
var querystring = require('querystring');
5+
var cid = require('node-uuid').v4();
6+
7+
module.exports = (function () {
8+
function GoogleAnalytics () {}
9+
10+
GoogleAnalytics.sendEvent = function(category, action, label, value) {
11+
var params = {
12+
t: 'event',
13+
ec: category,
14+
ea: action
15+
};
16+
if (label) {
17+
params.el = label;
18+
}
19+
if (value) {
20+
params.ev = value;
21+
}
22+
23+
GoogleAnalytics.send(params);
24+
};
25+
26+
GoogleAnalytics.send = function (params) {
27+
if (!atom.packages.getActivePackage('metrics')) {
28+
// If the metrics package is disabled, then user has opted out.
29+
return;
30+
}
31+
32+
_.extend(params, GoogleAnalytics.defaultParams());
33+
GoogleAnalytics.request('https://www.google-analytics.com/collect?' + querystring.stringify(params));
34+
};
35+
36+
GoogleAnalytics.request = function (url) {
37+
if (!navigator.onLine) {
38+
return;
39+
}
40+
GoogleAnalytics.post(url);
41+
};
42+
43+
GoogleAnalytics.post = function (url) {
44+
var xhr = new XMLHttpRequest();
45+
xhr.open('POST', url);
46+
xhr.send(null);
47+
};
48+
49+
GoogleAnalytics.defaultParams = function () {
50+
// https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters
51+
return {
52+
v: 1,
53+
tid: 'UA-47615700-5',
54+
cid: cid
55+
};
56+
};
57+
58+
return GoogleAnalytics;
59+
})();

lib/build-view.js

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
var _ = require('lodash');
44
var View = require('atom-space-pen-views').View;
55
var cscompatability = require('./cscompatability');
6+
var GoogleAnalytics = require('./GoogleAnalytics');
67
var Convert = require('ansi-to-html');
78

89
module.exports = (function() {
@@ -117,6 +118,7 @@ module.exports = (function() {
117118
};
118119

119120
BuildView.prototype.toggle = function(event, element) {
121+
GoogleAnalytics.sendEvent('view', 'panel toggled');
120122
this.isAttached() ? this.detach(true) : this.attach(true);
121123
};
122124

@@ -135,6 +137,7 @@ module.exports = (function() {
135137
};
136138

137139
BuildView.prototype.toggleMonocle = function(event, element) {
140+
GoogleAnalytics.sendEvent('view', 'monocle toggled');
138141
if (!this.monocle) {
139142
this.setHeightPercent(atom.config.get('build.monocleHeight'));
140143
this.monocleButton.removeClass('icon-chevron-up').addClass('icon-chevron-down');

lib/build.js

+14
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var XRegExp = require('xregexp').XRegExp;
88

99
var SaveConfirmView = require('./save-confirm-view');
1010
var BuildView = require('./build-view');
11+
var GoogleAnalytics = require('./GoogleAnalytics');
1112
var tools = require('./tools');
1213

1314
module.exports = {
@@ -76,9 +77,11 @@ module.exports = {
7677
atom.commands.add('atom-workspace', 'build:error-match-first', this.errorMatchFirst.bind(this));
7778
atom.commands.add('atom-workspace', 'build:stop', this.stop.bind(this));
7879
atom.commands.add('atom-workspace', 'build:confirm', function() {
80+
GoogleAnalytics.sendEvent('build', 'confirmed');
7981
document.activeElement.click();
8082
});
8183
atom.commands.add('atom-workspace', 'build:no-confirm', function() {
84+
GoogleAnalytics.sendEvent('build', 'not confirmed');
8285
this.saveConfirmView.cancel();
8386
}.bind(this));
8487

@@ -90,9 +93,12 @@ module.exports = {
9093
}
9194
});
9295
});
96+
97+
GoogleAnalytics.sendEvent('core', 'activated');
9398
},
9499

95100
deactivate: function() {
101+
GoogleAnalytics.sendEvent('core', 'deactivated');
96102
if (this.child) {
97103
this.child.kill('SIGKILL');
98104
}
@@ -124,6 +130,7 @@ module.exports = {
124130
if (!tool.isEligable(path)) {
125131
return;
126132
}
133+
GoogleAnalytics.sendEvent('build', 'tool selected', tool.niceName);
127134
cmd = _.defaults(tool.settings(path), cmd);
128135
return true;
129136
});
@@ -174,6 +181,7 @@ module.exports = {
174181

175182
},
176183
errorMatch: function() {
184+
GoogleAnalytics.sendEvent('errorMatch', 'match');
177185
if (!this.cmd.errorMatch) {
178186
return;
179187
}
@@ -190,6 +198,7 @@ module.exports = {
190198
},
191199

192200
errorMatchFirst: function() {
201+
GoogleAnalytics.sendEvent('errorMatch', 'first');
193202
if (!this.cmd.errorMatch) {
194203
return;
195204
}
@@ -214,6 +223,8 @@ module.exports = {
214223
return;
215224
}
216225

226+
GoogleAnalytics.sendEvent('build', 'triggered');
227+
217228
if (!this.cmd.exec) {
218229
return;
219230
}
@@ -253,9 +264,12 @@ module.exports = {
253264
this.child.on('close', function(exitCode) {
254265
this.buildView.buildFinished(0 === exitCode);
255266
if (0 === exitCode) {
267+
GoogleAnalytics.sendEvent('build', 'succeeded');
256268
this.finishedTimer = setTimeout(function() {
257269
this.buildView.detach();
258270
}.bind(this), 1000);
271+
} else {
272+
GoogleAnalytics.sendEvent('build', 'failed');
259273
}
260274
this.child = null;
261275
}.bind(this));

lib/tools/Cargo.js

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
var fs = require('fs');
44

5+
module.exports.niceName = 'Cargo';
6+
57
module.exports.isEligable = function (path) {
68
return fs.existsSync(path + '/Cargo.toml');
79
};

lib/tools/Elixir.js

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
var fs = require('fs');
44

5+
module.exports.niceName = 'Elixir';
6+
57
module.exports.isEligable = function (path) {
68
return fs.existsSync(path + '/mix.exs');
79
};

lib/tools/Grunt.js

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
var fs = require('fs');
44

5+
module.exports.niceName = 'Grunt';
6+
57
module.exports.isEligable = function (path) {
68
return fs.existsSync(path + '/Gruntfile.js');
79
};

lib/tools/atom-build.js

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
var fs = require('fs');
44

5+
module.exports.niceName = 'Custom file (.atom-build.json)';
6+
57
module.exports.isEligable = function (path) {
68
return fs.existsSync(path + '/.atom-build.json');
79
};

lib/tools/gulp.js

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
var fs = require('fs');
44

5+
module.exports.niceName = 'gulp';
6+
57
module.exports.isEligable = function (path) {
68
return fs.existsSync(path + '/gulpfile.js');
79
};

lib/tools/make.js

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
var fs = require('fs');
44

5+
module.exports.niceName = 'GNU Make';
6+
57
module.exports.isEligable = function (path) {
68
return fs.existsSync(path + '/Makefile');
79
};

lib/tools/npm_apm.js

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
var fs = require('fs');
44

5+
module.exports.niceName = 'npm or apm';
6+
57
module.exports.isEligable = function (path) {
68
if (!fs.existsSync(path + '/package.json')) {
79
return false;

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"temp": "^0.8.1",
1515
"fs-plus": "^2.4.0",
1616
"atom-space-pen-views": "^2.0.3",
17-
"xregexp": "^2.0.0"
17+
"xregexp": "^2.0.0",
18+
"node-uuid": "^1.4.3"
1819
},
1920
"devDependencies": {
2021
"jshint": "^2.5.11",

0 commit comments

Comments
 (0)