[NEW] Toggle analytics events (#2422)

* Create flow to toggle analytics events on memory

* Persist toggle analytics events

* Update crash report to contemplate analytics events

* Minor tweaks

Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
Youssef Muhamad 2020-09-11 14:34:11 -03:00 committed by GitHub
parent d37678b354
commit 639d667838
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 70 additions and 11 deletions

View File

@ -53,6 +53,7 @@ export const SNIPPETED_MESSAGES = createRequestTypes('SNIPPETED_MESSAGES', ['OPE
export const DEEP_LINKING = createRequestTypes('DEEP_LINKING', ['OPEN']); export const DEEP_LINKING = createRequestTypes('DEEP_LINKING', ['OPEN']);
export const SORT_PREFERENCES = createRequestTypes('SORT_PREFERENCES', ['SET_ALL', 'SET']); export const SORT_PREFERENCES = createRequestTypes('SORT_PREFERENCES', ['SET_ALL', 'SET']);
export const TOGGLE_CRASH_REPORT = 'TOGGLE_CRASH_REPORT'; export const TOGGLE_CRASH_REPORT = 'TOGGLE_CRASH_REPORT';
export const TOGGLE_ANALYTICS_EVENTS = 'TOGGLE_ANALYTICS_EVENTS';
export const SET_CUSTOM_EMOJIS = 'SET_CUSTOM_EMOJIS'; export const SET_CUSTOM_EMOJIS = 'SET_CUSTOM_EMOJIS';
export const SET_ACTIVE_USERS = 'SET_ACTIVE_USERS'; export const SET_ACTIVE_USERS = 'SET_ACTIVE_USERS';
export const USERS_TYPING = createRequestTypes('USERS_TYPING', ['ADD', 'REMOVE', 'CLEAR']); export const USERS_TYPING = createRequestTypes('USERS_TYPING', ['ADD', 'REMOVE', 'CLEAR']);

View File

@ -6,3 +6,10 @@ export function toggleCrashReport(value) {
payload: value payload: value
}; };
} }
export function toggleAnalyticsEvents(value) {
return {
type: types.TOGGLE_ANALYTICS_EVENTS,
payload: value
};
}

View File

@ -608,7 +608,7 @@ export default {
You_will_not_be_able_to_recover_this_message: 'You will not be able to recover this message!', You_will_not_be_able_to_recover_this_message: 'You will not be able to recover this message!',
You_will_unset_a_certificate_for_this_server: 'You will unset a certificate for this server', You_will_unset_a_certificate_for_this_server: 'You will unset a certificate for this server',
Change_Language: 'Change Language', Change_Language: 'Change Language',
Crash_report_disclaimer: 'We never track the content of your chats. The crash report only contains relevant information for us in order to identify problems and fix it.', Crash_report_disclaimer: 'We never track the content of your chats. The crash report and analytics events only contains relevant information for us in order to identify and fix issues.',
Type_message: 'Type message', Type_message: 'Type message',
Room_search: 'Rooms search', Room_search: 'Rooms search',
Room_selection: 'Room selection 1...9', Room_selection: 'Room selection 1...9',
@ -658,5 +658,6 @@ export default {
Logout_from_other_logged_in_locations: 'Logout from other logged in locations', Logout_from_other_logged_in_locations: 'Logout from other logged in locations',
You_will_be_logged_out_from_other_locations: 'You\'ll be logged out from other locations.', You_will_be_logged_out_from_other_locations: 'You\'ll be logged out from other locations.',
Logged_out_of_other_clients_successfully: 'Logged out of other clients successfully', Logged_out_of_other_clients_successfully: 'Logged out of other clients successfully',
Logout_failed: 'Logout failed!' Logout_failed: 'Logout failed!',
Log_analytics_events: 'Log analytics events'
}; };

View File

