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
Critical Insight
Using RxJava operators transforms a complex stateful tracking problem into a clean, declarative solution that fires analytics events only when users truly perceive content.