-
Notifications
You must be signed in to change notification settings - Fork 34
/
analytics.js
49 lines (39 loc) · 1.01 KB
/
analytics.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
const fs = require('fs');
const mkdirp = require('mkdirp');
const helper = require('./helper');
const environment = helper.environment();
const folder = "./private/analytics/" + environment['version'] + "/";
mkdirp(folder);
function trackPersonality(data) {
track("personality", data);
}
function trackConversion(data) {
track("conversion", data);
}
function trackEdit(data) {
track("edit", data);
}
function trackUnsubscribe(data) {
track("unsubscribe", data);
}
function trackError(data) {
track("error", data);
}
function track(category, data) {
const dataString = data
.map(d => JSON.stringify(d))
.map(d => d.replace(/[,\n"]/gi, ''))
.join(",") + "\n";
if (environment['dev-mode']) {
helper.log(dataString);
} else {
fs.appendFileSync(folder + category + ".csv", dataString, "utf8");
}
}
module.exports = {
"trackPersonality" : trackPersonality,
"trackConversion" : trackConversion,
"trackEdit" : trackEdit,
"trackUnsubscribe" : trackUnsubscribe,
"trackError" : trackError
}