feat(experiment-tag): share RTBT session across subdomains with rolling timeout#336
Open
tyiuhc wants to merge 1 commit into
Open
feat(experiment-tag): share RTBT session across subdomains with rolling timeout#336tyiuhc wants to merge 1 commit into
tyiuhc wants to merge 1 commit into
Conversation
…ng timeout Rework the behavioral-targeting SessionManager to mirror Amplitude Analytics' session model so RTBT current_session conditions work across subdomains. - Persist session id + lastEventTime in a root-domain cookie (resolved via a synchronous getTopLevelDomain probe) instead of per-tab sessionStorage, so the session is shared across subdomains and tabs. - Rotate the session on a rolling inactivity timeout (default 30m, configurable via WebExperimentConfig.rtbtSessionTimeout). - Treat any observed Amplitude event as session activity by calling recordActivity() at the top of trackEvent, upstream of the persistedEvents allowlist filter. - Degrade gracefully to an in-memory per-page session when cookie I/O is blocked (private browsing, ITP), detected via cookie write-back. Refs WEB-132. Co-authored-by: Cursor <cursoragent@cursor.com>
3 tasks
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
Reworks the behavioral-targeting (RTBT)
SessionManagerso thatcurrent_sessionconditions work across subdomains, mirroring Amplitude Analytics' session model.Previously the RTBT session lived in
sessionStorage, which is scoped per-tab and per-origin. That fragmented sessions across subdomains (and even tabs), socurrent_sessiontargeting could never match events fired on a different subdomain.Changes
lastEventTimeare persisted in a cookie scoped to the registrable domain (resolved with a new synchronousgetTopLevelDomainSyncprobe inutil/cookie.ts), so the session is shared across subdomains and tabs.WebExperimentConfig.rtbtSessionTimeout.recordActivity()is called at the top ofBehavioralTargetingManager.trackEvent, upstream of thepersistedEventsallowlist filter, so any observed event keeps the session alive (not just RTBT-relevant events). Reads usegetCurrentSessionId()which does not extend the session.getOrCreateSessionId()is kept as a backwards-compatible alias.Related PRs
Part of the cross-subdomain behavioral-targeting effort: #333 (RTBT relay protocol + RelayClient), #334 (dual-write events to relay), and #335 (wire relay iframe). The root-domain cookie reuses the same registrable-domain approach as #332 (cross-subdomain
web_exp_id_v2identity). This change is independent of the relay PRs (based onmain) but pairs with them so a sharedcurrent_sessionmatches across subdomains.Test plan
SessionManagerunit tests: cookie persistence, cross-instance sharing, rolling timeout (extend vs rotate), configurable timeout, start-time, clear, and in-memory fallback.experiment-tagsuite green (174 tests), eslint + prettier clean.current_sessionrule, fire events ona.example.com, confirm match onb.example.com).Made with Cursor