Store detected regulation in consent records and expose it in SDK

Add a regulation column to cookie_consent_records so each consent
captures which privacy law was in effect. Thread the value from the
handler's geoloc resolution through the service into the DB insert.

On the SDK side, add a Regulation union type to BannerConfig and expose
it via a getter on CookieBannerClient and in the probo-ready event
detail so themed-banner consumers can adapt their UI per regulation.

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-05-06 20:44:16 +04:00
parent d5394317bb
commit f695b90b19
6 changed files with 51 additions and 1 deletions

View File

@@ -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;

View File

@@ -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 },
}),
);

View File

@@ -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(),
}

View File

@@ -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

View File

@@ -0,0 +1,19 @@
-- Copyright (c) 2026 Probo Inc <hello@getprobo.com>.
--
-- 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;

View File

@@ -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)