What does Firebase Analytics track automatically without any code?
Firebase Analytics automatically tracks app_open, first_open, and basic screen_view events. Custom events like purchases or button taps must be logged manually.
Track user behavior, catch crashes, and control your app remotely
You can read this lesson publicly. Sign in to unlock exercises, quiz, and FX progress tracking.
Having trouble? AI is here to help
Ask context-aware questions about this lesson. Free plan: 5 questions/day. Upgrade to Premium for higher daily limits.
Use the AI button at the bottom of the screen
Once your app is live, you need visibility into how users interact with it, what errors they encounter, and a way to change app behavior without publishing a new update. Firebase provides three essential production services for this. Google Analytics tracks user events and screen views so you can understand usage patterns. Firebase Crashlytics automatically captures crash reports with full stack traces so you can find and fix bugs quickly. Firebase Remote Config lets you change values in your app from the Firebase console without requiring users to download an update.
Google Analytics is included automatically when you add Firebase to your project. It tracks basic events like app open and screen view by default. You can also log custom events to track specific user actions such as completing a purchase, finishing a level, or sharing content. These events appear in the Firebase console where you can build audiences, create funnels, and measure retention.
1// pubspec.yaml: firebase_analytics: ^11.0.02import 'package:firebase_analytics/firebase_analytics.dart';34final analytics = FirebaseAnalytics.instance;56// Log a custom event7await analytics.logEvent(8name: 'level_completed',9parameters: {10'level_id': 5,11'score': 1200,12'time_seconds': 45,13},14);1516// Log a screen view17await analytics.logScreenView(18screenName: 'Dashboard',19screenClass: 'DashboardScreen',20);2122// Log a predefined event (purchase)23await analytics.logPurchase(24currency: 'USD',25value: 9.99,26items: [27AnalyticsEventItem(28itemName: 'Premium Plan',29itemId: 'premium_monthly',30price: 9.99,31),32],33);3435// Set user properties for audience segmentation36await analytics.setUserProperty(37name: 'subscription_type',38value: 'premium',39);4041// Set user ID to link analytics across devices42await analytics.setUserId(id: 'user_12345');4344// Use as NavigatorObserver for automatic screen tracking45MaterialApp(46navigatorObservers: [47FirebaseAnalyticsObserver(analytics: analytics),48],49);
Crashlytics gives you real-time crash reporting with detailed stack traces, device information, and the sequence of events leading up to a crash. It groups similar crashes together so you can prioritize the most impactful issues. Setting up Crashlytics in Flutter involves overriding the default error handlers to forward all uncaught errors to the Crashlytics service.
1// pubspec.yaml: firebase_crashlytics: ^4.0.02import 'package:firebase_crashlytics/firebase_crashlytics.dart';34// Setup in main.dart - catch ALL Flutter errors5void main() async {6WidgetsFlutterBinding.ensureInitialized();7await Firebase.initializeApp(8options: DefaultFirebaseOptions.currentPlatform,9);1011// Catch Flutter framework errors12FlutterError.onError =13FirebaseCrashlytics.instance.recordFlutterFatalError;1415// Catch errors outside Flutter (async, isolates)16PlatformDispatcher.instance.onError = (error, stack) {17FirebaseCrashlytics.instance.recordError(error, stack, fatal: true);18return true;19};2021// Disable in debug mode22if (kDebugMode) {23await FirebaseCrashlytics.instance24.setCrashlyticsCollectionEnabled(false);25}2627runApp(const MyApp());28}2930// Record a non-fatal error manually31try {32await riskyOperation();33} catch (e, stack) {34await FirebaseCrashlytics.instance.recordError(35e,36stack,37reason: 'riskyOperation failed',38);39}4041// Add custom keys for debugging context42FirebaseCrashlytics.instance.setCustomKey('user_level', 5);43FirebaseCrashlytics.instance.setCustomKey('screen', 'checkout');4445// Add breadcrumb log messages46FirebaseCrashlytics.instance.log('User tapped checkout button');4748// Set user identifier49FirebaseCrashlytics.instance.setUserIdentifier('user_12345');
Remote Config lets you define key-value pairs in the Firebase console and fetch them at runtime. This is extremely useful for A/B testing, feature flags, changing UI text, toggling maintenance mode, adjusting difficulty levels, or updating promotion banners without publishing a new app version. You set default values in the app and then override them from the console whenever needed.
1// pubspec.yaml: firebase_remote_config: ^5.0.02import 'package:firebase_remote_config/firebase_remote_config.dart';34final remoteConfig = FirebaseRemoteConfig.instance;56// Configure fetch settings7await remoteConfig.setConfigSettings(RemoteConfigSettings(8fetchTimeout: const Duration(minutes: 1),9minimumFetchInterval: const Duration(hours: 1),10));1112// Set default values (used before first fetch)13await remoteConfig.setDefaults({14'welcome_message': 'Welcome to our app!',15'show_banner': true,16'max_free_lessons': 5,17'maintenance_mode': false,18});1920// Fetch and activate latest values from Firebase console21await remoteConfig.fetchAndActivate();2223// Read values anywhere in your app24final welcomeMsg = remoteConfig.getString('welcome_message');25final showBanner = remoteConfig.getBool('show_banner');26final maxLessons = remoteConfig.getInt('max_free_lessons');27final inMaintenance = remoteConfig.getBool('maintenance_mode');2829// Listen for real-time config updates30remoteConfig.onConfigUpdated.listen((event) async {31await remoteConfig.activate();32// Update UI with new values33print('Config updated: ${event.updatedKeys}');34});
Always disable Crashlytics collection during development by checking kDebugMode and calling setCrashlyticsCollectionEnabled(false). This prevents test crashes from cluttering your production dashboard and makes debugging faster since crash reports are not uploaded.
In production, set minimumFetchInterval to at least one hour. During development you can set it to Duration.zero for instant updates. Fetching too frequently in production can cause throttling and your requests will fail with a fetch error.
Analytics, Crashlytics, and Remote Config are strongest when designed as one loop:
This closed loop shortens incident response time and improves product decisions with data.
Track user behavior, catch crashes, and control your app remotely. This lesson adds one more building block for creating stable and user-friendly Flutter apps.
Think in architecture, reliability, and team-level maintainability.
After reading, rewrite the concept in your own words and apply it in a tiny runnable sample.
Each lesson becomes useful when you connect concept, implementation, and real-user outcome together.
Connect this lesson to separation of concerns so your codebase stays maintainable as it grows.
As your app grows, keep UI, state, and data responsibilities separate so each part stays testable and easier to modify.
Firebase Analytics automatically tracks app_open, first_open, and basic screen_view events. Custom events like purchases or button taps must be logged manually.
Setting FlutterError.onError to FirebaseCrashlytics.instance.recordFlutterFatalError forwards all uncaught Flutter framework errors to Crashlytics automatically.
Default values ensure your app works even before the first Remote Config fetch completes or if the device is offline.
fetchAndActivate() downloads the latest values from the Firebase console and immediately makes them available via getString(), getBool(), and getInt().
Something seems incorrect, unclear, or missing? Let us know.
FlutterCraft editorial lessons are reviewed by experienced Flutter developers and updated to stay aligned with modern Flutter and Dart best practices.
Reference docs: Flutter Documentation, Dart Language Tour, and official package documentation where relevant.
Sign in to continue with exercises and quiz for this lesson.
Sign In to Continue