Skip to content

Commit

Permalink
[NEW] Toggle analytics events (#2422)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
youssef-md and diegolmello authored Sep 11, 2020
1 parent d37678b commit 639d667
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 11 deletions.
1 change: 1 addition & 0 deletions app/actions/actionsTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
7 changes: 7 additions & 0 deletions app/actions/crashReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ export function toggleCrashReport(value) {
payload: value
};
}

export function toggleAnalyticsEvents(value) {
return {
type: types.TOGGLE_ANALYTICS_EVENTS,
payload: value
};
}
5 changes: 3 additions & 2 deletions app/i18n/locales/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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'
};
5 changes: 3 additions & 2 deletions app/i18n/locales/pt-BR.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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'
};
8 changes: 8 additions & 0 deletions app/lib/rocketchat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
Expand Down
12 changes: 10 additions & 2 deletions app/reducers/crashReport.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
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
};


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;
}
Expand Down
5 changes: 4 additions & 1 deletion app/sagas/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions app/utils/log/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',

Expand Down
37 changes: 33 additions & 4 deletions app/views/SettingsView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -148,7 +150,6 @@ class SettingsView extends React.Component {
toggleCrashReport(value);
if (!isFDroidBuild) {
loggerConfig.autoNotify = value;
analytics().setAnalyticsCollectionEnabled(value);
if (value) {
loggerConfig.clearBeforeSendCallbacks();
} else {
Expand All @@ -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;
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -399,13 +426,15 @@ const mapStateToProps = state => ({
server: state.server,
user: getUserSelector(state),
allowCrashReport: state.crashReport.allowCrashReport,
allowAnalyticsEvents: state.crashReport.allowAnalyticsEvents,
isMasterDetail: state.app.isMasterDetail
});

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))
});

Expand Down

0 comments on commit 639d667

Please sign in to comment.