TRAC-1395: fix - treat consent as granted when the store has cookie consent disabled - #3163
TRAC-1395: fix - treat consent as granted when the store has cookie consent disabled#3163parthshahp wants to merge 1 commit into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 8c58638 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Bundle Size ReportComparing against baseline from No bundle size changes detected. |
| currency, | ||
| }) => { | ||
| const format = getFormatter(); | ||
|
|
There was a problem hiding this comment.
This is the actual e2e test fix: we can just set the cookie explicitly for the test that we need
Unlighthouse Performance Comparison — VercelComparing PR preview deployment Unlighthouse scores vs production Unlighthouse scores. Summary ScoreAggregate score across all categories as reported by Unlighthouse.
Category Scores
Core Web Vitals
|
| return; | ||
| } | ||
|
|
||
| saveConsents('all'); |
There was a problem hiding this comment.
If cookie consent is disabled in the control panel, act like the user "accepts all".
There was a problem hiding this comment.
On second thought; this might not be such a good idea: https://c15t.com/docs/shared/react/hooks/use-consent-manager/setting-consent
From the documentation, it looks like saveConsents stores the value in localstorage. If a merchant decides to later enable cookie consent, this "fake consent" may still be stored in localstorage for the user.
(Edit: this is a rare case we needn't account for)
There was a problem hiding this comment.
Are we planning to do something about this?
There was a problem hiding this comment.
Nope, we probably don't really need to account for this. The consent cookie has expiration anyway
There was a problem hiding this comment.
This is what I came up with to resolve the issue of:
- Consent cookies are disabled.
- Shopper goes to site and consent is granted for
allscope. - Consent cookies are enabled.
- Shopper goes to site, but does not see banner because consent is granted for
allscope still.
I'm not sure if this is a real scenario that we should consider or not.
Another solution here would be to just call isCookieConsentEnabled on the set currency code server action. We can also cache this request, and we need to remember to call it for any server action that may also depend on consent cookies (like analytics).
There was a problem hiding this comment.
Thinking more about it I don't really like this localstorage solution, and we should just bite the bullet and make sure to check the consent cookie setting on relevant server actions, but I'll leave this up unchanged to get feedback first.
There was a problem hiding this comment.
I don't think that is a scenario we really need to worry about. Definitely an edge-case, because once a merchant enables it, the consent cookies will expire and will require consent after some time.
There was a problem hiding this comment.
We store cookie consent both in localstorage and in cookies. You'll need to dive into what c15t does, but we made sure we designed it that way to integrate better with Next.js.
Edit: technically, this method is not GDPR or CCPA compliant but we document this here: https://docs.bigcommerce.com/developer/docs/storefront/catalyst/features/cookie-consent
There was a problem hiding this comment.
Ok, so then should I just go with
- the
saveConsents('all');approach (if cookie consent is enabled) - make a request on server action specifically for set currency code?
There was a problem hiding this comment.
make a request on server action specifically for set currency code?
What is this for?
There was a problem hiding this comment.
The specific issue regarding currency code is this:
On the set currency code server action, we check the consent cookie.
Before this PR, we weren't saving a consent cookie even when the consent cookies were disabled, meaning that the currency code wasn't able to be changed.
Line 25 in 7848623
The current PR's solution to this is to just set the cookie with 'all' scopes when we see that consent cookies are disabled in the control panel.
The alternative I was suggesting to my above solution is: we make an extra request inside of the set currency code server action to check the consent cookies control panel setting on our own (create a new graphql request). If it is set to false, we don't care about the consent cookie.
The issue with the alternative is that it doesn't fix the analytics case (doesn't start visit + deletes visits).
| return; | ||
| } | ||
|
|
||
| saveConsents('all'); |
There was a problem hiding this comment.
Heads up that StartVisitOnConsent won't call startVisit for this path. c15t grants synchronously when enabled: false, so wasMeasurementGranted over there initializes to true — there's no false → true transition to observe. The analytics recovery for first-load is deferred to the second request once this cookie is readable. I think that's fine, mind adding a note to the comment above so it's not mysterious later?
There was a problem hiding this comment.
Sure, updated the comment!
There was a problem hiding this comment.
Well... no it actually shouldn't be a comment. We need to actually make sure it fires whenever cookie consent is turned off.
There was a problem hiding this comment.
Answered with this change: #3163 (comment)
| const hasStartedVisit = useRef<boolean | null>(null); | ||
|
|
||
| if (hasStartedVisit.current === null) { | ||
| hasStartedVisit.current = getConsentCookie()?.['c.measurement'] ?? false; |
There was a problem hiding this comment.
hasStartedVisit depends on if the cookie exists. We've removed the wasMeasurementGranted ref since that only starts the visit on a false -> true change.
|
LGTM, but should we run this by legal for this scenario? It might be overkill, but I would hate to cause a GDPR issue: Day 1: consent disabled -> shopper visits, cookie says "accepted everything" |
|
There's already a comment for this in the PR. TLDR this is an edge case and we have an expiration on the cookie anyway |
…sabled c15t grants every consent category when `cookieConsentEnabled` is off, but only inside its in-memory store — it never persists them. `hasConsentFor` reads the consent cookie, so it saw nothing and treated the shopper as having declined, silently dropping the selected currency and preventing the analytics visitor/visit cookies from ever being set. The consent manager now persists that automatic grant, so the consent cookie stays the single source of truth on both sides and `hasConsentFor` needs no store lookup — no added work in the proxy, and no added fetches anywhere, since c15t runs in offline mode and persisting is storage-only. Known tradeoff: this records a grant the shopper was never asked for. If a store later enables cookie consent, returning shoppers carrying that cookie get `showPopup: false` and won't see the banner. Marking the grant and resetting it on that transition was considered and rejected as more machinery than the case warrants. Also seeds an explicit functionality-consent cookie in the two alternate currency e2e tests so they don't race the client-side grant or depend on the test store's `cookieConsentEnabled` setting, and moves the consent cookie builder duplicated in analytics-session.spec.ts into a shared test helper.
What/Why?
When
cookieConsentEnabled(setting in the control panel) is off, c15t grants every consent category client-side but only in its in-memory store, so noc15t-consentcookie is ever written.hasConsentForread the cookie as the sole source of truth and so returned false for every category on those stores.hasConsentFornow falls back to the store's cookie consent setting when no consent cookie is present. An explicit consent cookie still takes precedence.Also seeds an explicit functionality-consent cookie in the two alternate currency e2e tests so they assert the consented path rather than depending on the test store's
cookieConsentEnabledsetting, and moves the consent cookie builder duplicated in analytics-session.spec.ts into a shared test helper.Testing
Tested using local tests as well as CI.
Before, you can see that I must refresh for the currency to take effect:
Screen.Recording.2026-08-05.at.5.06.47.PM.mov
After:
Screen.Recording.2026-08-05.at.3.47.55.PM.mov
Migration
No migration needed.