2018-02-16 09:47:52 +01:00
|
|
|
// @flow
|
|
|
|
import mixpanel from 'mixpanel-browser';
|
2018-03-08 04:56:58 +01:00
|
|
|
import Lbryio from 'lbryio';
|
2018-03-08 06:44:03 +01:00
|
|
|
import isDev from 'electron-is-dev';
|
2018-03-16 19:22:19 +01:00
|
|
|
|
2018-03-08 06:44:03 +01:00
|
|
|
if (isDev) {
|
|
|
|
mixpanel.init('691723e855cabb9d27a7a79002216967');
|
|
|
|
} else {
|
|
|
|
mixpanel.init('af5c6b8110068fa4f5c4600c81f05e60');
|
|
|
|
}
|
2018-02-16 09:47:52 +01:00
|
|
|
|
|
|
|
type Analytics = {
|
|
|
|
track: (string, ?Object) => void,
|
2018-02-24 01:24:00 +01:00
|
|
|
setUser: Object => void,
|
|
|
|
toggle: (boolean, ?boolean) => void,
|
2018-03-16 19:22:19 +01:00
|
|
|
apiLogView: (string, string, string) => void,
|
2018-02-24 01:24:00 +01:00
|
|
|
};
|
2018-02-16 09:47:52 +01:00
|
|
|
|
2018-02-16 10:16:50 +01:00
|
|
|
let analyticsEnabled: boolean = false;
|
|
|
|
|
2018-02-16 09:47:52 +01:00
|
|
|
const analytics: Analytics = {
|
|
|
|
track: (name: string, payload: ?Object): void => {
|
2018-02-24 01:24:00 +01:00
|
|
|
if (analyticsEnabled) {
|
|
|
|
if (payload) {
|
2018-02-16 10:16:50 +01:00
|
|
|
mixpanel.track(name, payload);
|
|
|
|
} else {
|
|
|
|
mixpanel.track(name);
|
|
|
|
}
|
2018-02-16 09:47:52 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
setUser: (user: Object): void => {
|
2018-02-24 01:24:00 +01:00
|
|
|
if (user.id) {
|
2018-02-16 09:47:52 +01:00
|
|
|
mixpanel.identify(user.id);
|
|
|
|
}
|
2018-02-24 01:24:00 +01:00
|
|
|
if (user.primary_email) {
|
2018-02-16 09:47:52 +01:00
|
|
|
mixpanel.people.set({
|
2018-02-24 01:24:00 +01:00
|
|
|
$email: user.primary_email,
|
2018-02-16 09:47:52 +01:00
|
|
|
});
|
|
|
|
}
|
2018-02-16 10:16:50 +01:00
|
|
|
},
|
|
|
|
toggle: (enabled: boolean, logDisabled: ?boolean): void => {
|
2018-02-24 01:24:00 +01:00
|
|
|
if (!enabled && logDisabled) {
|
2018-02-16 10:16:50 +01:00
|
|
|
mixpanel.track('DISABLED');
|
|
|
|
}
|
|
|
|
analyticsEnabled = enabled;
|
2018-02-24 01:24:00 +01:00
|
|
|
},
|
2018-03-16 19:22:19 +01:00
|
|
|
apiLogView: (uri: string, outpoint: string, claimId: string): void => {
|
2018-03-08 06:07:42 +01:00
|
|
|
if (analyticsEnabled) {
|
2018-03-08 04:56:58 +01:00
|
|
|
Lbryio.call('file', 'view', {
|
|
|
|
uri,
|
2018-03-08 06:07:42 +01:00
|
|
|
outpoint,
|
|
|
|
claim_id: claimId,
|
2018-03-08 04:56:58 +01:00
|
|
|
}).catch(() => {});
|
|
|
|
}
|
2018-03-08 06:07:42 +01:00
|
|
|
},
|
2018-02-24 01:24:00 +01:00
|
|
|
};
|
2018-02-16 09:47:52 +01:00
|
|
|
|
|
|
|
export default analytics;
|