How to count views when content changes right on the screen

Samson Avakyan11 Nov 2026

Problem

A travel product shows hotel offers as a list of cards and a map, and search results keep arriving by polling while the user compares them. The pricing ML model needs the offers the user saw, not only the hotel finally clicked, because clicks cover only chosen hotels. The offer (price, cashback, payment, cancellation, meals) changes inside a card that stays on screen, with no reload.

Example from the article: a card shows 7,000 ₽, the next search response replaces it with 6,500 ₽, and each price is logged as a separate view if it was visible for 1.2 s.

Solution in brief

One tracker per page watches the price block of each card with Intersection Observer and stores the current offer snapshot beside it. A view is counted when the block is at least partly visible for one second. A change of offer, visibility or page action ends the open interval, checks its duration and adds the snapshot to a deduplicated buffer. A common flush sends the buffer in batches.

Questions this case answers
  • How to log which items a user actually saw when content in the visible cards is replaced in place by background updates, so that each logged view keeps the exact state that was on screen
  • How to deliver batched client-side view events before the user navigates away or closes the page, without double-counting or losing the order of events
  • How to log which hotel offers a user actually saw, including the ones never clicked, to train a pricing model?
  • How to count a view when the price in an already visible card changes after a polling update?

Tools and methods

  • Intersection Observer — visibility of the price block, one observer for many cards
  • React — hooks and context link the DOM element to the card data and share one tracker
  • Offer snapshot and key — immutable copy of price and conditions, plus a key for deduplication
  • Page lifecycle events, navigator.sendBeacon() — flush when the tab is hidden or the page is left
Continue reading — it's free

Google or a one-time email code. No password.