Context
In 2023 I designed and mostly wrote the client analytics framework for the learner apps, in React Native and Next.js. A teammate co-wrote much of the event catalogue under my review.
The problem
The company had no first-party, event-level learner data: watch time, page time, mock-test behaviour or checkout funnel. One emit path had to work in React Native and in Next.js server rendering, survive offline use and app kills, and not flood the backend.
What I did
I built middleware on Redux actions. An allow-list of actions becomes typed events, so screens never call analytics directly.
I added batching: flush at 20 events, cap at 250, retry failed batches every 3 minutes, and restore a failed batch to the queue.
I persisted the queue, a device ID and a visitor ID, so events survive an app kill or an offline stretch.
I sampled watch time every 10 seconds and aggregated it per lesson, and added an inactivity tracker that stops time-spent counting when the user is idle.
I added a second sink for selected events, such as play failures. There were 36 event types by September 2023.
Key decision
I derived events from actions in middleware instead of instrumenting each screen. That kept screens clean and made rollout fast.
The trade-off was that events were untyped and tied to action names. I replaced that approach in 2026 with explicit typed emits.
Result
The framework fed the events service in both apps and gave the company its first event-level learner data. I do not have event-volume figures from this period, so I do not quote any.
The 2026 ProductEventHub work replaced it.
What I learned
I would keep the batching, persisted queue and inactivity rules. I would use explicit typed emits from the start, which is what I moved to later.
Stack
- TypeScript
- React Native
- Next.js
- Redux
- Mixpanel
