feat(session-replay): enhance targeting evaluation with page URL#1571
feat(session-replay): enhance targeting evaluation with page URL#1571
Conversation
- Updated `evaluateTargetingAndCapture` to include page URL from `getGlobalScope`. - Modified related types and functions to accommodate the new `page` parameter. - Added tests to verify correct behavior when page URL is provided or absent.
|
bugbot run |
| /** Page data passed into targeting so the evaluator can use the current URL (or other page data). */ | ||
| export interface TargetingPage { | ||
| url?: string; | ||
| } |
There was a problem hiding this comment.
New TargetingPage type not exported from package
Low Severity
The new TargetingPage interface is defined with export in targeting.ts but is not re-exported from the package's index.ts. The index file exports TargetingFlag and TargetingParameters but omits TargetingPage, making it inaccessible to consumers who may want to type variables with the page structure directly. Other sibling types like TargetingFlag are properly re-exported.
lewgordon-amplitude
left a comment
There was a problem hiding this comment.
Chatted about this in person. We want to hook this into url tracking so that we can capture when the url changes not just on events or init.
URL tracking (plugin / rrweb)
URL-based targeting re-evaluation (URL eval)
|
packages/session-replay-browser/src/plugins/url-tracking-plugin.ts
Outdated
Show resolved
Hide resolved
packages/session-replay-browser/src/plugins/url-tracking-plugin.ts
Outdated
Show resolved
Hide resolved
|
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.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.


feat(session-replay): URL-based targeting re-evaluation and 100% test coverage
URL-based targeting
subscribeToUrlChangesfrom the URL tracking plugin; on URL change callevaluateTargetingAndCapture(..., false, true)and skip IDB cache inevaluateTargetingAndStorewhenurlChangeis true.session-replay-browser
setupUrlChangeListenerForTargeting()subscribes to URL changes and cleans up on shutdown.globalScope.location?.hrefin URL plugin (already guarded by early return).console.logfrom URL plugin.Tests
evaluateTargetingAndCapturewith empty/undefined page.Coverage
Note
Medium Risk
Changes when/why session replay starts recording by adding URL-driven targeting re-evaluations and new shared history/listener patching; regressions could affect capture rates or introduce subtle listener/async ordering issues.
Overview
Session Replay targeting now receives
page.urlcontext and can re-evaluate on SPA navigation:SessionReplay.evaluateTargetingAndCaptureacceptspage, passes it through to@amplitude/targeting, andSessionReplaysubscribes to URL changes (with cleanup on re-init/shutdown and stale-evaluation protection) to queue forced re-evaluations.The URL tracking plugin is refactored around a new shared
subscribeToUrlChangeshelper (history patching + popstate/hashchange or polling) to avoid double-patching and to share subscriptions across consumers, and targeting’s IDB cache is bypassed on URL-change re-evaluations. Tests are expanded substantially acrossplugin-session-replay-browser,session-replay-browser,url-tracking-plugin, andtargeting(includingtsconfigtest inclusion) to cover the new behaviors and race conditions.Written by Cursor Bugbot for commit 0a9bddb. This will update automatically on new commits. Configure here.