Impression Tracker ? wtf is that (2)

Alham Wahyuanda
Style Theory Engineering & Data
3 min readMar 29, 2020
Photo by Lukas Blazek on Unsplash

In my previous post about Impression Tracker, I just consider the view percentage which already visible to user. Then a problem come, my tracker will track all the item that already scrolled although the user did not really see the item and not get the impression of that. I think this is not right, because the goal is to know how user impression when see each item. One missing key is the time. To tracking user impression, we must consider time that user spend on each item, not only from view visibility.

Now, how to add time variable to my previous tracker ? The easiest way is using CountDownTimer. Don’t worry about threading, CountDownTimer will manage its own thread. We just to make sure the timer stop when item not visible in screen.

Lets define the prerequites :

  • Minimal 60% view visible on screen
  • The time user spend on each item is 20000 ms/ 10s
  • Only track the untracked view

Let’s cook it together !!

We need to make a pilot of data that will hold the CountDownTimer for each item, we will call it as TimeTrackHolder.

There are 2 variable, isTracked and onTracking. Variable isTracked is used to determine is item already tracked or not. Variable onTracking is used to determine is item on tracking or not. We will use these variable to manage item tracking state later.

Let’s back to MainActivity. Create new variable that will hold the item TimeTrackHolder.

To manage tracking state of each item, we need to create a function called checkTrackedDataState().

Above function will check whether item visible on screen or not, if not visible then the timer will be stop.

We need another function to accomplish our goal. This function will determine visibility percentage then add new TimeTrackHolder or if already added to trackedData, the timer will be start again if not tracked yet.

Function trackViewHeightAndTime() will stop the timer if view percentage below the threshold (60%). The third input argument is var function that will invoked when user viewing item for 20s.

All the ingredients already prepared, time to pour it all and accomplish our goal.

Put checkTrackedDataState() below the first and last visible item. It is important, because we need to stop the timer if the item is no longer visible on screen. Then put trackViewHeightAndTime() inside looping to check every visible item on screen.

trackViewHeightAndTime(visibleHeightPercent, position) {
Log.d("TAG", "$position")
}

When item view already seen at least 60% and user visible on screen for 20s, it will print the the tracked position to logcat. That’s it. Simple and thread safe for sure.

Conclusion …

Impression tracker will be more accurate if we consider the time user spend on viewing item. To accomplish that, the easiest way is using CountDownTimer. Sure we can replace it with another, for example we can use bounce() function from RxJava. Maybe later I think .

You can check my github to get full insight about impression tracker. Thank you

--

--