This skill defines how to correctly implement Firebase Analytics in Flutter applications, covering setup, event logging, user properties, and data collection best practices.
Use this skill when:
flutter pub add firebase_analytics
flutter run
import 'package:firebase_analytics/firebase_analytics.dart';
// After Firebase.initializeApp():
FirebaseAnalytics analytics = FirebaseAnalytics.instance;
FirebaseAnalyticsWithoutAdIdSupport instead of the default iOS dependency to avoid App Store review questions about advertising identifiers:
FIREBASE_ANALYTICS_WITHOUT_ADID=true when building (FIREBASE_ANALYTICS_WITHOUT_ADID=true flutter build ios).pod 'FirebaseAnalytics', :modular_headers => true and pod 'FirebaseAnalyticsWithoutAdIdSupport', :modular_headers => true to your Podfile.MaterialApp(
navigatorObservers: [
FirebaseAnalyticsObserver(analytics: FirebaseAnalytics.instance),
],
);
For GoRouter, log screen views manually on route changes:
GoRouter(
observers: [FirebaseAnalyticsObserver(analytics: FirebaseAnalytics.instance)],
);
Firebase.initializeApp() completes before accessing FirebaseAnalytics.instance.first_open, session_start) appear without extra code.Use predefined event methods when possible for maximum detail in reports and access to future Google Analytics features:
await FirebaseAnalytics.instance.logSelectContent(
contentType: "image",
itemId: itemId,
);
Use the general logEvent() method for both predefined and custom events:
await FirebaseAnalytics.instance.logEvent(
name: "select_content",
parameters: {
"content_type": "image",
"item_id": itemId,
},
);
Future<void> logAddToCart(String productId, String productName, double price) async {
await FirebaseAnalytics.instance.logEvent(
name: 'add_to_cart',
parameters: {
'product_id': productId,
'product_name': productName,
'price': price,
'currency': 'USD',
},
);
}
firebase_, google_, and ga_ are reserved — do not use them for parameter names.Set default parameters for all future events (not supported on web):
await FirebaseAnalytics.instance.setDefaultEventParameters({
'app_version': '1.2.3',
'environment': 'production',
});
Clear a default parameter by setting it to null.
await FirebaseAnalytics.instance.setUserProperty(
name: 'favorite_food',
value: favoriteFood,
);
Set the user ID to correlate events across devices:
await FirebaseAnalytics.instance.setUserId(id: 'user_12345');
adb shell setprop debug.firebase.analytics.app <package_name>
-FIRDebugEnabled to scheme arguments in Xcode.