Firebase Analytics & Crashlytics Integration in React Native (Android)
This guide will walk you through step-by-step integration of Firebase Analytics and Firebase Crashlytics into a React Native Android app. By the end, you will be able to track user behavior and capture app crashes in real-time.
1. Prerequisites
- Node.js & npm/yarn installed
- React Native project already set up
- Android Studio installed (with SDK & Emulator)
- Firebase account and project created
2. Setup Firebase Project
- Go to Firebase Console → Create a new project.
- Add an Android App:
- Enter your package name (must match applicationId in android/app/build.gradle).
- Download the google-services.json file.
- Place it inside:
android/app/google-services.json
3. In Firebase → Project Settings → Your Apps, enable Google Analytics for the project.
3. Install Required Packages
Run the following commands in your React Native project root:
# Firebase core
yarn add @react-native-firebase/app
# Firebase Analytics
yarn add @react-native-firebase/analytics
# Firebase Crashlytics
yarn add @react-native-firebase/crashlytics
4. Configure Android
Step 4.1: Update Gradle Settings
Edit android/build.gradle:
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.4.2'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.9'
}
}
Edit android/app/build.gradle:
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
Step 4.2: Add Firebase Dependencies
Inside android/app/build.gradle:
dependencies {
implementation platform('com.google.firebase:firebase-bom:33.1.2')
// Analytics
implementation 'com.google.firebase:firebase-analytics'
// Crashlytics
implementation 'com.google.firebase:firebase-crashlytics'
}
5. Analytics Usage
In your React Native code:
import analytics from '@react-native-firebase/analytics';
// Log events
async function logEvents() {
await analytics().logEvent('app_opened', {
source: 'manual_test',
});
await analytics().logScreenView({
screen_name: 'HomeScreen',
screen_class: 'Home',
});
}
Events and user behavior can be monitored in the Firebase Analytics Dashboard.
6. Crashlytics Usage
Import Crashlytics:
import crashlytics from '@react-native-firebase/crashlytics';
// Log non-fatal error
crashlytics().log('User visited HomeScreen');
// Record a custom error
try {
throw new Error('Test error for Crashlytics');
} catch (err) {
crashlytics().recordError(err);
}
// Force crash (for testing)
function crashApp() {
crashlytics().crash();
}
Crashes will appear in Firebase Crashlytics Dashboard within a few minutes.
7. Testing Setup
Analytics
- Run the app in debug or release mode.
- Use adb to verify Analytics events:
adb shell setprop debug.firebase.analytics.app your.package.name
adb logcat -s FA FA-SVC
Crashlytics
- Call crashlytics().crash() from your app.
- Reopen Firebase Crashlytics Console after 5–10 minutes to see reports.
8. Best Practices
- Use custom events in Analytics to understand user behavior.
- Log non-fatal exceptions in Crashlytics to catch edge-case errors.
- Test both debug and release builds.
- Regularly review dashboards for insights.