Impression Tracker ? wth is that

Alham Wahyuanda
Style Theory Engineering & Data
2 min readJun 26, 2019
Photo by João Silas on Unsplash

Sometimes, we want to know how many items on browse page that already user sees. To achieve that, we need something to track it and this something we can call it as impression tracker. This tracker consists of third library (ex: firebase event track) and some code to implement it in application. So here how we can create impression tracker and implement it in our application.

First of all, we will define that view should be tracked if 75% of its height is visible.

Let’s rock the code !!!

Basic idea is that we will observe visible and invisible height each item on recylerView and compare it to get the percentage of visible height. when the visible height passed the minimum visible height, then it’s mean that item should be tracked.

In above picture, there a 3 items. Item 1st and 2nd already passed the minimum visible height, so those 2 items already tracked. For 3rd item, the view have not passed the minimum visible height. When user scrolled up and the 3rd item visible height reach the minimum visible height, then this item ready to be tracked.

Now, how do we will measure the visible and invisible height of each item ??

Don’t worry, android have provide “addOnScrollListener” to listen every scroll occur on recyclerView.

Inside “onScrolled()” we will get the first visible and last visible item then measure each items height.

“getLocalVisibleRect()” used to get visible height while “view.measuredHeight” used to get invisible height, then compare those to get visible height percentage. If the result more than 75% then view should be tracked.

Furthermore, we can add more condition like user’s time spent to measure whether view should be tracked or not. You can check my github to get full insight about impression tracker.

--

--