forked from motepair/motepair-server
-
Notifications
You must be signed in to change notification settings - Fork 3
/
tracker.js
50 lines (41 loc) · 1.32 KB
/
tracker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Generated by CoffeeScript 1.8.0
(function() {
var Keen, Tracker, getenv;
Keen = require('keen-js');
getenv = require('getenv');
Tracker = (function() {
function Tracker() {
this.KEEN_TRACK = getenv.bool('KEEN_TRACK', false);
this.KEEN_PROJECTID = getenv('KEEN_PROJECT_ID', '');
this.KEEN_WRITEKEY = getenv('KEEN_WRITE_KEY', '');
this.client = new Keen({
projectId: this.KEEN_PROJECTID,
writeKey: this.KEEN_WRITEKEY
});
}
Tracker.prototype.ready = function() {
return this.KEEN_TRACK && this.KEEN_PROJECTID !== '' && this.KEEN_WRITEKEY !== '';
};
Tracker.prototype.connectionClosed = function(client, remoteAddress) {
var connection;
if (!this.ready()) {
return;
}
connection = {
sessionId: client.sessionId,
duration: (new Date() - client.sessionStarted) / 60000,
atomVersion: client.atomVersion,
motepairVersion: client.motepairVersion
};
return this.client.addEvent("connections", connection, function(err, res) {
if (err) {
return console.log('Connection could not be saved.');
} else {
return console.log('Connection logged.', connection, res);
}
});
};
return Tracker;
})();
module.exports = Tracker;
}).call(this);