diff --git a/src/renderer/analytics.js b/src/renderer/analytics.js index 15db084c3..7d426e4f9 100644 --- a/src/renderer/analytics.js +++ b/src/renderer/analytics.js @@ -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; } } diff --git a/src/renderer/redux/actions/settings.js b/src/renderer/redux/actions/settings.js index 661ff10ba..9196dca44 100644 --- a/src/renderer/redux/actions/settings.js +++ b/src/renderer/redux/actions/settings.js @@ -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: {