feat(pixel): capture-phase scroll tracking for SPAs and internal scroll containers (SDK-276)#2871
Merged
Merged
Conversation
…ll containers (SDK-276)
Replaces the window-level scroll listener with a single capture-phase
listener on document, so scroll_depth milestones fire on SPA pages where
document.documentElement never scrolls but an internal overflow container
does. Containers smaller than 50% of the viewport are ignored to avoid
noise from dropdowns and tooltips. Milestones reset on each pixel.page()
call so SPA route transitions start fresh. Also fixes a pre-existing bug
where autocapture: { scroll: false } was silently ignored.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
View your CI Pipeline Execution ↗ for commit 69cad58
☁️ Nx Cloud last updated this comment at |
✅ Pixel Bundle Size — @imtbl/pixel
Budget: 10.00 KB gzipped (warn at 8.00 KB) |
- Trim scroll_depth README cell; iframe limitation belongs in docs.immutable.com (separate PR) and isn't scroll-specific anyway - Drop unnecessary (el as HTMLElement) cast — Element.scrollTop is in the DOM spec - Tighten setupAutocapture docstring Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…per frame Addresses two Cursor bugbot findings: 1. Stale rAF after reset() (medium): if a scroll event scheduled a rAF just before pixel.page() called resetScrollDepth(), the rAF would read the (still-stale) scrollTop of a reused container and fire milestones against the freshly-cleared set — misattributing scroll depth to the new page view. reset() now cancels any pending rAF. 2. Single pendingEl drops concurrent container scrolls (low): if two large containers fired scroll events in the same frame, only the later target was checked. Replaced pendingEl with a Set so every container that scrolled within the frame is processed on rAF. Adds two regression tests. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit ecaa8f2. Configure here.
… tests Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
nattb8
approved these changes
May 11, 2026
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
windowscroll listener withdocument.addEventListener('scroll', ..., { capture: true })soscroll_depthmilestones fire on SPA pages wheredocument.documentElementnever scrolls but an internaloverflow: autocontainer does (the pattern used on godsunchained.com and most Angular/Vue/React apps)scroll_depthmilestones now reset on eachpixel.page()call, so SPA route transitions start with a fresh depth counter — without this, milestones would silently do nothing after the first route in a sessionautocapture: { scroll: false }was silently ignored (thescrolloption was not being passed through tosetupAutocapture)setupScrollTrackingreturns{ teardown, reset }andsetupAutocapturereturns{ teardown, resetScroll }to support the reset path without tearing down and re-attaching all listenerspage()could schedule a rAF that fires milestones against the freshly-cleared set;reset()now cancels any pending rAFpendingEl: Element | nullwithpending: Set<Element>so all containers in a frame are processedscroll_depthrow updated to document SPA support and reset-on-page behaviourTest plan
pnpm testinpackages/audience/pixel)document(correct for capture-phase listener)resetScroll()allows milestones to re-fire after a simulated SPA route changepixel.page()callsresetScroll(regression guard for milestone reset on route changes)autocapture: { scroll: false }is forwarded tosetupAutocapture(regression guard for the scroll-option bug)Closes SDK-276
🤖 Generated with Claude Code
Note
Medium Risk
Changes scroll auto-capture behavior by moving to capture-phase
documentlisteners, adding container filtering, and resetting milestones onpage(), which could affect analytics event volume/semantics in production. Includes broad test updates/additions to cover new scroll targets and reset/rAF edge cases.Overview
Scroll auto-capture is reworked so
scroll_depthmilestones fire for both document scrolling and SPA-style internaloverflowcontainers by listening ondocumentin capture phase and processing multiple scrolled elements per animation frame.Milestones are now reset per page view via a new
resetScrollhook thatPixel.page()calls (including cancelling pending rAF work), and small scroll containers (≤ 50% viewport height) are ignored to reduce noise;autocapture.scrollis also correctly forwarded and the public API now returns{ teardown, resetScroll }fromsetupAutocapture.Docs and tests are updated/expanded accordingly, and
@imtbl/pixelversion is bumped to0.2.0.Reviewed by Cursor Bugbot for commit de0b6d3. Bugbot is set up for automated code reviews on this repo. Configure here.