Skip to content
Back to archipelago.banuacoder.com

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 ​

VariableTypeDefaultDescription
appNamestring—The name of your application
isForMonorepobooleantrueWhether 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 — Implements AnalyticVendor using FirebaseAnalytics, registered as @Named(AnalyticInjectorKey.firebaseImpl)
  • FirebaseAnalyticsRegisterModule — Injectable module whose constructor registers the vendor key with AnalyticVendorRegistry.instance, and provides the FirebaseAnalytics.instance singleton
  • MicroPackage DI — initFirebaseAnalyticsImplModule() is annotated @InjectableInit.microPackage(), which generates FirebaseAnalyticsImplPackageModule. This package declares that class under its own archipelago: di_modules manifest, and post_gen.dart wires it into the app's injector.dart via ServiceLocatorUpdater and adds itself as a dependency of the app's pubspec.yaml — the same pattern other vendor bricks (e.g. monitoring) use. analytics_impl depends only on analytics_api and 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 ​

text
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.md

Key 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(); null values are dropped
  • User identification — setUserId maps to FirebaseAnalytics.setUserId
  • User properties — setUserProperty maps to FirebaseAnalytics.setUserProperty
  • Consent — setCollectionEnabled maps to FirebaseAnalytics.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. Requires analytics_sdk 4.0.0 or newer.
  • Reset — Full data reset via FirebaseAnalytics.resetAnalyticsData()
  • Named DI — Registered under AnalyticInjectorKey.firebaseImpl for unambiguous resolution alongside other vendors

Configuration ​

Firebase Analytics is configured through native project files — no runtime API keys are read from app_config:

FilePlatformPurpose
google-services.jsonAndroidFirebase project configuration
GoogleService-Info.plistiOSFirebase 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:

ConstraintLimitHandled by
Event name length40 characters_sanitizeEventName truncation
Parameter key length40 characters_sanitizeParameterKey truncation
String value length100 characters_sanitizeParameterValue truncation
Allowed characters[a-zA-Z0-9_]regex replacement with _

Dependencies ​

PackageVersionPurpose
firebase_analytics^12.4.6Firebase Analytics Flutter SDK
analytics_apiworkspaceVendor contract (AnalyticVendor, TrackData)
dependenciesworkspaceShared 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.