Diagnostic checkbox analytics integration

This commit is contained in:
Liam Cardenas 2018-02-16 01:16:50 -08:00
parent a81924626d
commit c765ebd28f
2 changed files with 18 additions and 5 deletions

View file

@ -6,14 +6,19 @@ mixpanel.init('691723e855cabb9d27a7a79002216967');
type Analytics = {
track: (string, ?Object) => void,
setUser: (Object) => void,
toggle: (boolean, ?boolean) => void
}
let analyticsEnabled: boolean = false;
const analytics: Analytics = {
track: (name: string, payload: ?Object): void => {
if(payload) {
mixpanel.track(name, payload);
} else {
mixpanel.track(name);
if(analyticsEnabled) {
if(payload) {
mixpanel.track(name, payload);
} else {
mixpanel.track(name);
}
}
},
setUser: (user: Object): void => {
@ -25,6 +30,12 @@ const analytics: Analytics = {
"$email": user.primary_email
});
}
},
toggle: (enabled: boolean, logDisabled: ?boolean): void => {
if(!enabled && logDisabled) {
mixpanel.track('DISABLED');
}
analyticsEnabled = enabled;
}
}

View file

@ -2,15 +2,16 @@ import * as ACTIONS from 'constants/action_types';
import * as SETTINGS from 'constants/settings';
import Fs from 'fs';
import Http from 'http';
import Lbry from 'lbry';
import moment from 'moment';
import analytics from 'analytics';
const UPDATE_IS_NIGHT_INTERVAL = 10 * 60 * 1000;
export function doFetchDaemonSettings() {
return dispatch => {
Lbry.settings_get().then(settings => {
analytics.toggle(settings.share_usage_data);
dispatch({
type: ACTIONS.DAEMON_SETTINGS_RECEIVED,
data: {
@ -27,6 +28,7 @@ export function doSetDaemonSetting(key, value) {
newSettings[key] = value;
Lbry.settings_set(newSettings).then(newSettings);
Lbry.settings_get().then(settings => {
analytics.toggle(settings.share_usage_data, true);
dispatch({
type: ACTIONS.DAEMON_SETTINGS_RECEIVED,
data: {