-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmetrics.js
64 lines (49 loc) · 1.23 KB
/
metrics.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*jslint node: true, indent: 2, white: true, vars: true */
/*
* Record events through KISSmetrics.
*/
'use strict';
var KissClient = require('kissmetrics');
var kissKey = process.env.KISS_KEY;
var kissClient = new KissClient({ key: kissKey });
function kissHandler(err) {
if (err) {
console.log('KISSmetrics error: ' + err.message);
}
}
function record(user, event, callback) {
// Ignore the default user ID, which we use for testing
if (user === '0') {
return;
}
if (callback === undefined) {
callback = kissHandler;
}
kissClient.record(user, event, callback);
}
var metrics = {
message: function (user) {
record(user, 'Sent Message', kissHandler);
},
conversationContinue: function (user) {
record(user, 'Continued Conversation', kissHandler);
},
stopID: function (user) {
record(user, 'Sent Stop ID', kissHandler);
},
cacheMiss: function () {
record('NO USER RECORDED', 'Cache Miss', kissHandler);
}
};
if (kissKey !== undefined) {
module.exports = metrics;
} else {
console.log('No KISSmetrics API key found. Disabling metrics.');
var dummy = function () {};
var f;
for (f in metrics) {
if (metrics.hasOwnProperty(f)) {
module.exports[f] = dummy;
}
}
}