fix(autocapture): exposure snapshot - #1948
Open
jxiwang wants to merge 9 commits into
Open
Conversation
The plugin imported this module, but it was never committed, which broke CI builds. Co-authored-by: Cursor <cursoragent@cursor.com>
jxiwang
marked this pull request as ready for review
August 20, 2026 23:41
Collaborator
Author
|
bugbot run |
size-limit report 📦
|
Keep lastScroll in sync with the scroll tracker after SPA navigation so the next snapshot does not fire an empty Viewport Content Updated. Co-authored-by: Cursor <cursoragent@cursor.com>
jxiwang
enabled auto-merge (squash)
August 21, 2026 00:31
jxiwang
disabled auto-merge
August 21, 2026 00:31
Collaborator
Author
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit ac3e883. Configure here.
jxiwang
commented
Aug 21, 2026
| export const EXPOSURE_SNAPSHOT_QUIET_MS = 150; | ||
|
|
||
| /** Upper bound to wait for DOM hydration before taking the initial exposure snapshot. */ | ||
| export const EXPOSURE_SNAPSHOT_MAX_WAIT_MS = 4_000; |
Collaborator
Author
There was a problem hiding this comment.
Just chose a value for this, do not think it would reach this.
daniel-graham-amplitude
approved these changes
Aug 21, 2026
daniel-graham-amplitude
left a comment
Collaborator
There was a problem hiding this comment.
Lgtm, everything looks good. But I'd want other code reviews on this too.
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
Fixes
[Amplitude] Viewport Content Updatedunder-reporting on SPAs and duplicate/partial events caused by hydration and history API behavior.Problem
pushState/replaceStateduring hydration, which triggered spurious page-end flushes and a second snapshot cycle — producing two events where the second was a superset of the first.Solution
Viewport Content Updatedevent per page view.DocumentFragmentsupport — observe elements committed via React hydration fragments, not just directElementnodes.How the initial snapshot works
Note
Medium Risk
Changes browser autocapture event emission, IntersectionObserver scanning, and history API proxies. Incorrect URL comparison or snapshot timing could drop or duplicate analytics events, but this is not auth or data-security critical.
Overview
Fixes
[Amplitude] Viewport Content Updatedunder-reporting on hydrated SPAs and duplicate/partial events from same-URL history changes.After DOM mutations settle (or a 4s cap), an initial exposure snapshot rescans allowlisted elements and flushes one event per page view. Exposure observation now includes
DocumentFragmentnodes (React hydration) and can re-observe existing nodes.SPA page-end flushes only run when the normalized URL actually changes (query-only changes ignored; hash kept).
pushState/replaceStateflush the previous page before applying history, and already-sent element paths are not re-emitted within the same page view.Reviewed by Cursor Bugbot for commit ac3e883. Bugbot is set up for automated code reviews on this repo. Configure here.