Contentful Personalization & Analytics
    Preparing search index...
    • Tracks whether an entry is visible in the viewport and fires entry view events at the start and end of a qualified visibility cycle.

      The hook implements a two-phase event lifecycle per visibility cycle:

      1. Initial event after 1000 ms of accumulated visible time.
      2. Final event when visibility ends (only if the initial event was attempted).

      Parameters

      Returns UseViewportTrackingReturn

      An object with isVisible state and an onLayout callback for the tracked View.

      Error if called outside of an OptimizationProvider

      Uses useScrollContext if available, otherwise falls back to screen dimensions. A new visibility cycle (with a fresh viewId) starts each time the tracked entry transitions from invisible to visible. Time accumulation pauses when the app moves to the background. If trackView is blocked by consent, visibility timing starts only after Core allows the event type.

      function TrackedEntry({ entry }: { entry: Entry }) {
      const { onLayout, isVisible } = useViewportTracking({
      entry,
      })

      return (
      <View onLayout={onLayout}>
      <Text>{isVisible ? 'Visible' : 'Hidden'}</Text>
      </View>
      )
      }