epoxy icon indicating copy to clipboard operation
epoxy copied to clipboard

Trigger visibility track in onResume

Open nlgtuankiet opened this issue 5 years ago • 3 comments

The use case is I want to retrigger the visibility state changed callback when the user came back to a screen.

From an analytic point of view, in case we want to check a widget's full impression, when the user first enters the screen, if the widget is fully visible to the user then we fire one event. When the user came back to that screen, if they see that widget again, we should also fire another event. The idea is we want to track the click-through rate of a widget (click/view)

Current behavior, visibility fire only one, not fire again when the user came back to the screen (because the view has stayed at the same spot when the user left the screen, so no visibility state changed there)

nlgtuankiet avatar Aug 13 '20 05:08 nlgtuankiet

We had the same requirement, and we managed to achieve this by calling

visibilityTracker.clearVisibilityStates()
visibilityTracker.requestVisibilityCheck()

in onResume.

But we had another problem when we call these in a fragment. It appears that during onResume the views are not drawn on the screen yet, so checking the visibility will give the result of INVISIBLE, which caused our impression events to not get triggered at users' first entering, UNLESS the user starts to scroll.

Sadly we have to use a hack to resolve the above issue:

visibilityTracker.clearVisibilityStates()
view.postDelayed(300) {
            // FIXME: delay hack to request visibility check after the fragment is fully visible
            // calling immediately has no effect cuz the tracker sees the views as not drawn yet
            visibilityTracker.requestVisibilityCheck()
}

Any ideas on how to solve this more properly?

xiaoyuin avatar Sep 08 '20 11:09 xiaoyuin

What would be great is to build a sample project where we can reproduce the issue. It is hard to find a better way without seeing the code. Is it something you can do?

eboudrant avatar Sep 08 '20 22:09 eboudrant

visibilityTracker.clearVisibilityStates()
visibilityTracker.requestVisibilityCheck()

This is useful for monitoring the visibility state and starting my impression events, with the exception of the things inside Carousel. Is there any way to make the items inside CarouselModel_ to trigger VisibilityCheck when the page resumes?

vibindas-m avatar May 28 '24 03:05 vibindas-m