A simple module for just Firebase Crashlytics; in case you still can't update your firebase setup for God-knows-what reasons you might have.
Code is heavily inspired by invertase/react-native-firebase.
Follow Crashlytic's installation instructions for iOS and Android, then install the package:
$ yarn add @elcoach/react-native-crashlytics
$ npm install @elcoach/react-native-crashlytics --save
$ react-native link @elcoach/react-native-crashlytics
Versions used in this module:
firebase-analytics:
17.5.0
firebase-crashlytics:
17.2.1
import RnCrashlytics, { initCrashlytics } from '@elcoach/react-native-crashlytics';
const logDetails = () => {
// log app version
RnCrashlytics.setValueForKey('app_version', '2.0-alpha');
RnCrashlytics.setValueForKey('some_other_key', 'some other value');
}
const cleanUp = () => {
console.log('we crashed pretty hard');
}
initCrashlytics (
userId = 'unique_user_id_goes_here',
beforeLog = logDetails,
afterLog = cleanUp
);
// you can be really creative here, sky is the limit.
RnCrashlytics.crash();
By default, js errors are reported as non-fatal exceptions, while native errors are reported as fatal exceptions.
If you want to force-report all erros as fatal you can use the forceFatal
flag (default – false):
initCrashlytics (
userId = ...,
beforeLog = ...,
afterLog = ...,
forceFatal = true
);