All features

Analytics for Flutter

Firebase Analytics behind a service interface

Only the analytics implementation imports firebase_analytics. Feature code logs through an AnalyticsService, and a pure sanitizer keeps GA4 happy.

What this feature covers

  • Events: GA4 event tracking with typed, snake_case constants.
  • Screen views: One screen-tracking mechanism wired to the router.
  • Identity: An internal user id, never PII.
  • Consent: Consent Mode v2 gathered before collection, with UMP.
  • Verification: A DebugView workflow and a release checklist.

How Flutter Agent Kit implements it

Feature code never calls FirebaseAnalytics.instance. It logs through an AnalyticsService interface read from analyticsServiceProvider, and only the Firebase implementation imports the plugin, alongside console and no-op implementations for tests and local runs. A pure-Dart AnalyticsSanitizer converts booleans to strings and drops the values GA4 rejects, since only String and num parameters exist.

Screen tracking uses exactly one mechanism, a router observer, to avoid duplicate screen_view events. Analytics runs on Android, iOS, macOS and web, where the web target is a first-class citizen rather than an afterthought.

Frequently asked questions

Why route analytics through a service instead of calling the SDK?

A direct FirebaseAnalytics.instance call is untestable and spread across the app. An AnalyticsService interface gives one boundary to change, lets tests use a console or no-op implementation, and keeps the plugin import in a single file.

Why does a boolean event parameter cause problems?

GA4 accepts only String and num parameter values, so a bool, null, Map, List or DateTime is dropped or trips an assertion. The kit sanitizes every payload in one pure-Dart place so the rule is enforced, not remembered.

Get Flutter Agent Kit

Flutter Agent Kit ships this as a ready feature skill, together with the AGENTS.md context layer and the rest of the skills. €99.99 one-time, lifetime updates, unlimited personal and commercial projects.

Browse all features included in Flutter Agent Kit.