Analytics tools like PostHog charge by the number of events. The free tier is generous, so a small app should never run out. Ours used up the free monthly event quota within a few days.
The cause was in our own code. Our product spec listed events like "user started typing their email" and "user moved the loan amount slider". We hooked them up in the obvious place: onChanged. In Flutter, a text field's onChanged runs on every keystroke, and a slider's onChanged runs on every step it crosses while the user drags. An email address became twenty events. One drag across the slider became dozens. Multiply that by every field on every registration screen, then by every user, and the quota was gone.
You can't see this in the PostHog dashboard. The event names were exactly what the spec asked for and the funnels looked right. There were just far too many of them.
The fix kept every event name and property the same. It only changed when they fire:
- Text fields: fire once per screen visit, on the first edit. A
bool _emailInputFiredflag on the screen state does it. If you need the final value (only as a non-sensitive property, like "is valid"), fire when the field loses focus instead. - Sliders: move the event from
onChangedtoonChangeEnd, so it fires once per drag, when the user lets go. - Scrolls: the same idea. Listen for
ScrollEndNotificationrather than every scroll update.
Check if this applies to you
Applies if: a Flutter app that sends events to PostHog (or any analytics service billed per event). Read-only steps:
grep -rn "onChanged\|addListener\|NotificationListener<ScrollNotification>\|ScrollUpdateNotification" lib/- For each hit, read the callback (and any method it calls) for
Posthog().capture, your own capture wrapper, or an analyticslogcall.
Has the problem: a capture call runs inside an onChanged, a TextEditingController / ScrollController listener, or a scroll-update handler, without a once-only flag or debounce in front of it. Doesn't have it: every capture inside those callbacks sits behind a once-per-visit flag, or is in onChangeEnd / a focus-lost handler / ScrollEndNotification instead.
Reproduce this
Prerequisites: a Flutter app using posthog_flutter (or another per-event-billed analytics SDK) with capture calls in widget callbacks.
Your agent will need from you: which of the events are allowed to stay per-change (usually none); whether any event must carry the field's final value.
Steps:
- Run the check above and list every capture inside
onChanged, a controller listener, or a scroll-update handler. - Text fields: add a
bool _<field>InputFired = false;to the screen state. InonChanged, capture onlyif (!_<field>InputFired)and set the flag. If the state object survives navigation between steps, put the flag there and decide whether "once" means per visit or per flow. - Tap/focus events: capture in a
FocusNodelistener only whenhasFocus && !_tapFired. - Events that need the final value: capture in the
FocusNodelistener when focus is lost (!hasFocus), not inonChanged. - Sliders: move the capture from
onChangedtoonChangeEnd. KeeponChangedfor updating the UI only. - Scrolls: capture from
NotificationListener<ScrollEndNotification>, never fromScrollUpdateNotificationor aScrollControllerlistener. - Keep event names and properties unchanged, so existing dashboards and funnels keep working.
Verify: run a debug build with PostHogConfig.debug = true. Type a 20-letter value into a fixed field: the log shows one *_input capture, not twenty. Drag a slider end to end: one event when you let go. In PostHog → Activity, the event count per session for these events drops to 1.