Endurative

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

  1. Node.js & npm/yarn installed
  2. React Native project already set up
  3. Android Studio installed (with SDK & Emulator)
  4. Firebase account and project created

2. Setup Firebase Project

  1. Go to Firebase Console → Create a new project.
  2. Add an Android App:
  3. Enter your package name (must match applicationId in android/app/build.gradle).
  4. Download the google-services.json file.
  5. Place it inside:
android/app/google-services.json

3. In Firebase → Project SettingsYour 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

  1. Run the app in debug or release mode.
  2. Use adb to verify Analytics events:
adb shell setprop debug.firebase.analytics.app your.package.name
adb logcat -s FA FA-SVC

Crashlytics

  1. Call crashlytics().crash() from your app.
  2. Reopen Firebase Crashlytics Console after 5–10 minutes to see reports.


8. Best Practices

  1. Use custom events in Analytics to understand user behavior.
  2. Log non-fatal exceptions in Crashlytics to catch edge-case errors.
  3. Test both debug and release builds.
  4. Regularly review dashboards for insights.