Skip to content

Commit

Permalink
GoogleAnalytics: Unique cid per user
Browse files Browse the repository at this point in the history
Instead of generating a new cid everytime `build` launches,
make it dependant on the computer (the MAC address), so it is
the same for each user (in reality each computer). The MAC is
hashed before sent so it can not be used for tracing.
  • Loading branch information
noseglid committed May 14, 2015
1 parent 5a5cb83 commit ccdc9c9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
23 changes: 19 additions & 4 deletions lib/GoogleAnalytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,25 @@

var _ = require('lodash');
var querystring = require('querystring');
var cid = require('node-uuid').v4();
var cid;

module.exports = (function () {
function GoogleAnalytics () {}

GoogleAnalytics.getCid = function (cb) {
if (cid) {
return cb(cid);
}

require('getmac').getMac(function(error, macAddress) {
if (error) {
return cb(cid = require('node-uuid').v4());
}

return cb(require('crypto').createHash('sha1').update(macAddress, 'utf8').digest('hex'));
});
};

GoogleAnalytics.sendEvent = function(category, action, label, value) {
var params = {
t: 'event',
Expand All @@ -29,8 +43,10 @@ module.exports = (function () {
return;
}

_.extend(params, GoogleAnalytics.defaultParams());
GoogleAnalytics.request('https://www.google-analytics.com/collect?' + querystring.stringify(params));
GoogleAnalytics.getCid(function (cid) {
_.extend(params, { cid: cid }, GoogleAnalytics.defaultParams());
GoogleAnalytics.request('https://www.google-analytics.com/collect?' + querystring.stringify(params));
});
};

GoogleAnalytics.request = function (url) {
Expand All @@ -51,7 +67,6 @@ module.exports = (function () {
return {
v: 1,
tid: 'UA-47615700-5',
cid: cid
};
};

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"fs-plus": "^2.4.0",
"atom-space-pen-views": "^2.0.3",
"xregexp": "^2.0.0",
"node-uuid": "^1.4.3"
"node-uuid": "^1.4.3",
"getmac": "^1.0.7"
},
"devDependencies": {
"jshint": "^2.5.11",
Expand Down

3 comments on commit ccdc9c9

@srid
Copy link

@srid srid commented on ccdc9c9 May 14, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the tracking be totally disabled?

I was surprised to find out Atom doing it by default: atom/metrics#16

@noseglid
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it can. Disable the metrics package and the build package wont do any tracking either. It's stated in the README.md file.

@xax
Copy link

@xax xax commented on ccdc9c9 May 15, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MAC is hashed before sent so it can not be used for tracing.

Shouldn't you add some salt to impede dictionary “attacks”? (I'm aware of the fact, that regrettably metrics isn't doing it, either.)

Please sign in to comment.