Firebase Crashlytics
Firebase Crashlytics tracks crashes and errors in your app in real time. When your app crashes or throws an unhandled error, Crashlytics records the error, the stack trace, the device details, and what the user was doing just before the crash. This turns invisible bugs into actionable reports you can fix.
Why Crashlytics Matters
Most app crashes go unreported. Users experience them, close the app, and move on — rarely bothering to tell you. Crashlytics is a silent reporter sitting inside your app. It catches every crash automatically and sends you the details, even when users say nothing.
Without Crashlytics:
User experiences crash --> closes app --> you never know
With Crashlytics:
User experiences crash --> Crashlytics records all details
--> sends crash report to Firebase
--> you see it in the console within minutes
--> you fix it in the next release
Crashlytics for Web vs Mobile
Crashlytics has full native support for iOS and Android apps. For web apps, Firebase provides a JavaScript error tracking approach using the Performance Monitoring SDK combined with manual error logging, since web browsers handle crash recovery differently from native apps.
This topic covers the Crashlytics SDK for React Native and mobile platforms, and manual error reporting for web apps.
Setting Up Crashlytics (React Native / Mobile)
For React Native apps using @react-native-firebase:
npm install @react-native-firebase/app @react-native-firebase/crashlytics
Crashlytics starts collecting crash reports automatically after installation and app restart. No additional initialization code is needed for basic crash tracking.
Logging Custom Error Messages
import crashlytics from "@react-native-firebase/crashlytics";
// Log a message to appear in the crash report
crashlytics().log("User tapped the checkout button.");
// Record a JavaScript error manually
try {
const result = await processPayment(cart);
} catch (error) {
crashlytics().recordError(error);
showErrorMessage("Payment failed. Please try again.");
}
Setting User Identifiers
Attach a user identifier to crash reports so you know which users are affected:
await crashlytics().setUserId(auth.currentUser.uid);
Crashlytics does not store personally identifiable information by default. Use a UID rather than an email address.
Custom Attributes
Add custom key-value pairs to crash reports for extra debugging context:
await crashlytics().setAttribute("payment_method", "credit_card");
await crashlytics().setAttribute("cart_item_count", "3");
await crashlytics().setAttribute("checkout_step", "address_entry");
These attributes appear alongside every crash report from this session, helping you reproduce the issue.
Web Error Tracking
For web apps, capture unhandled errors and report them to Firestore or a logging service:
// Catch all unhandled JavaScript errors
window.addEventListener("error", (event) => {
logErrorToFirestore({
message: event.message,
filename: event.filename,
line: event.lineno,
column: event.colno,
stack: event.error ? event.error.stack : null,
userId: auth.currentUser ? auth.currentUser.uid : "anonymous",
timestamp: new Date().toISOString(),
url: window.location.href
});
});
// Catch unhandled promise rejections
window.addEventListener("unhandledrejection", (event) => {
logErrorToFirestore({
message: event.reason ? event.reason.message : "Unhandled promise rejection",
stack: event.reason ? event.reason.stack : null,
userId: auth.currentUser ? auth.currentUser.uid : "anonymous",
timestamp: new Date().toISOString()
});
});
async function logErrorToFirestore(errorData) {
const db = getFirestore();
await addDoc(collection(db, "error_logs"), errorData);
}
Reading Crashlytics Reports
Go to the Firebase Console and click Crashlytics in the left sidebar. The dashboard shows:
- Crash-free user percentage — the most important top-level metric
- Issues list — unique crash signatures grouped by stack trace
- Number of users affected per issue
- Session logs leading up to each crash
- Device and OS version breakdown
Click any issue to see the full stack trace, the breadcrumb log of what the user did before the crash, and the device details at the time of the crash.
Setting Up Crash Alerts
Receive email alerts when new crash types appear: go to Crashlytics > Settings and enable crash alerting. Firebase emails you when a crash type appears for the first time or spikes above a threshold.
Key Takeaway
Crashlytics captures crash details automatically the moment a crash occurs, without users needing to report anything. For mobile apps, install the Crashlytics SDK and use recordError for caught exceptions and setAttribute for debugging context. For web apps, use global error listeners to log errors to Firestore. Monitor the crash-free user percentage in the console as your primary app health metric.
