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-08-28 22:46:50 +02:00
|
|
|
apiLogView: (
|
|
|
|
uri: string,
|
|
|
|
outpoint: string,
|
|
|
|
claimId: string,
|
|
|
|
timeToStart?: number,
|
|
|
|
onSuccessCb: ?() => void
|
|
|
|
): void => {
|
2018-03-08 06:07:42 +01:00
|
|
|
if (analyticsEnabled) {
|
2018-08-03 17:54:10 +02:00
|
|
|
const params = {
|
2018-03-08 04:56:58 +01:00
|
|
|
uri,
|
2018-03-08 06:07:42 +01:00
|
|
|
outpoint,
|
|
|
|
claim_id: claimId,
|
2018-08-03 17:54:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if (timeToStart) {
|
|
|
|
params.time_to_start = timeToStart;
|
|
|
|
}
|
|
|
|
|
2018-08-28 22:46:50 +02:00
|
|
|
Lbryio.call('file', 'view', params)
|
|
|
|
.then(() => {
|
|
|
|
if (onSuccessCb) {
|
|
|
|
onSuccessCb();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(() => {});
|
2018-03-08 04:56:58 +01:00
|
|
|
}
|
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;
|