Analytics: consentMode 'basic' keeps Google tags out until consent

Opt-in; the default stays 'advanced' (tag loads with denied signals).
shouldLoadGoogle holds the rule so it is testable without a DOM.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-10-22 17:05:14 +02:00
co-authored by Claude Opus 5.5
parent 0bfc509102
commit 9a72ebfaff
3 changed files with 66 additions and 6 deletions
+19
View File
@@ -0,0 +1,19 @@
import { describe, expect, test } from 'vitest'
import { shouldLoadGoogle } from '../src/modules/analytics/Analytics.js'
const none = { analytics: false, marketing: false }
describe("Google tag and consent", () => {
test("'basic': no Google request before an analytics or marketing grant", () => {
expect(shouldLoadGoogle({ consentMode: 'basic', ready: true, state: none })).toBe(false)
expect(shouldLoadGoogle({ consentMode: 'basic', ready: true, state: { ...none, analytics: true } })).toBe(true)
expect(shouldLoadGoogle({ consentMode: 'basic', ready: true, state: { ...none, marketing: true } })).toBe(true)
})
test("'advanced' (default) loads with denied signals; `defer` still holds both back", () => {
expect(shouldLoadGoogle({ consentMode: 'advanced', ready: true, state: none })).toBe(true)
expect(shouldLoadGoogle({ consentMode: 'advanced', ready: false, state: none })).toBe(false)
expect(shouldLoadGoogle({ consentMode: 'basic', ready: false, state: { analytics: true } })).toBe(false)
})
})