Fix Cookie Persistence for VTEX Domains and Cross-Subdomain Tracking #37
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.
Problem
Session tracking was failing for
orderPlacedevents in VTEX domains due to several cookie configuration issues:www.store.com), not shared across subdomains (e.g.,secure.store.com,checkout.store.com)SameSite=Laxbehavior, which causes cookies to be dropped during:Pageinstance inCookies.set()caused infinite loop becausePageconstructor createsUTMinstance, which callsCookies.set()Changes
Cookie Attributes (
src/models/cookies.js)Secureflag for HTTPS connectionsdomainattribute with root domain calculation (e.g.,.example.com,.storename.com.br)SameSite=Laxto handle payment gateway redirectsmax-age=315360000(10 years) for persistent trackingRoot Domain Logic (
src/models/page.js)Page.getRootDomain(hostname)that:.com,.net) → returns last 2 parts.com.br,.co.uk) → returns last 3 parts.vtexcommercestable.com.br)nullfor invalid/missing URLspage.domaingetter to use static methodpage.urlgetter to preserve empty strings instead of falling back towindow.location.hrefTests
Page.getRootDomain()covering:Impact
Before:
After:
VTEX-Specific Benefits
orderPlacedevents) persists through checkout flowvtexcommercestable.com.brdomainsBreaking Changes
None. Changes are backward-compatible and only enhance cookie behavior.
Note
Adds Secure, SameSite=Lax, max-age, and domain to cookies using a new Page.getRootDomain utility; updates URL handling and adds comprehensive tests.
Cookies.setnow setsSecure(HTTPS),SameSite=Lax,max-age=315360000, anddomain(viaPage.getRootDomain); falls back when domain unavailable.getRootDomain(hostname)to resolve root domains (regular, multi-part TLDs, VTEX/myvtex/myshopify/wixsite, localhost/single-part).domaingetter usinggetRootDomain.urlgetter preserves explicit empty/undefined instead of always falling back towindow.location.href.Page.getRootDomainandPage.domainacross TLD and platform cases.dist/hellotext.js,lib/models/*) updated to reflect changes.Written by Cursor Bugbot for commit 14c405c. This will update automatically on new commits. Configure here.