[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 SORT_PREFERENCES = createRequestTypes('SORT_PREFERENCES', ['SET_ALL', 'SET']);
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_ACTIVE_USERS = 'SET_ACTIVE_USERS';
export const USERS_TYPING = createRequestTypes('USERS_TYPING', ['ADD', 'REMOVE', 'CLEAR']);

View File

@ -6,3 +6,10 @@ export function toggleCrashReport(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_unset_a_certificate_for_this_server: 'You will unset a certificate for this server',
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',
Room_search: 'Rooms search',
Room_selection: 'Room selection 1...9',
@ -658,5 +658,6 @@ export default {
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.',
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: 'Acesso à Galeria',
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',
Room_search: 'Busca de sala',
Room_selection: 'Selecionar sala 1...9',
@ -601,5 +601,6 @@ export default {
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',
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';
export const THEME_PREFERENCES_KEY = 'RC_THEME_PREFERENCES_KEY';
export const CRASH_REPORT_KEY = 'RC_CRASH_REPORT_KEY';
export const ANALYTICS_EVENTS_KEY = 'RC_ANALYTICS_EVENTS_KEY';
const returnAnArray = obj => obj || [];
const MIN_ROCKETCHAT_VERSION = '0.70.0';
@ -1061,6 +1062,13 @@ const RocketChat = {
}
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() {
const prefs = await UserPreferences.getMapAsync(SORT_PREFS_KEY);
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 = {
allowCrashReport: false
allowCrashReport: false,
allowAnalyticsEvents: false
};
@ -9,8 +10,15 @@ export default (state = initialState, action) => {
switch (action.type) {
case TOGGLE_CRASH_REPORT:
return {
...state,
allowCrashReport: action.payload
};
case TOGGLE_ANALYTICS_EVENTS:
return {
...state,
allowAnalyticsEvents: action.payload
};
default:
return state;
}

View File

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

View File

@ -139,6 +139,7 @@ export default {
SE_COPY_APP_VERSION: 'se_copy_app_version',
SE_COPY_SERVER_VERSION: 'se_copy_server_version',
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_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 { 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 { DrawerButton, CloseModalButton } from '../../containers/HeaderButton';
import StatusBar from '../../containers/StatusBar';
@ -19,7 +19,7 @@ import ItemInfo from '../../containers/ItemInfo';
import { DisclosureImage } from '../../containers/DisclosureIndicator';
import Separator from '../../containers/Separator';
import I18n from '../../i18n';
import RocketChat, { CRASH_REPORT_KEY } from '../../lib/rocketchat';
import RocketChat, { CRASH_REPORT_KEY, ANALYTICS_EVENTS_KEY } from '../../lib/rocketchat';
import {
getReadableVersion, getDeviceModel, isAndroid
} from '../../utils/deviceInfo';
@ -74,7 +74,9 @@ class SettingsView extends React.Component {
navigation: PropTypes.object,
server: PropTypes.object,
allowCrashReport: PropTypes.bool,
allowAnalyticsEvents: PropTypes.bool,
toggleCrashReport: PropTypes.func,
toggleAnalyticsEvents: PropTypes.func,
theme: PropTypes.string,
isMasterDetail: PropTypes.bool,
logout: PropTypes.func.isRequired,
@ -148,7 +150,6 @@ class SettingsView extends React.Component {
toggleCrashReport(value);
if (!isFDroidBuild) {
loggerConfig.autoNotify = value;
analytics().setAnalyticsCollectionEnabled(value);
if (value) {
loggerConfig.clearBeforeSendCallbacks();
} 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) => {
logEvent(events[`SE_GO_${ screen.replace('View', '').toUpperCase() }`]);
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() {
const { server, isMasterDetail, theme } = this.props;
return (
@ -356,6 +376,13 @@ class SettingsView extends React.Component {
{!isFDroidBuild ? (
<>
<ListItem
title={I18n.t('Log_analytics_events')}
testID='settings-view-analytics-events'
right={() => this.renderAnalyticsEventsSwitch()}
theme={theme}
/>
<Separator theme={theme} />
<ListItem
title={I18n.t('Send_crash_report')}
testID='settings-view-crash-report'
@ -367,10 +394,10 @@ class SettingsView extends React.Component {
info={I18n.t('Crash_report_disclaimer')}
theme={theme}
/>
<Separator theme={theme} />
</>
) : null}
<Separator theme={theme} />
<ListItem
title={I18n.t('Clear_cache')}
testID='settings-clear-cache'
@ -399,6 +426,7 @@ const mapStateToProps = state => ({
server: state.server,
user: getUserSelector(state),
allowCrashReport: state.crashReport.allowCrashReport,
allowAnalyticsEvents: state.crashReport.allowAnalyticsEvents,
isMasterDetail: state.app.isMasterDetail
});
@ -406,6 +434,7 @@ const mapDispatchToProps = dispatch => ({
logout: () => dispatch(logoutAction()),
selectServerRequest: params => dispatch(selectServerRequestAction(params)),
toggleCrashReport: params => dispatch(toggleCrashReportAction(params)),
toggleAnalyticsEvents: params => dispatch(toggleAnalyticsEventsAction(params)),
appStart: params => dispatch(appStartAction(params))
});