Zalando May 10, 2017

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

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.

The article includes a complete code implementation and compares this reactive approach against a naive state-based solution that misses key edge cases.

About This Article

Problem

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.

Solution

They built a ThrottleTrackingBus class with RxJava's PublishSubject, using distinctUntilChanged and throttleWithTimeout operators. This filtered out duplicate events and enforced the 250ms timeout.

Impact

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.