diff --git a/packages/cookie-banner/src/client.ts b/packages/cookie-banner/src/client.ts index f44d79a0a..91b4fb4d3 100644 --- a/packages/cookie-banner/src/client.ts +++ b/packages/cookie-banner/src/client.ts @@ -43,6 +43,22 @@ export interface Category { posthog_consent: boolean; } +export type Regulation = + | "GDPR" + | "UK_GDPR" + | "FADP" + | "CCPA" + | "PIPEDA" + | "LGPD" + | "LFPDPPP" + | "POPIA" + | "PDPA" + | "PIPL" + | "PIPA" + | "APPI" + | "DPDP" + | "PDPL"; + export interface BannerConfig { banner_id: string; version: number; @@ -52,6 +68,7 @@ export interface BannerConfig { cookie_policy_url: string; consent_expiry_days: number; consent_mode: "OPT_IN" | "OPT_OUT"; + regulation: Regulation | null; show_branding: boolean; categories: Category[]; texts: BannerTexts; @@ -210,6 +227,10 @@ export class CookieBannerClient { return this._gpcApplied; } + get regulation(): Regulation | null { + return this.bannerConfig?.regulation ?? null; + } + gpc(): void { const cfg = this.config; diff --git a/packages/cookie-banner/src/components/cookie-banner-root.ts b/packages/cookie-banner/src/components/cookie-banner-root.ts index 969bca862..409abe29a 100644 --- a/packages/cookie-banner/src/components/cookie-banner-root.ts +++ b/packages/cookie-banner/src/components/cookie-banner-root.ts @@ -156,7 +156,7 @@ export class ProboCookieBannerRoot extends ProboElement implements ProboRootElem new CustomEvent("probo-ready", { bubbles: true, composed: true, - detail: { config: this._config, gpcApplied: this.gpcApplied }, + detail: { config: this._config, gpcApplied: this.gpcApplied, regulation: this._client.regulation }, }), ); diff --git a/pkg/cookiebanner/service.go b/pkg/cookiebanner/service.go index 6aff5baef..8c56baef9 100644 --- a/pkg/cookiebanner/service.go +++ b/pkg/cookiebanner/service.go @@ -103,6 +103,7 @@ type ( ConsentData json.RawMessage Action coredata.CookieConsentAction SdkVersion string + Regulation Regulation } DetectedCookie struct { @@ -1855,6 +1856,7 @@ func (s *Service) RecordConsent( ConsentData: req.ConsentData, Action: req.Action, SdkVersion: req.SdkVersion, + Regulation: string(req.Regulation), CreatedAt: time.Now(), } diff --git a/pkg/coredata/cookie_consent_record.go b/pkg/coredata/cookie_consent_record.go index 194040f06..9714e0d3d 100644 --- a/pkg/coredata/cookie_consent_record.go +++ b/pkg/coredata/cookie_consent_record.go @@ -40,6 +40,7 @@ type ( ConsentData json.RawMessage `db:"consent_data"` Action CookieConsentAction `db:"action"` SdkVersion string `db:"sdk_version"` + Regulation string `db:"regulation"` CreatedAt time.Time `db:"created_at"` } @@ -90,6 +91,7 @@ SELECT consent_data, action, sdk_version, + regulation, created_at FROM cookie_consent_records @@ -174,6 +176,7 @@ INSERT INTO cookie_consent_records ( consent_data, action, sdk_version, + regulation, created_at ) VALUES ( @id, @@ -187,6 +190,7 @@ INSERT INTO cookie_consent_records ( @consent_data, @action, @sdk_version, + @regulation, @created_at ) ` @@ -203,6 +207,7 @@ INSERT INTO cookie_consent_records ( "consent_data": r.ConsentData, "action": r.Action, "sdk_version": r.SdkVersion, + "regulation": r.Regulation, "created_at": r.CreatedAt, } @@ -232,6 +237,7 @@ SELECT consent_data, action, sdk_version, + regulation, created_at FROM cookie_consent_records @@ -283,6 +289,7 @@ SELECT consent_data, action, sdk_version, + regulation, created_at FROM cookie_consent_records diff --git a/pkg/coredata/migrations/20260506T163600Z.sql b/pkg/coredata/migrations/20260506T163600Z.sql new file mode 100644 index 000000000..5a2cb66fe --- /dev/null +++ b/pkg/coredata/migrations/20260506T163600Z.sql @@ -0,0 +1,19 @@ +-- Copyright (c) 2026 Probo Inc . +-- +-- Permission to use, copy, modify, and/or distribute this software for any +-- purpose with or without fee is hereby granted, provided that the above +-- copyright notice and this permission notice appear in all copies. +-- +-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +-- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +-- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +-- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +-- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +-- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +-- PERFORMANCE OF THIS SOFTWARE. + +ALTER TABLE cookie_consent_records + ADD COLUMN regulation TEXT NOT NULL DEFAULT ''; + +ALTER TABLE cookie_consent_records + ALTER COLUMN regulation DROP DEFAULT; diff --git a/pkg/server/api/cookiebanner/v1/handler.go b/pkg/server/api/cookiebanner/v1/handler.go index 0e1fbc64b..8c782bad4 100644 --- a/pkg/server/api/cookiebanner/v1/handler.go +++ b/pkg/server/api/cookiebanner/v1/handler.go @@ -191,6 +191,7 @@ func (h *Handler) handlePostConsent(w http.ResponseWriter, r *http.Request) { ConsentData: body.ConsentData, Action: body.Action, SdkVersion: sdkVersion, + Regulation: h.resolveRegulation(r), } record, err := h.cookieBannerSvc.RecordConsent(r.Context(), bannerID, req)