2020-08-24 12:24:10 +00:00
|
|
|
import firebaseAnalytics from '@react-native-firebase/analytics';
|
2021-09-13 20:41:05 +00:00
|
|
|
|
2022-04-07 14:10:03 +00:00
|
|
|
import { isFDroidBuild } from '../../lib/constants';
|
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 || '';
|
2022-01-12 12:54:04 +00:00
|
|
|
let bugsnag: any = '';
|
|
|
|
let crashlytics: any;
|
2021-08-23 14:15:01 +00:00
|
|
|
let reportCrashErrors = true;
|
|
|
|
let reportAnalyticsEvents = true;
|
|
|
|
|
2022-01-12 12:54:04 +00:00
|
|
|
export const getReportCrashErrorsValue = (): boolean => reportCrashErrors;
|
|
|
|
export const getReportAnalyticsEventsValue = (): boolean => reportAnalyticsEvents;
|
2021-08-23 14:15:01 +00:00
|
|
|
|
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;
|
|
|
|
},
|
2022-01-12 12:54:04 +00:00
|
|
|
onError(error: { breadcrumbs: string[] }) {
|
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 = {};
|
|
|
|
|
2022-01-12 12:54:04 +00:00
|
|
|
export const logServerVersion = (serverVersion: string): void => {
|
2020-02-28 19:51:13 +00:00
|
|
|
metadata = {
|
|
|
|
serverVersion
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-01-12 12:54:04 +00:00
|
|
|
export const logEvent = (eventName: string, payload?: { [key: string]: any }): void => {
|
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
|
|
|
};
|
|
|
|
|
2022-01-12 12:54:04 +00:00
|
|
|
export const setCurrentScreen = (currentScreen: string): void => {
|
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
|
|
|
};
|
|
|
|
|
2022-01-12 12:54:04 +00:00
|
|
|
export const toggleCrashErrorsReport = (value: boolean): boolean => {
|
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
|
|
|
};
|
|
|
|
|
2022-01-12 12:54:04 +00:00
|
|
|
export const toggleAnalyticsEventsReport = (value: boolean): boolean => {
|
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
|
|
|
};
|
|
|
|
|
2022-01-12 12:54:04 +00:00
|
|
|
export default (e: any): void => {
|
2020-08-24 12:24:10 +00:00
|
|
|
if (e instanceof Error && bugsnag && e.message !== 'Aborted' && !__DEV__) {
|
2022-01-12 12:54:04 +00:00
|
|
|
bugsnag.notify(e, (event: { addMetadata: (arg0: string, arg1: {}) => void }) => {
|
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 {
|
2022-01-26 03:06:00 +00:00
|
|
|
console.error(e);
|
2019-08-31 19:22:58 +00:00
|
|
|
}
|
|
|
|
};
|