Diagnostic checkbox analytics integration
This commit is contained in:
parent
a81924626d
commit
c765ebd28f
2 changed files with 18 additions and 5 deletions
|
@ -6,15 +6,20 @@ mixpanel.init('691723e855cabb9d27a7a79002216967');
|
||||||
type Analytics = {
|
type Analytics = {
|
||||||
track: (string, ?Object) => void,
|
track: (string, ?Object) => void,
|
||||||
setUser: (Object) => void,
|
setUser: (Object) => void,
|
||||||
|
toggle: (boolean, ?boolean) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let analyticsEnabled: boolean = false;
|
||||||
|
|
||||||
const analytics: Analytics = {
|
const analytics: Analytics = {
|
||||||
track: (name: string, payload: ?Object): void => {
|
track: (name: string, payload: ?Object): void => {
|
||||||
|
if(analyticsEnabled) {
|
||||||
if(payload) {
|
if(payload) {
|
||||||
mixpanel.track(name, payload);
|
mixpanel.track(name, payload);
|
||||||
} else {
|
} else {
|
||||||
mixpanel.track(name);
|
mixpanel.track(name);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
setUser: (user: Object): void => {
|
setUser: (user: Object): void => {
|
||||||
if(user.id) {
|
if(user.id) {
|
||||||
|
@ -25,6 +30,12 @@ const analytics: Analytics = {
|
||||||
"$email": user.primary_email
|
"$email": user.primary_email
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
toggle: (enabled: boolean, logDisabled: ?boolean): void => {
|
||||||
|
if(!enabled && logDisabled) {
|
||||||
|
mixpanel.track('DISABLED');
|
||||||
|
}
|
||||||
|
analyticsEnabled = enabled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,15 +2,16 @@ import * as ACTIONS from 'constants/action_types';
|
||||||
import * as SETTINGS from 'constants/settings';
|
import * as SETTINGS from 'constants/settings';
|
||||||
import Fs from 'fs';
|
import Fs from 'fs';
|
||||||
import Http from 'http';
|
import Http from 'http';
|
||||||
|
|
||||||
import Lbry from 'lbry';
|
import Lbry from 'lbry';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
import analytics from 'analytics';
|
||||||
|
|
||||||
const UPDATE_IS_NIGHT_INTERVAL = 10 * 60 * 1000;
|
const UPDATE_IS_NIGHT_INTERVAL = 10 * 60 * 1000;
|
||||||
|
|
||||||
export function doFetchDaemonSettings() {
|
export function doFetchDaemonSettings() {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
Lbry.settings_get().then(settings => {
|
Lbry.settings_get().then(settings => {
|
||||||
|
analytics.toggle(settings.share_usage_data);
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.DAEMON_SETTINGS_RECEIVED,
|
type: ACTIONS.DAEMON_SETTINGS_RECEIVED,
|
||||||
data: {
|
data: {
|
||||||
|
@ -27,6 +28,7 @@ export function doSetDaemonSetting(key, value) {
|
||||||
newSettings[key] = value;
|
newSettings[key] = value;
|
||||||
Lbry.settings_set(newSettings).then(newSettings);
|
Lbry.settings_set(newSettings).then(newSettings);
|
||||||
Lbry.settings_get().then(settings => {
|
Lbry.settings_get().then(settings => {
|
||||||
|
analytics.toggle(settings.share_usage_data, true);
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.DAEMON_SETTINGS_RECEIVED,
|
type: ACTIONS.DAEMON_SETTINGS_RECEIVED,
|
||||||
data: {
|
data: {
|
||||||
|
|
Loading…
Reference in a new issue