Analytics Implementations
firebase_analytics_impl Free
- Tier
- Freeversion 1.3.6
- Command
archipelago generate firebase_analytics_impl- Generates
infrastructure/firebase_analytics_impl
- Generates first
- analytics_sdkwhen needed and missing, so there is nothing to install first
Firebase Analytics vendor implementation for the analytics_api contract.
Variables
| Variable | Type | Default | Description |
|---|---|---|---|
| appName | string | — | The name of your application |
| isForMonorepo | boolean | true | Whether this is being generated as part of a monorepo |
Prerequisites
Needs analytics_sdk (4.0.0 or newer). This package's own code imports analytics_api. When infrastructure/analytics_api is missing, pre_gen generates analytics_sdk first, so the brick can be added on its own. post_gen patches the app's pubspec.yaml and injector; it never touches analytics_impl.
Firebase itself: Firebase must be configured with flutterfire configure: see Firebase Setup. The brick wires a guarded Firebase.initializeApp() into bootstrap.dart (before initializeInjector()). Without Firebase config the app still boots and this vendor is skipped with a debug message.
Architecture
This brick generates a single vendor implementation package that plugs into the analytics_sdk orchestration layer:
FirebaseAnalyticsVendor— ImplementsAnalyticVendorusingFirebaseAnalytics, registered as@Named(AnalyticInjectorKey.firebaseImpl)FirebaseAnalyticsRegisterModule— Injectable module whose constructor registers the vendor key withAnalyticVendorRegistry.instance, and provides theFirebaseAnalytics.instancesingleton- MicroPackage DI —
initFirebaseAnalyticsImplModule()is annotated@InjectableInit.microPackage(), which generatesFirebaseAnalyticsImplPackageModule. This package declares that class under its ownarchipelago: di_modulesmanifest, andpost_gen.dartwires it into the app'sinjector.dartviaServiceLocatorUpdaterand adds itself as a dependency of the app'spubspec.yaml— the same pattern other vendor bricks (e.g. monitoring) use.analytics_impldepends only onanalytics_apiand is never touched.
Unlike other vendor bricks, this implementation does not depend on app_config because FirebaseAnalytics.instance is configured via the google-services.json / GoogleService-Info.plist files placed in the native project.
Generated Structure
infrastructure/
└── firebase_analytics_impl/
├── lib/
│ ├── firebase_analytics_impl.dart # Package barrel export
│ └── src/
│ ├── firebase_analytics_vendor.dart # AnalyticVendor impl
│ └── di/
│ ├── injector.dart # microPackage DI entry (@InjectableInit.microPackage())
│ ├── injector.module.dart # pre-built generated output, committed
│ └── register_module.dart # FirebaseAnalytics provider
├── test/src/firebase_analytics_vendor_test.dart
├── pubspec.yaml
└── README.mdKey Features
- Event name sanitization — Event names are cleaned to alphanumeric + underscore characters, collapsed to single underscores, and truncated to Firebase's 40-character maximum
- Parameter key sanitization — Parameter keys receive the same treatment (alphanumeric + underscore, max 40 chars)
- Parameter value coercion — Values are coerced to Firebase-compatible types: strings are truncated at 100 chars; lists and maps are converted via
toString();nullvalues are dropped - User identification —
setUserIdmaps toFirebaseAnalytics.setUserId - User properties —
setUserPropertymaps toFirebaseAnalytics.setUserProperty - Consent —
setCollectionEnabledmaps toFirebaseAnalytics.setAnalyticsCollectionEnabled, so revoking analytics consent stops collection. Native auto-collection is off by default (firebase_analytics_collection_enabled/FIREBASE_ANALYTICS_COLLECTION_ENABLED= false) until consent turns it on. Requiresanalytics_sdk4.0.0 or newer. - Reset — Full data reset via
FirebaseAnalytics.resetAnalyticsData() - Named DI — Registered under
AnalyticInjectorKey.firebaseImplfor unambiguous resolution alongside other vendors
Configuration
Firebase Analytics is configured through native project files — no runtime API keys are read from app_config:
| File | Platform | Purpose |
|---|---|---|
google-services.json | Android | Firebase project configuration |
GoogleService-Info.plist | iOS | Firebase project configuration |
Follow the FlutterFire setup guide to generate and place these files.
Firebase Constraints
Firebase Analytics enforces strict limits that this vendor handles automatically:
| Constraint | Limit | Handled by |
|---|---|---|
| Event name length | 40 characters | _sanitizeEventName truncation |
| Parameter key length | 40 characters | _sanitizeParameterKey truncation |
| String value length | 100 characters | _sanitizeParameterValue truncation |
| Allowed characters | [a-zA-Z0-9_] | regex replacement with _ |
Dependencies
| Package | Version | Purpose |
|---|---|---|
firebase_analytics | ^12.4.6 | Firebase Analytics Flutter SDK |
analytics_api | workspace | Vendor contract (AnalyticVendor, TrackData) |
dependencies | workspace | Shared DI annotations (injectable) |
Changelog
Run archipelago brick info firebase_analytics_impl to see the latest published version. Enterprise customers can read the full CHANGELOG.md in the brick source repository.