Detecting List Items Observed by User
Article Summary
Zalando's engineering team faced a tricky challenge: how do you know if a user actually *saw* an item in a scrolling list, not just flew past it?
The team needed to track when users viewed RecyclerView items for at least 250ms, accounting for rapid scrolling and multiple callbacks. Their solution combines RxJava operators with Android's scroll listeners to create an elegant tracking system.
Key Takeaways
- RxJava's distinctUntilChanged filters duplicate scroll callbacks from single swipe gestures
- throttleWithTimeout delays tracking 250ms and cancels if user scrolls away
- Approach avoids performance hits from processing every scroll callback individually
- PublishSubject creates event bus that handles visibility state changes reactively
Using RxJava operators transforms a complex stateful tracking problem into a clean, declarative solution that fires analytics events only when users truly perceive content.
About This Article
Zalando's team had to tell the difference between actual item views and the multiple scroll callbacks that fire during a single swipe. They also needed to make sure users kept items visible for at least 250 milliseconds before sending any analytics events.
They built a ThrottleTrackingBus class with RxJava's PublishSubject, using distinctUntilChanged and throttleWithTimeout operators. This filtered out duplicate events and enforced the 250ms timeout.
The RxJava approach cut down the performance cost of handling every single scroll callback. They got efficient tracking without needing separate Activity lifecycle tricks or timestamp management on individual items.