-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathanalytics.ts
43 lines (35 loc) · 1.23 KB
/
analytics.ts
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
import { remote } from 'electron';
import Analytics from 'electron-ga';
import * as R from 'ramda';
import * as uuid from 'uuid/v4';
import { PreferenceKey, preferences } from '../utils/preferences';
const isDevelopment = (r) => r.process.env.NODE_ENV === 'development';
const allowAnalytics = (): boolean => {
if (isDevelopment(remote)) {
return false;
}
return preferences.get(PreferenceKey.SETTING_ALLOW_ANALYTICS, true);
};
const trackingCode = 'UA-50962418-2';
const appVersion = '0.12.1';
const userId = preferences.get(PreferenceKey.APP_USER_ID, uuid());
preferences.set(PreferenceKey.APP_USER_ID, userId);
const analytics = new Analytics(trackingCode, {
appName: 'Overlay',
appVersion,
userId
});
export const track = R.curry(
(category: string, action: string, label: string) => {
if (allowAnalytics()) {
// tslint:disable-next-line
console.log('Tracking', `v${appVersion}`, category, action, label, 1);
analytics.send('event', { ec: category, ea: action, el: label, ev: 1 });
}
}
);
export const initAnalytics = (): boolean => {
const allow = preferences.get(PreferenceKey.SETTING_ALLOW_ANALYTICS, true);
preferences.set(PreferenceKey.SETTING_ALLOW_ANALYTICS, allow);
return allow;
};