Skip to content

fix(web): flush active view and hover heartbeats on page hide/unload#385

Merged
Felipe Mamud (fmamud) merged 2 commits into
mainfrom
NT-3718-flush-active-component-view
Jul 23, 2026
Merged

fix(web): flush active view and hover heartbeats on page hide/unload#385
Felipe Mamud (fmamud) merged 2 commits into
mainfrom
NT-3718-flush-active-component-view

Conversation

@fmamud

@fmamud Felipe Mamud (fmamud) commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Emit a final duration heartbeat for active component views and hovers on visibilitychange hidden, pagehide, and beforeunload, before the lifecycle Insights flush runs.
  • Add flushActive() to ElementViewObserver and ElementHoverObserver that reuses the existing heartbeat path (same viewId/hoverId, existing threshold/dedupe). No new event type, no isFinal field.
  • Expose flushActiveInteractions() on EntryInteractionRuntime and invoke it from the SDK's visibility callback before flushQueues, preserving queue ordering.

Fixes NT-3718.

Test plan

  • pnpm --filter @contentful/optimization-web test:unit — 280 tests pass, including new coverage: active view/hover flush past dwell, no emission before dwell, runtime dispatch to running detectors only, flushActiveInteractions running before sendBatchEvents on pagehide.
  • pnpm --filter @contentful/optimization-web typecheck
  • pnpm lint
  • pnpm format:check
  • Shared Playwright E2E — new emits a final hover heartbeat when the page becomes hidden while still hovered in lib e2e-web/e2e/tracking.spec.ts — hovers past dwell, flips document.visibilityState to hidden and dispatches visibilitychange, asserts data-hover-duration-ms advances beyond the pre-hidden snapshot. Verified locally against react-web-sdk on chromium; runs across all supported CSR implementations via CI matrix.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

@fmamud
Felipe Mamud (fmamud) merged commit 99e35bb into main Jul 23, 2026
37 checks passed
@fmamud
Felipe Mamud (fmamud) deleted the NT-3718-flush-active-component-view branch July 23, 2026 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants