-
Notifications
You must be signed in to change notification settings - Fork 199
Add option to skip recording GPC consent #1784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // Copyright (c) 2026 Probo Inc <hello@probo.com>. | ||
| // | ||
| // Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| // of this software and associated documentation files (the "Software"), to deal | ||
| // in the Software without restriction, including without limitation the rights | ||
| // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| // copies of the Software, and to permit persons to whom the Software is | ||
| // furnished to do so, subject to the following conditions: | ||
| // | ||
| // The above copyright notice and this permission notice shall be included in | ||
| // all copies or substantial portions of the Software. | ||
| // | ||
| // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| // SOFTWARE. | ||
|
|
||
| import { afterEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| import { resolveBooleanAttribute } from "./attributes"; | ||
|
|
||
| describe("resolveBooleanAttribute", () => { | ||
| afterEach(() => { | ||
| vi.restoreAllMocks(); | ||
| }); | ||
|
|
||
| it("defaults to true when the attribute is absent", () => { | ||
| expect(resolveBooleanAttribute(null, "gpc-record")).toBe(true); | ||
| }); | ||
|
|
||
| it("parses \"true\" and \"false\"", () => { | ||
| expect(resolveBooleanAttribute("true", "gpc-record")).toBe(true); | ||
| expect(resolveBooleanAttribute("false", "gpc-record")).toBe(false); | ||
| }); | ||
|
|
||
| it("normalizes case and whitespace", () => { | ||
| expect(resolveBooleanAttribute("FALSE", "gpc-record")).toBe(false); | ||
| expect(resolveBooleanAttribute(" false ", "gpc-record")).toBe(false); | ||
| expect(resolveBooleanAttribute("True", "gpc-record")).toBe(true); | ||
| }); | ||
|
|
||
| it("warns with the attribute name and falls back to true", () => { | ||
| const warn = vi.spyOn(console, "warn").mockImplementation(() => {}); | ||
| expect(resolveBooleanAttribute("off", "gpc-record")).toBe(true); | ||
| expect(warn).toHaveBeenCalledTimes(1); | ||
| expect(warn.mock.calls[0][0]).toContain("gpc-record"); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // Copyright (c) 2026 Probo Inc <hello@probo.com>. | ||
| // | ||
| // Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| // of this software and associated documentation files (the "Software"), to deal | ||
| // in the Software without restriction, including without limitation the rights | ||
| // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| // copies of the Software, and to permit persons to whom the Software is | ||
| // furnished to do so, subject to the following conditions: | ||
| // | ||
| // The above copyright notice and this permission notice shall be included in | ||
| // all copies or substantial portions of the Software. | ||
| // | ||
| // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| // SOFTWARE. | ||
|
|
||
| export function resolveBooleanAttribute( | ||
| value: string | null, | ||
| attribute: string, | ||
| ): boolean { | ||
| if (value == null) { | ||
| return true; | ||
| } | ||
|
|
||
| const normalized = value.trim().toLowerCase(); | ||
| if (normalized === "true") { | ||
| return true; | ||
| } | ||
| if (normalized === "false") { | ||
| return false; | ||
| } | ||
|
|
||
| console.warn( | ||
| `[probo] invalid ${attribute} value "${value}": expected "true" or "false", falling back to enabled`, | ||
| ); | ||
| return true; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,6 +79,7 @@ export class CookieBannerClient { | |
| private readonly lang: string; | ||
|
|
||
| private readonly integrations: ConsentIntegration[]; | ||
| private readonly gpcRecord: boolean; | ||
|
|
||
| private bannerConfig: BannerConfig | null = null; | ||
| private consent: VisitorConsent | null = null; | ||
|
|
@@ -97,6 +98,7 @@ export class CookieBannerClient { | |
| this.visitorId = getVisitorId(config.bannerId); | ||
| this.lang = detectLanguage(config.lang); | ||
| this.integrations = createDefaultIntegrations(config.integrations); | ||
| this.gpcRecord = config.gpcRecord !== false; | ||
| } | ||
|
|
||
| get loaded(): boolean { | ||
|
|
@@ -194,7 +196,13 @@ export class CookieBannerClient { | |
| gpcData[cat.slug] = cat.kind === "NECESSARY"; | ||
| } | ||
| getConsent()._setReady(gpcData, false); | ||
| this.gpc(); | ||
| // GPC is honoured either way; gpcRecord only controls whether the | ||
| // decision is persisted and sent. | ||
| if (this.gpcRecord) { | ||
| this.gpc(); | ||
| } else { | ||
| this.activate(gpcData); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: When Prompt for AI agents
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: With Prompt for AI agents |
||
| } | ||
| this._gpcApplied = true; | ||
| } else if (!this.consent) { | ||
| const defaults = this.buildDefaultConsentData(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3: The new tests only cover
resolveBooleanAttributeparsing, not the actual behavior this PR introduces. There is no client-level test asserting thatgpcRecord: falseskips the consent cookie, visitor-id creation, and the{bannerId}/consentsPOST, or that the defaulttruestill records. Add a client test for the GPC branch so the privacy-relevant toggle can't silently regress.Prompt for AI agents