trackImpression

fun Modifier.trackImpression(event: Event, threshold: Float = 0.5f, minVisibleDuration: Duration = Duration.ZERO): Modifier(source)

Tracks event once, when at least threshold of this layout is visible on screen. With a minVisibleDuration, it has to stay that visible for that long first; leaving earlier cancels the count.

"Visible" means inside the window after clipping by parents: half of a list item under the app bar is half visible. Something drawn over the layout, such as a dialog, does not count as hiding it.

It fires once per appearance. A list item that scrolls off and back on counts again. If the same item should count only once per session, keep that rule in the caller.

Use a data class for a parameterised event, or remember it. A new, unequal event restarts the count.

Does nothing in previews and in the layout inspector.