2020-08-24 12:24:10 +00:00
|
|
|
import firebaseAnalytics from '@react-native-firebase/analytics';
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (!isFDroidBuild) {
|
2021-07-28 20:36:06 +00:00
|
|
|
bugsnag = require('@bugsnag/react-native').default;
|
|
|
|
bugsnag.start();
|
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 = {};
|
|
|
|
|
|
|
|
export const logServerVersion = (serverVersion) => {
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2020-06-15 14:00:46 +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
|
|
|
};
|
|
|
|
|
2019-08-31 19:22:58 +00:00
|
|
|
export default (e) => {
|
2020-08-24 12:24:10 +00:00
|
|
|
if (e instanceof Error && bugsnag && e.message !== 'Aborted' && !__DEV__) {
|
2021-07-28 20:36:06 +00:00
|
|
|
bugsnag.notify(e, (event) => {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
};
|