2020-08-24 12:24:10 +00:00
|
|
|
import firebaseAnalytics from '@react-native-firebase/analytics';
|
2021-09-13 20:41:05 +00:00
|
|
|
|
2020-08-24 12:24:10 +00:00
|
|
|
import { isFDroidBuild } from '../../constants/environment';
|
2020-07-22 19:31:38 +00:00
|
|
|
import events from './events';
|
2018-05-18 17:55:08 +00:00
|
|
|
|
2020-08-24 12:24:10 +00:00
|
|
|
const analytics = firebaseAnalytics || '';
|
|
|
|
let bugsnag = '';
|
|
|
|
let crashlytics;
|
2021-08-23 14:15:01 +00:00
|
|
|
let reportCrashErrors = true;
|
|
|
|
let reportAnalyticsEvents = true;
|
|
|
|
|
|
|
|
export const getReportCrashErrorsValue = () => reportCrashErrors;
|
|
|
|
export const getReportAnalyticsEventsValue = () => reportAnalyticsEvents;
|
|
|
|
|
2020-08-24 12:24:10 +00:00
|
|
|
if (!isFDroidBuild) {
|
2021-07-28 20:36:06 +00:00
|
|
|
bugsnag = require('@bugsnag/react-native').default;
|
2021-08-23 14:15:01 +00:00
|
|
|
bugsnag.start({
|
|
|
|
onBreadcrumb() {
|
|
|
|
return reportAnalyticsEvents;
|
|
|
|
},
|
|
|
|
onError(error) {
|
2021-09-13 20:41:05 +00:00
|
|
|
if (!reportAnalyticsEvents) {
|
|
|
|
error.breadcrumbs = [];
|
|
|
|
}
|
2021-08-23 14:15:01 +00:00
|
|
|
return reportCrashErrors;
|
|
|
|
}
|
|
|
|
});
|
2020-08-28 15:53:33 +00:00
|
|
|
crashlytics = require('@react-native-firebase/crashlytics').default;
|
2020-08-24 12:24:10 +00:00
|
|
|
}
|
2019-08-23 13:18:47 +00:00
|
|
|
|
2020-07-24 13:19:17 +00:00
|
|
|
export { analytics };
|
2019-08-23 13:18:47 +00:00
|
|
|
export const loggerConfig = bugsnag.config;
|
2020-07-22 19:31:38 +00:00
|
|
|
export { events };
|
2019-08-23 13:18:47 +00:00
|
|
|
|
2020-02-28 19:51:13 +00:00
|
|
|
let metadata = {};
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
export const logServerVersion = serverVersion => {
|
2020-02-28 19:51:13 +00:00
|
|
|
metadata = {
|
|
|
|
serverVersion
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-07-22 19:31:38 +00:00
|
|
|
export const logEvent = (eventName, payload) => {
|
2020-07-31 18:24:38 +00:00
|
|
|
try {
|
2020-08-24 12:24:10 +00:00
|
|
|
if (!isFDroidBuild) {
|
|
|
|
analytics().logEvent(eventName, payload);
|
2021-07-28 20:36:06 +00:00
|
|
|
bugsnag.leaveBreadcrumb(eventName, payload);
|
2020-08-24 12:24:10 +00:00
|
|
|
}
|
2020-07-31 18:24:38 +00:00
|
|
|
} catch {
|
|
|
|
// Do nothing
|
|
|
|
}
|
2020-07-22 19:31:38 +00:00
|
|
|
};
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
export const setCurrentScreen = currentScreen => {
|
2020-08-24 12:24:10 +00:00
|
|
|
if (!isFDroidBuild) {
|
|
|
|
analytics().setCurrentScreen(currentScreen);
|
2021-07-28 20:36:06 +00:00
|
|
|
bugsnag.leaveBreadcrumb(currentScreen, { type: 'navigation' });
|
2020-08-24 12:24:10 +00:00
|
|
|
}
|
2020-06-15 14:00:46 +00:00
|
|
|
};
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
export const toggleCrashErrorsReport = value => {
|
2021-08-23 14:15:01 +00:00
|
|
|
crashlytics().setCrashlyticsCollectionEnabled(value);
|
2021-09-13 20:41:05 +00:00
|
|
|
return (reportCrashErrors = value);
|
2021-08-23 14:15:01 +00:00
|
|
|
};
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
export const toggleAnalyticsEventsReport = value => {
|
2021-08-23 14:15:01 +00:00
|
|
|
analytics().setAnalyticsCollectionEnabled(value);
|
2021-09-13 20:41:05 +00:00
|
|
|
return (reportAnalyticsEvents = value);
|
2021-08-23 14:15:01 +00:00
|
|
|
};
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
export default e => {
|
2020-08-24 12:24:10 +00:00
|
|
|
if (e instanceof Error && bugsnag && e.message !== 'Aborted' && !__DEV__) {
|
2021-09-13 20:41:05 +00:00
|
|
|
bugsnag.notify(e, event => {
|
2021-07-28 20:36:06 +00:00
|
|
|
event.addMetadata('details', { ...metadata });
|
2020-02-28 19:51:13 +00:00
|
|
|
});
|
2020-08-24 12:24:10 +00:00
|
|
|
if (!isFDroidBuild) {
|
|
|
|
crashlytics().recordError(e);
|
|
|
|
}
|
2019-08-31 19:22:58 +00:00
|
|
|
} else {
|
|
|
|
console.log(e);
|
|
|
|
}
|
|
|
|
};
|