fix(autocapture): fire exposure at 50% visibility instead of 100% - #1972
Open
jxiwang wants to merge 2 commits into
Open
fix(autocapture): fire exposure at 50% visibility instead of 100%#1972jxiwang wants to merge 2 commits into
jxiwang wants to merge 2 commits into
Conversation
size-limit report 📦
|
jxiwang
marked this pull request as ready for review
September 4, 2026 15:44
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Exposure — the signal behind
[Amplitude] Viewport Content Updated— now treats an element as seen once half of it is inside the viewport, instead of requiring the whole element.createExposureObservableobserved withthreshold: 1.0; it now uses a new shared constantEXPOSURE_INTERSECTION_THRESHOLD(0.5).trackExposurestarted its exposure timer onentry.isIntersectingalone. It now comparesentry.intersectionRatioagainst that same constant, so the 50% rule lives in the code rather than only in the observer options. The spec definesisIntersectingas any overlap with the root, independent of the configured threshold; Chromium and Firefox both tie it to the threshold instead, but a spec-literal implementation (or a polyfill) would expose an element from a single visible pixel. The explicit ratio check makes the behavior the same either way.!isIntersecting && intersectionRatio < 1.0) collapses to a plainelse: anything below the threshold cancels a pending timer, whether the element left the viewport or just scrolled partway out.With
threshold: 0.5the observer still delivers a callback on viewport entry/exit and on each crossing of 50%, which is all the ratio-based gate needs — no extra thresholds required. Ratios are compared with a small tolerance so sub-pixel rounding cannot strand an element parked exactly at the boundary.Verification
New unit tests cover exposure at exactly 50%, no exposure at 30%, and cancellation when an element scrolls from 60% down to 40% while still touching the viewport. Package suite: 517 tests passing at 100% coverage.
I also probed a real
IntersectionObserverin Chromium and Firefox (both reportintersectionRatio0.505 /isIntersecting: truewhen half visible, and no threshold-met callback at 40%), then ran the builtanalytics-browserUMD bundle end to end in Chromium against a button positioned below the fold:mainbutton#targetexposedNote for reviewers
An element more than twice the viewport size can never reach 50% of its own area, so it is never exposed. That matches the current behavior — it could never reach 100% either — but it is worth confirming that no customer relies on exposure for full-page containers via
[data-amp-default-track]or a customcssSelectorAllowlist. I prototyped a fallback that exposed such elements once their visible part filled half the viewport, then dropped it: because both engines suppressisIntersectingbelow the threshold, it would have fired only on the rare rescan that happened to coincide with the element filling the viewport, making behavior inconsistent across browsers and hard to reason about.Checklist
Viewport Content Updatedwill report more elements than before.