@ -552,7 +552,7 @@ export default {
Write_External_Permission_Message: 'Rocket.Chat precisa de acesso à sua galeria para salvar imagens', Write_External_Permission_Message: 'Rocket.Chat precisa de acesso à sua galeria para salvar imagens',
Write_External_Permission: 'Acesso à Galeria', Write_External_Permission: 'Acesso à Galeria',
Yes: 'Sim', Yes: 'Sim',
Crash_report_disclaimer: 'Nós não rastreamos o conteúdo das suas conversas. O relatório de erros apenas contém informações relevantes para identificarmos problemas e corrigí-los.', Crash_report_disclaimer: 'Nós não rastreamos o conteúdo das suas conversas. O relatório de erros e os eventos do analytics apenas contém informações relevantes para identificarmos problemas e corrigí-los.',
Type_message: 'Digitar mensagem', Type_message: 'Digitar mensagem',
Room_search: 'Busca de sala', Room_search: 'Busca de sala',
Room_selection: 'Selecionar sala 1...9', Room_selection: 'Selecionar sala 1...9',
@ -601,5 +601,6 @@ export default {
Logout_from_other_logged_in_locations: 'Sair de outros locais logados', Logout_from_other_logged_in_locations: 'Sair de outros locais logados',
You_will_be_logged_out_from_other_locations: 'Você perderá a sessão de outros clientes', You_will_be_logged_out_from_other_locations: 'Você perderá a sessão de outros clientes',
Logged_out_of_other_clients_successfully: 'Desconectado de outros clientes com sucesso', Logged_out_of_other_clients_successfully: 'Desconectado de outros clientes com sucesso',
Logout_failed: 'Falha ao desconectar!' Logout_failed: 'Falha ao desconectar!',
Log_analytics_events: 'Logar eventos no analytics'
}; };

View File

@ -62,6 +62,7 @@ const CURRENT_SERVER = 'currentServer';
const SORT_PREFS_KEY = 'RC_SORT_PREFS_KEY'; const SORT_PREFS_KEY = 'RC_SORT_PREFS_KEY';
export const THEME_PREFERENCES_KEY = 'RC_THEME_PREFERENCES_KEY'; export const THEME_PREFERENCES_KEY = 'RC_THEME_PREFERENCES_KEY';
export const CRASH_REPORT_KEY = 'RC_CRASH_REPORT_KEY'; export const CRASH_REPORT_KEY = 'RC_CRASH_REPORT_KEY';
export const ANALYTICS_EVENTS_KEY = 'RC_ANALYTICS_EVENTS_KEY';
const returnAnArray = obj => obj || []; const returnAnArray = obj => obj || [];
const MIN_ROCKETCHAT_VERSION = '0.70.0'; const MIN_ROCKETCHAT_VERSION = '0.70.0';
@ -1061,6 +1062,13 @@ const RocketChat = {
} }
return JSON.parse(allowCrashReport); return JSON.parse(allowCrashReport);
}, },
async getAllowAnalyticsEvents() {
const allowAnalyticsEvents = await AsyncStorage.getItem(ANALYTICS_EVENTS_KEY);
if (allowAnalyticsEvents === null) {
return true;
}
return JSON.parse(allowAnalyticsEvents);
},
async getSortPreferences() { async getSortPreferences() {
const prefs = await UserPreferences.getMapAsync(SORT_PREFS_KEY); const prefs = await UserPreferences.getMapAsync(SORT_PREFS_KEY);
return prefs; return prefs;

View File

@ -1,7 +1,8 @@
import { TOGGLE_CRASH_REPORT } from '../actions/actionsTypes'; import { TOGGLE_CRASH_REPORT, TOGGLE_ANALYTICS_EVENTS } from '../actions/actionsTypes';
const initialState = { const initialState = {
allowCrashReport: false allowCrashReport: false,
allowAnalyticsEvents: false
}; };
@ -9,8 +10,15 @@ export default (state = initialState, action) => {
switch (action.type) { switch (action.type) {
case TOGGLE_CRASH_REPORT: case TOGGLE_CRASH_REPORT:
return { return {
...state,
allowCrashReport: action.payload allowCrashReport: action.payload
}; };
case TOGGLE_ANALYTICS_EVENTS:
return {
...state,
allowAnalyticsEvents: action.payload
};
default: default:
return state; return state;
} }

View File

@ -4,7 +4,7 @@ import RNBootSplash from 'react-native-bootsplash';
import UserPreferences from '../lib/userPreferences'; import UserPreferences from '../lib/userPreferences';
import { selectServerRequest } from '../actions/server'; import { selectServerRequest } from '../actions/server';
import { setAllPreferences } from '../actions/sortPreferences'; import { setAllPreferences } from '../actions/sortPreferences';
import { toggleCrashReport } from '../actions/crashReport'; import { toggleCrashReport, toggleAnalyticsEvents } from '../actions/crashReport';
import { APP } from '../actions/actionsTypes'; import { APP } from '../actions/actionsTypes';
import RocketChat from '../lib/rocketchat'; import RocketChat from '../lib/rocketchat';
import log from '../utils/log'; import log from '../utils/log';
@ -18,6 +18,9 @@ export const initLocalSettings = function* initLocalSettings() {
const allowCrashReport = yield RocketChat.getAllowCrashReport(); const allowCrashReport = yield RocketChat.getAllowCrashReport();
yield put(toggleCrashReport(allowCrashReport)); yield put(toggleCrashReport(allowCrashReport));
const allowAnalyticsEvents = yield RocketChat.getAllowAnalyticsEvents();
yield put(toggleAnalyticsEvents(allowAnalyticsEvents));
}; };
const restore = function* restore() { const restore = function* restore() {

View File

@ -139,6 +139,7 @@ export default {
SE_COPY_APP_VERSION: 'se_copy_app_version', SE_COPY_APP_VERSION: 'se_copy_app_version',
SE_COPY_SERVER_VERSION: 'se_copy_server_version', SE_COPY_SERVER_VERSION: 'se_copy_server_version',
SE_TOGGLE_CRASH_REPORT: 'se_toggle_crash_report', SE_TOGGLE_CRASH_REPORT: 'se_toggle_crash_report',
SE_TOGGLE_ANALYTICS_EVENTS: 'se_toggle_analytics_events',
SE_CLEAR_LOCAL_SERVER_CACHE: 'se_clear_local_server_cache', SE_CLEAR_LOCAL_SERVER_CACHE: 'se_clear_local_server_cache',
SE_LOG_OUT: 'se_log_out', SE_LOG_OUT: 'se_log_out',

View File

@ -10,7 +10,7 @@ import CookieManager from '@react-native-community/cookies';
import { logout as logoutAction } from '../../actions/login'; import { logout as logoutAction } from '../../actions/login';
import { selectServerRequest as selectServerRequestAction } from '../../actions/server'; import { selectServerRequest as selectServerRequestAction } from '../../actions/server';
import { toggleCrashReport as toggleCrashReportAction } from '../../actions/crashReport'; import { toggleCrashReport as toggleCrashReportAction, toggleAnalyticsEvents as toggleAnalyticsEventsAction } from '../../actions/crashReport';
import { SWITCH_TRACK_COLOR, themes } from '../../constants/colors'; import { SWITCH_TRACK_COLOR, themes } from '../../constants/colors';
import { DrawerButton, CloseModalButton } from '../../containers/HeaderButton'; import { DrawerButton, CloseModalButton } from '../../containers/HeaderButton';
import StatusBar from '../../containers/StatusBar'; import StatusBar from '../../containers/StatusBar';
@ -19,7 +19,7 @@ import ItemInfo from '../../containers/ItemInfo';
import { DisclosureImage } from '../../containers/DisclosureIndicator'; import { DisclosureImage } from '../../containers/DisclosureIndicator';
import Separator from '../../containers/Separator'; import Separator from '../../containers/Separator';
import I18n from '../../i18n'; import I18n from '../../i18n';
import RocketChat, { CRASH_REPORT_KEY } from '../../lib/rocketchat'; import RocketChat, { CRASH_REPORT_KEY, ANALYTICS_EVENTS_KEY } from '../../lib/rocketchat';
import { import {
getReadableVersion, getDeviceModel, isAndroid getReadableVersion, getDeviceModel, isAndroid
} from '../../utils/deviceInfo'; } from '../../utils/deviceInfo';
@ -74,7 +74,9 @@ class SettingsView extends React.Component {
navigation: PropTypes.object, navigation: PropTypes.object,
server: PropTypes.object, server: PropTypes.object,
allowCrashReport: PropTypes.bool, allowCrashReport: PropTypes.bool,
allowAnalyticsEvents: PropTypes.bool,
toggleCrashReport: PropTypes.func, toggleCrashReport: PropTypes.func,
toggleAnalyticsEvents: PropTypes.func,
theme: PropTypes.string, theme: PropTypes.string,
isMasterDetail: PropTypes.bool, isMasterDetail: PropTypes.bool,
logout: PropTypes.func.isRequired, logout: PropTypes.func.isRequired,
@ -148,7 +150,6 @@ class SettingsView extends React.Component {
toggleCrashReport(value); toggleCrashReport(value);
if (!isFDroidBuild) { if (!isFDroidBuild) {
loggerConfig.autoNotify = value; loggerConfig.autoNotify = value;
analytics().setAnalyticsCollectionEnabled(value);
if (value) { if (value) {
loggerConfig.clearBeforeSendCallbacks(); loggerConfig.clearBeforeSendCallbacks();
} else { } else {
@ -157,6 +158,14 @@ class SettingsView extends React.Component {
} }
} }
toggleAnalyticsEvents = (value) => {
logEvent(events.SE_TOGGLE_ANALYTICS_EVENTS);
const { toggleAnalyticsEvents } = this.props;
AsyncStorage.setItem(ANALYTICS_EVENTS_KEY, JSON.stringify(value));
toggleAnalyticsEvents(value);
analytics().setAnalyticsCollectionEnabled(value);
}
navigateToScreen = (screen) => { navigateToScreen = (screen) => {
logEvent(events[`SE_GO_${ screen.replace('View', '').toUpperCase() }`]); logEvent(events[`SE_GO_${ screen.replace('View', '').toUpperCase() }`]);
const { navigation } = this.props; const { navigation } = this.props;
@ -230,6 +239,17 @@ class SettingsView extends React.Component {
); );
} }
renderAnalyticsEventsSwitch = () => {
const { allowAnalyticsEvents } = this.props;
return (
<Switch
value={allowAnalyticsEvents}
trackColor={SWITCH_TRACK_COLOR}
onValueChange={this.toggleAnalyticsEvents}
/>
);
}
render() { render() {
const { server, isMasterDetail, theme } = this.props; const { server, isMasterDetail, theme } = this.props;
return ( return (
@ -356,6 +376,13 @@ class SettingsView extends React.Component {
{!isFDroidBuild ? ( {!isFDroidBuild ? (
<> <>
<ListItem
title={I18n.t('Log_analytics_events')}
testID='settings-view-analytics-events'
right={() => this.renderAnalyticsEventsSwitch()}
theme={theme}
/>
<Separator theme={theme} />
<ListItem <ListItem
title={I18n.t('Send_crash_report')} title={I18n.t('Send_crash_report')}
testID='settings-view-crash-report' testID='settings-view-crash-report'
@ -367,10 +394,10 @@ class SettingsView extends React.Component {
info={I18n.t('Crash_report_disclaimer')} info={I18n.t('Crash_report_disclaimer')}
theme={theme} theme={theme}
/> />
<Separator theme={theme} />
</> </>
) : null} ) : null}
<Separator theme={theme} />
<ListItem <ListItem
title={I18n.t('Clear_cache')} title={I18n.t('Clear_cache')}
testID='settings-clear-cache' testID='settings-clear-cache'
@ -399,6 +426,7 @@ const mapStateToProps = state => ({
server: state.server, server: state.server,
user: getUserSelector(state), user: getUserSelector(state),
allowCrashReport: state.crashReport.allowCrashReport, allowCrashReport: state.crashReport.allowCrashReport,
allowAnalyticsEvents: state.crashReport.allowAnalyticsEvents,
isMasterDetail: state.app.isMasterDetail isMasterDetail: state.app.isMasterDetail
}); });
@ -406,6 +434,7 @@ const mapDispatchToProps = dispatch => ({
logout: () => dispatch(logoutAction()), logout: () => dispatch(logoutAction()),
selectServerRequest: params => dispatch(selectServerRequestAction(params)), selectServerRequest: params => dispatch(selectServerRequestAction(params)),
toggleCrashReport: params => dispatch(toggleCrashReportAction(params)), toggleCrashReport: params => dispatch(toggleCrashReportAction(params)),
toggleAnalyticsEvents: params => dispatch(toggleAnalyticsEventsAction(params)),
appStart: params => dispatch(appStartAction(params)) appStart: params => dispatch(appStartAction(params))
}); });