Migration Guides topic
Migration Guides
Instrumentation rarely starts from a clean slate. This guide walks through migrating existing analytics stacks to analytics_gen while keeping downstream dashboards stable. Each section covers a common provider (Firebase Analytics manual strings, Amplitude, Mixpanel) and calls out mapping strategies, validation tips, and rollout sequencing.
Shared Migration Checklist
- Inventory current events - export the list of event names + parameters from your existing provider. Include descriptions, allowed values, and any downstream dependency (dashboards, alerts, contractual SLAs).
- Define YAML domains - group events by ownership (auth, screen, purchase) and create
events/<domain>.yamlfiles. Usedescription,parameters,deprecated, andreplacementmetadata to capture the current behavior. - Configure naming strategy - update
analytics_gen.yamlwithidentifier_template,domain_aliases, and parameter overrides so the generated identifiers match your provider expectations. - Generate + review artifacts - run
dart run analytics_gen:generate --docs --exportsand inspect generated Dart/doc/export diffs just like production code. - Wire runtime providers - implement
IAnalytics(or wrap the SDK you already use) and initialize the generatedAnalyticssingleton in your app bootstrap. - Roll out gradually - release instrumentation file-by-file or screen-by-screen. Keep deprecated events emitting until stakeholders confirm the new events are live.
- Plan for rollback - for each domain change, include a short rollback plan (e.g., revert the YAML change or re-enable the legacy helper) in case of data issues.
Firebase Analytics (manual logEvent strings)
Firebase allows arbitrary event names and parameter maps, so migrations are usually about consistency:
- Normalize identifiers - map every historical
logEvent('foo_bar')call into YAML entries. UsecustomEventNamewhen you must keep the exact Firebase string, and setidentifierto the new canonical name so the generated code stays idiomatic. - Parameter metadata - define
type,description,allowed_values, and per-parameteridentifier/param_namepairs. Firebase dashboards often rely on snake_case keys; keep them viaparam_namewhile the generated Dart uses camelCase. - Deprecations - for legacy events you intend to replace, set
deprecated: trueplusreplacement. The generator emits@Deprecatedannotations so call sites are easy to find. - Runtime provider - if you already wrap
FirebaseAnalytics, implementIAnalyticsby delegating tologEventwith the generatedname+parameters. You can stackMultiProviderAnalyticsorBatchingAnalyticsas needed. - Cut-over - replace manual
logEventcalls with generated mixins domain-by-domain. Use CI to ensure developers runanalytics_gen:generateso Firebase stays in sync with YAML.
Amplitude
Amplitude events typically include descriptive names ("User Signed Up") and a mix of super properties + event props.
- Event naming - set
customEventNameto the human-friendly Amplitude strings and keep identifiers snake_case (auth.signup_completed). This preserves your Amplitude taxonomy while keeping Dart ergonomic. - Property mapping - document every property under
parameterswithdescription,type, and allowed values. When a property is optional, mark it as nullable (string?). - Super properties / user properties - expose provider-specific behavior through capabilities (e.g.,
UserPropertiesCapability) rather than custom mixin code. The controller or service layer can request the capability when needed. - QA - run Amplitude's "event stream" alongside the generated
MockAnalyticsServiceduring staging to ensure required properties are present before shipping.
Mixpanel
Mixpanel projects often have strict property schemas and roll-up dashboards.
- Flatten tokens - Mixpanel likes
PascalCaseorsnake_casekeys; configureparam_nameoverrides to keep compatibility while letting the generated Dart use idiomatic names. - Batching - Mixpanel benefits from batching on mobile. Use
BatchingAnalytics+AsyncAnalyticsAdapterso UI code stays synchronous while uploads happen in the background. - Rollout strategy - ship the generated mixins in parallel with legacy helpers. Validate using Mixpanel's live view, then delete the legacy helper once dashboards confirm parity.
- Exports - hand the generated CSV/JSON exports (
assets/generated/) to analysts so they can diff against Mixpanel's official plan.
Verification Tips
- Add a dedicated integration test that wires
MockAnalyticsServiceand asserts that each domain action emits the expected event names/parameters. This ensures parity during the migration window. - Keep
docs/analytics_events.mdand exports committed so reviewers can spot accidental regressions. - Use the new Flutter example (
example/) as a sandbox for teaching developers how to depend on generated mixins through controllers instead of callingAnalytics.instanceeverywhere.
Need another provider or deeper steps? Open a doc issue with the target SDK + quirks and we will extend this guide.
Libraries
- analytics_gen Overview Onboarding Validation & Naming Capabilities Migration Guides Scalability & Performance Code Review
- Analytics Gen - Type-safe analytics event tracking with code generation.