Consent compliance: Global Privacy Control honoured, equal choice by default, withdrawal that stops running tools, consent log on by default
- GPC (gpc.ts): read in the browser before the first paint (consentBannerScript) and in the consent store; pages stay static. 'honour' (default): no banner, analytics and marketing off, no request to Google or a pixel; an explicit choice on the site wins; a grant made without the signal gives way when it appears. 'ask' and false as opt-outs. - equalChoice defaults to true; a development warning when the banner has no 'reject'. - Withdrawal: Meta / TikTok / Clarity told at once, listed localStorage / sessionStorage keys removed. - Clarity gets consentv2 when it loads; ads_data_redaction with the Consent Mode default. - consentLog on by default (consentLog: false turns it off); SiteProviders posts to it by itself; a missing SQL table answers 503 with one log line. - Default banner text: one sentence on changing the choice and browser settings; the GPC line (PL / EN). - Doctor: consent-log-migration, consent-banner rules. - Stats: Sec-GPC over a choice made without it keeps the visitor id out. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
41771fd51a
commit
99036eb70c
@@ -30,11 +30,11 @@ const REJECT: ConsentState = { analytics: false, functional: false, marketing: f
|
||||
const texts = { ...CONSENT_FALLBACK, version: 3 }
|
||||
const stored = (state: ConsentState, version = 3) => serializeConsent(state, version, 'id-1')
|
||||
|
||||
type TreeOptions = { analytics?: object; banner?: object; cookieValue?: null | string; logEndpoint?: string; nonce?: string; texts?: object }
|
||||
type TreeOptions = { analytics?: object; banner?: object; cookieValue?: null | string; gpc?: 'ask' | 'honour' | false; logEndpoint?: string; nonce?: string; texts?: object }
|
||||
const tree = (o: TreeOptions = {}) =>
|
||||
h(
|
||||
ConsentProvider,
|
||||
{ cookieValue: o.cookieValue, logEndpoint: o.logEndpoint, nonce: o.nonce, texts: o.texts ?? texts },
|
||||
{ cookieValue: o.cookieValue, gpc: o.gpc, logEndpoint: o.logEndpoint, nonce: o.nonce, texts: o.texts ?? texts },
|
||||
h('main', null, 'page'),
|
||||
h(CookieBanner, o.banner ?? {}),
|
||||
h(CookieButton),
|
||||
@@ -151,12 +151,18 @@ describe('server render', () => {
|
||||
['another policy version', stored(ACCEPT, 2)],
|
||||
['malformed', '%7Bnot-json'],
|
||||
['foreign content', encodeURIComponent('yes')],
|
||||
])('server-read cookie, %s: the banner is in the HTML, shown, without a script', (_label, cookieValue) => {
|
||||
])('server-read cookie, %s: the banner is in the HTML; Global Privacy Control is the browser\'s, so its script decides (gpc={false}: shown, no script)', (_label, cookieValue) => {
|
||||
// the server cannot know Global Privacy Control (a browser signal): with 'honour' the script decides that part
|
||||
const html = renderToString(tree({ cookieValue }))
|
||||
expect(html).toContain('data-ipal="banner"')
|
||||
expect(html).not.toMatch(/data-ipal="banner"[^>]*hidden/)
|
||||
expect(html).not.toContain('<script')
|
||||
expect(html).toMatch(/<div[^>]*data-ipal="banner"[^>]*hidden=""/)
|
||||
expect(html).toContain('data-ipal="banner-script"')
|
||||
expect(html).toContain('navigator.globalPrivacyControl===true')
|
||||
expect(html).not.toContain('data-ipal="cookie-button"')
|
||||
// the signal ignored: as before GPC, shown with no script
|
||||
const off = renderToString(tree({ cookieValue, gpc: false }))
|
||||
expect(off).toContain('data-ipal="banner"')
|
||||
expect(off).not.toMatch(/data-ipal="banner"[^>]*hidden/)
|
||||
expect(off).not.toContain('<script')
|
||||
})
|
||||
|
||||
test('firstPaint={false}: nothing in the HTML, as before 1.17.0', () => {
|
||||
@@ -177,7 +183,8 @@ describe('server render', () => {
|
||||
const decided = site({ consentCookie: stored(REJECT) })
|
||||
expect(decided).not.toContain('data-ipal="banner"')
|
||||
expect(decided).toContain('data-ipal="cookie-button"')
|
||||
expect(site({ consentCookie: null })).not.toMatch(/data-ipal="banner"[^>]*hidden/)
|
||||
expect(site({ consentCookie: null })).toContain('data-ipal="banner-script"')
|
||||
expect(site({ consentCookie: null, gpc: false })).not.toMatch(/data-ipal="banner"[^>]*hidden/)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -383,8 +390,9 @@ describe('decisions, reopening and withdrawal work as before', () => {
|
||||
// the consent log: one POST per decision, the same body as before
|
||||
expect(fetchMock).toHaveBeenCalledTimes(2)
|
||||
const calls = fetchMock.mock.calls.map(([url, init]) => ({ ...(init as object), body: JSON.parse(init.body) as unknown, url }))
|
||||
expect(calls[0]).toEqual({ body: { id: first.id, state: REJECT, version: 3 }, headers: { 'content-type': 'application/json' }, keepalive: true, method: 'POST', url: '/api/ipal/consent' })
|
||||
expect(calls[1].body).toEqual({ id: first.id, state: ACCEPT, version: 3 })
|
||||
// 1.17.0: `gpc` (the browser's Global Privacy Control at the time) joins the body; the record's shape is unchanged
|
||||
expect(calls[0]).toEqual({ body: { gpc: false, id: first.id, state: REJECT, version: 3 }, headers: { 'content-type': 'application/json' }, keepalive: true, method: 'POST', url: '/api/ipal/consent' })
|
||||
expect(calls[1].body).toEqual({ gpc: false, id: first.id, state: ACCEPT, version: 3 })
|
||||
expect(errors).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
@@ -445,7 +453,7 @@ describe('tags: nothing earlier than before', () => {
|
||||
test('no decision: showing the banner at first paint loads no tag; Consent Mode default is all denied', () => {
|
||||
load({ analytics: pixels })
|
||||
expect(injected).toEqual([])
|
||||
expect(layer()).toEqual([['consent', 'default', expect.objectContaining({ ad_storage: 'denied', analytics_storage: 'denied', wait_for_update: 500 })]])
|
||||
expect(layer()).toEqual([['consent', 'default', expect.objectContaining({ ad_storage: 'denied', analytics_storage: 'denied', wait_for_update: 500 })], ['set', 'ads_data_redaction', true]])
|
||||
expect((window as { fbq?: unknown }).fbq).toBeUndefined()
|
||||
})
|
||||
|
||||
@@ -460,8 +468,9 @@ describe('tags: nothing earlier than before', () => {
|
||||
click('accept')
|
||||
const entries = layer()
|
||||
expect((entries[0] as unknown[]).slice(0, 2)).toEqual(['consent', 'default'])
|
||||
expect((entries[1] as unknown[]).slice(0, 2)).toEqual(['consent', 'update'])
|
||||
expect(entries[2]).toMatchObject({ event: 'gtm.js' })
|
||||
expect(entries[1]).toEqual(['set', 'ads_data_redaction', true])
|
||||
expect((entries[2] as unknown[]).slice(0, 2)).toEqual(['consent', 'update'])
|
||||
expect(entries[3]).toMatchObject({ event: 'gtm.js' })
|
||||
expect(injected).toEqual(expect.arrayContaining(['https://www.googletagmanager.com/gtm.js?id=GTM-TEST', 'https://connect.facebook.net/en_US/fbevents.js']))
|
||||
})
|
||||
|
||||
@@ -478,7 +487,8 @@ describe('tags: nothing earlier than before', () => {
|
||||
load({ analytics: { gtmContainerId: 'GTM-TEST', metaPixelId: '123' } })
|
||||
const entries = layer()
|
||||
expect(entries[0]).toEqual(['consent', 'default', expect.objectContaining({ analytics_storage: 'denied' })])
|
||||
expect(entries[1]).toMatchObject({ event: 'gtm.js' })
|
||||
expect(entries[1]).toEqual(['set', 'ads_data_redaction', true])
|
||||
expect(entries[2]).toMatchObject({ event: 'gtm.js' })
|
||||
expect(injected).toEqual(['https://www.googletagmanager.com/gtm.js?id=GTM-TEST']) // no Meta Pixel without consent
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user