Skip to content
Back to archipelago.banuacoder.com

Analytics Implementations

How to add Firebase Analytics to a Flutter app with analytics_sdk ​

Free Reference for firebase_analytics_impl: every variable, option and package it generates. Command: archipelago generate firebase_analytics_impl

Generate the Firebase Analytics vendor, configure Firebase with native config files, see how it self-registers, and verify events and consent.

What you'll learn ​

  • Generating the Firebase Analytics vendor for analytics_sdk
  • Configuring Firebase with native config files
  • Seeing how the module registers itself
  • Verifying events and consent behavior

Prerequisites ​

Generate analytics_sdk first. This brick does not check for it. The workspace fails to resolve without it.

Step 1: Generate the Brick ​

Skip this step if you chose firebase in analyticsVendors at project creation.

bash
archipelago generate firebase_analytics_impl

The prompts are:

  • appName: the name of your app
  • isForMonorepo: leave this as true

The brick creates infrastructure/firebase_analytics_impl/. It also adds a guarded Firebase.initializeApp() to bootstrap.dart before initializeInjector().

Step 2: Add Native Config Files ​

Firebase reads credentials from native files. You set no keys in app_config. Run flutterfire configure, or place the files by hand:

  • Android: android/app/google-services.json
  • iOS: ios/Runner/GoogleService-Info.plist

Follow the FlutterFire setup guide if Firebase is new to your app. Without Firebase config, the app still boots and this vendor is skipped with a debug message.

Step 3: Check the Registration ​

You register nothing by hand. The post-generation hook adds the package to the app pubspec.yaml and registers FirebaseAnalyticsImplPackageModule in lib/di/injector.dart.

The vendor registers itself under AnalyticInjectorKey.firebaseImpl. The tracker finds it through AnalyticVendorRegistry, so events flow with no more wiring.

Step 4: Verify Events Flow ​

Grant analytics consent, then track an event. Open the Firebase console, then DebugView, to see events arrive.

The vendor cleans the data for you:

  • Event names and parameter keys keep letters, digits and underscores, up to 40 characters.
  • String values are cut at 100 characters.
  • Lists and maps become strings, and null values are dropped.

Native auto-collection is off until consent turns it on. setCollectionEnabled calls setAnalyticsCollectionEnabled. Revoking consent stops collection. reset() calls resetAnalyticsData().

Next Steps ​