Skip to content

fix(sdk): migrate host-scoped visitor cookie when domain is set#358

Draft
nicklasl wants to merge 3 commits into
mainfrom
nicklasl/visitor-cookie-migration
Draft

fix(sdk): migrate host-scoped visitor cookie when domain is set#358
nicklasl wants to merge 3 commits into
mainfrom
nicklasl/visitor-cookie-migration

Conversation

@nicklasl

Copy link
Copy Markdown
Member

Summary

  • Uses the CookieStore API to properly migrate host-scoped cnfdVisitorId cookies when domain is configured
  • Detects existing domain cookies and preserves them instead of overwriting, preventing the visitor ID flip-flop across subdomains
  • Falls back to simple domain cookie set when CookieStore is unavailable

Context

Follow-up to #356. When a user has host-scoped cookies on multiple subdomains (e.g. visitorId=x on a.acme.com and visitorId=y on b.acme.com), the legacy document.cookie API can't distinguish host vs domain cookies — whichever subdomain is visited last overwrites the domain cookie. CookieStore's getAll() returns domain info, letting us preserve the first-set domain value.

Test plan

  • yarn build passes
  • yarn test — 168 tests pass (8 new for visitorId)
  • yarn format:check clean
  • yarn bundle — API report unchanged
  • Manual: verify on HTTPS site with multiple subdomains

🤖 Generated with Claude Code

nicklasl and others added 3 commits June 15, 2026 08:34
Uses CookieStore API to detect and preserve existing domain cookies
during subdomain migration, preventing visitor ID flip-flop.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Host-only cookies have domain=null in the CookieStore API.
Delete them by name only, not by domain.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant