- Challenge
- Tracking calls sat directly on the Amplitude SDK inside feature screens, so staging events leaked into production and re-renders fired duplicates.
- Approach
- One typed analytics layer for the Flutter mobile and web apps: production-only routing, duplicate filtering, and a Hive buffer on the device flushed in batches.
- Impact
- About 15M events a month go through one layer. Test data stays out of production dashboards, and activity from offline sessions is sent once the connection returns.
1One layer
Screens call a single ProductAnalytics layer and never import Amplitude directly.
2Environment guard
Sandbox and dev builds log to the console. Only production reaches Amplitude.
3Drop duplicates
A sliding window hashes each event and drops repeats from re-renders and auth toggles.
4Buffer busy activity
High-frequency CRM activity is stored in Hive on the device, so it survives restarts and bad connections.
5Flush in batches
Buffered events go out in batches when the app is idle, not one request per tap.
~15M
Analytics events a month
~15M / month45M reprocess
- Surfaces
- Flutter mobile and web
- Volume
- ~15M events a month
Problem
Telemetry calls sat directly on vendor SDKs inside feature views:
- Sandbox leakage: missing or inline env guards let staging events into production Amplitude projects
- Duplicate spikes: re-renders and auth toggles re-fired
.identify()and events, skewing funnels - Chatty network: high-frequency actions paid one HTTP request each on poor mobile links
Constraints
- Identical behavior on Flutter mobile and web
- User/company traits attached automatically, not hand-copied at every call site
- Events must survive disconnects and app restarts without blocking the UI
Approach
A single ProductAnalytics facade implements AnalyticsProvider and owns routing, dedup, and accumulation:
Pieces that matter
- Vendor-agnostic facade: feature code does not import Amplitude
- Sliding-window dedup: payload hashes suppress duplicates inside the window
- Hive accumulator: high-frequency activity survives restarts and flushes in batches
- Environment isolation: sandbox/dev routes to mock logging by default
Outcomes
- Offline and flaky-network sessions stop silently dropping buffered activity once connectivity returns
- Sandbox pollution of production dashboards stopped after env routing lived in one place
- High-frequency actions stopped issuing one request per tap
The design rule is persist before transmit: every event is written to the on-device buffer before any network call, so a dropped connection delays delivery instead of costing the event its place in the queue.
Scale
Steady-state throughput is ~15M events a month. The pipeline is also sized for full replays: reprocessing runs over the whole history rather than from a checkpoint, so every replay applies the current taxonomy to every event. The largest run so far carried 45M events over a 3-month window, three times a normal month. As history grows, checkpointed replay is the next step to keep the cost of that run flat.




