Repository navigation
Conversation
…Analytics session After a long break, the Analytics SDK restores the old session id and only starts a new session when its next event fires. Session Replay recorded under that expired session in the gap. Its min duration clock had started long ago, so the gate passed at once and a near-empty replay was uploaded (0s replays). The plugin now passes the Analytics session timeout and a live lastEventTime getter to Session Replay (analyticsSessionExpiry). With it: - On init, SR does not start recording under an expired session. It starts when setSessionId brings the new session. - If the session expires while recording (same tab, no reload), the min duration clock restarts once, so the leftover is dropped when Analytics starts a new session. Recording continues, so content is kept if no Analytics event comes. Standalone SDK users and plugin users with customSessionId are unchanged. SRC-501 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
size-limit report 📦
|
Session Replay Browser E2E ResultsDetails
Flaky testschromium › e2e/idb.spec.ts › IDB transaction abort handling › getSequencesToSend cursor abort: AbortError logged at debug not warn |
This branch has not been deployed
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 SRC-501: 0s replays that show up even with Minimum Session Duration set (reported by Almosafer).
Cause. After a long break, the Analytics SDK restores the old session id on page load. It only starts a new session when its next event fires. Session Replay recorded under that expired session in the gap. The session's min duration clock started hours earlier, so the gate passed at once and a ~60ms snapshot got uploaded as a 0s replay. The same happens without a reload, when a tab is left open (or frozen by a mobile browser) past the session timeout.
Fix. The plugin passes the Analytics session timeout and a live
lastEventTimegetter to Session Replay (analyticsSessionExpiry, marked@internal). A session counts as expired whennow - lastEventTime > sessionTimeout, the same rule Analytics uses (isNewSession).initialize()does not start recording under an expired session. Recording starts whensetSessionIdbrings the new session. The session id is still passed toinit, so interaction (heatmap) capture is set up as before.Unchanged: standalone
@amplitude/session-replay-browserusers (they manage their own session ids, and SR can't know their session rules), plugin users withcustomSessionId, and sessions without a min duration threshold.Known limits
Testing
Checklist
🤖 Generated with Claude Code
Note
Medium Risk
Changes session start/recording and min-duration upload gating for plugin-integrated replay; behavior shifts around page load after long idle periods and same-tab expiry, though scoped to plugin users without customSessionId.
Overview
Fixes 0-second Session Replay uploads when Analytics has already expired a session but Session Replay still records under the restored session id (page reload or idle tab).
The plugin now passes an internal
analyticsSessionExpiryhook (sessionTimeout+ livelastEventTime) into Session Replay, unlesscustomSessionIdis used. Session Replay uses the same rule as Analytics (now - lastEventTime > sessionTimeout) to:setSessionIdwith a new session.Standalone SDK users are unchanged (no expiry hook). Unit tests cover wiring and expiry/min-duration behavior.
Reviewed by Cursor Bugbot for commit f1587d0. Bugbot is set up for automated code reviews on this repo. Configure here.