Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Bugsnag and Analytics opt-out #3335

Merged
merged 8 commits into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions app/actions/actionsTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ export const LOGOUT = 'LOGOUT'; // logout is always success
export const SNIPPETED_MESSAGES = createRequestTypes('SNIPPETED_MESSAGES', ['OPEN', 'READY', 'CLOSE', 'MESSAGES_RECEIVED']);
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
15 changes: 0 additions & 15 deletions app/actions/crashReport.js

This file was deleted.

12 changes: 6 additions & 6 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { deepLinkingOpen } from './actions/deepLinking';
import parseQuery from './lib/methods/helpers/parseQuery';
import { initializePushNotifications, onNotification } from './notifications/push';
import store from './lib/createStore';
import { loggerConfig, analytics } from './utils/log';
import { toggleAnalyticsEventsReport, toggleCrashErrorsReport } from './utils/log';
import { ThemeContext } from './theme';
import { DimensionsContext } from './dimensions';
import RocketChat, { THEME_PREFERENCES_KEY } from './lib/rocketchat';
Expand Down Expand Up @@ -188,11 +188,11 @@ export default class Root extends React.Component {
initCrashReport = () => {
RocketChat.getAllowCrashReport()
.then((allowCrashReport) => {
if (!allowCrashReport) {
loggerConfig.autoNotify = false;
loggerConfig.registerBeforeSendCallback(() => false);
analytics().setAnalyticsCollectionEnabled(false);
}
toggleCrashErrorsReport(allowCrashReport);
});
RocketChat.getAllowAnalyticsEvents()
.then((allowAnalyticsEvents) => {
toggleAnalyticsEventsReport(allowAnalyticsEvents);
});
}

Expand Down
25 changes: 0 additions & 25 deletions app/reducers/crashReport.js

This file was deleted.

2 changes: 0 additions & 2 deletions app/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import createChannel from './createChannel';
import app from './app';
import sortPreferences from './sortPreferences';
import share from './share';
import crashReport from './crashReport';
import customEmojis from './customEmojis';
import activeUsers from './activeUsers';
import usersTyping from './usersTyping';
Expand All @@ -35,7 +34,6 @@ export default combineReducers({
rooms,
sortPreferences,
share,
crashReport,
customEmojis,
activeUsers,
usersTyping,
Expand Down
7 changes: 0 additions & 7 deletions app/sagas/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import RNBootSplash from 'react-native-bootsplash';
import UserPreferences from '../lib/userPreferences';
import { selectServerRequest } from '../actions/server';
import { setAllPreferences } from '../actions/sortPreferences';
import { toggleCrashReport, toggleAnalyticsEvents } from '../actions/crashReport';
import { APP } from '../actions/actionsTypes';
import RocketChat from '../lib/rocketchat';
import log from '../utils/log';
Expand All @@ -15,12 +14,6 @@ import { appStart, ROOT_OUTSIDE, appReady } from '../actions/app';
export const initLocalSettings = function* initLocalSettings() {
const sortPreferences = yield RocketChat.getSortPreferences();
yield put(setAllPreferences(sortPreferences));

const allowCrashReport = yield RocketChat.getAllowCrashReport();
yield put(toggleCrashReport(allowCrashReport));

const allowAnalyticsEvents = yield RocketChat.getAllowAnalyticsEvents();
yield put(toggleAnalyticsEvents(allowAnalyticsEvents));
};

const restore = function* restore() {
Expand Down
26 changes: 25 additions & 1 deletion app/utils/log/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,24 @@ import events from './events';
const analytics = firebaseAnalytics || '';
let bugsnag = '';
let crashlytics;
let reportCrashErrors = true;
let reportAnalyticsEvents = true;

export const getReportCrashErrorsValue = () => reportCrashErrors;
export const getReportAnalyticsEventsValue = () => reportAnalyticsEvents;


if (!isFDroidBuild) {
bugsnag = require('@bugsnag/react-native').default;
bugsnag.start();
bugsnag.start({
onBreadcrumb() {
return reportAnalyticsEvents;
},
onError(error) {
if (!reportAnalyticsEvents) { error.breadcrumbs = []; }
return reportCrashErrors;
}
});
crashlytics = require('@react-native-firebase/crashlytics').default;
}

Expand Down Expand Up @@ -42,6 +56,16 @@ export const setCurrentScreen = (currentScreen) => {
}
};

export const toggleCrashErrorsReport = (value) => {
crashlytics().setCrashlyticsCollectionEnabled(value);
return reportCrashErrors = value;
};

export const toggleAnalyticsEventsReport = (value) => {
analytics().setAnalyticsCollectionEnabled(value);
return reportAnalyticsEvents = value;
};

export default (e) => {
if (e instanceof Error && bugsnag && e.message !== 'Aborted' && !__DEV__) {
bugsnag.notify(e, (event) => {
Expand Down
Loading