Default cookie consent to GDPR and track its source
When IP geolocation does not resolve a country, or resolves one with no known cookie-consent regulation (common on localhost and unmapped regions), the banner previously fell back to OPT_OUT with no recorded regulation. Apply GDPR (OPT_IN) as the safe default in that case so the strictest consent model wins when origin is unknown. To keep consent records auditable, stamp each one with a regulation source of DETECTED (resolved from geolocation) or DEFAULT (fell back to GDPR). The shared cookiebanner.ResolveRegulation helper centralizes the decision for both the config and consent endpoints, and the new value is exposed through GraphQL, MCP, the CLI, the n8n node, and the console consent-records views. Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
@@ -58,6 +58,7 @@ export const cookieBannerConsentRecordPageQuery = graphql`
|
||||
userAgent
|
||||
sdkVersion
|
||||
regulation
|
||||
regulationSource
|
||||
countryCode
|
||||
consentData
|
||||
createdAt
|
||||
@@ -159,6 +160,11 @@ export default function CookieBannerConsentRecordPage({
|
||||
{record.regulation || "-"}
|
||||
</span>
|
||||
</PropertyRow>
|
||||
<PropertyRow label={__("Regulation Source")}>
|
||||
<span className="font-mono text-sm">
|
||||
{record.regulationSource || "-"}
|
||||
</span>
|
||||
</PropertyRow>
|
||||
<PropertyRow label={__("Country")}>
|
||||
<span className="font-mono text-sm">
|
||||
{record.countryCode || "-"}
|
||||
|
||||
@@ -217,6 +217,7 @@ export default function CookieBannerConsentRecordsPage({
|
||||
<Th>{__("IP Address")}</Th>
|
||||
<Th>{__("SDK Version")}</Th>
|
||||
<Th>{__("Regulation")}</Th>
|
||||
<Th>{__("Source")}</Th>
|
||||
<Th>{__("Country")}</Th>
|
||||
<SortableTh field="CREATED_AT">{__("Date")}</SortableTh>
|
||||
</Tr>
|
||||
|
||||
@@ -36,6 +36,7 @@ const consentRecordFragment = graphql`
|
||||
ipAddress
|
||||
sdkVersion
|
||||
regulation
|
||||
regulationSource
|
||||
countryCode
|
||||
createdAt
|
||||
}
|
||||
@@ -81,6 +82,11 @@ export function ConsentRecordRow({ recordKey }: ConsentRecordRowProps) {
|
||||
{record.regulation || "-"}
|
||||
</span>
|
||||
</Td>
|
||||
<Td>
|
||||
<span className="font-mono text-sm">
|
||||
{record.regulationSource || "-"}
|
||||
</span>
|
||||
</Td>
|
||||
<Td>
|
||||
<span className="font-mono text-sm">
|
||||
{record.countryCode || "-"}
|
||||
|
||||
@@ -50,6 +50,7 @@ export async function execute(
|
||||
action
|
||||
sdkVersion
|
||||
regulation
|
||||
regulationSource
|
||||
countryCode
|
||||
createdAt
|
||||
}
|
||||
|
||||
@@ -153,6 +153,7 @@ export async function execute(
|
||||
action
|
||||
sdkVersion
|
||||
regulation
|
||||
regulationSource
|
||||
countryCode
|
||||
createdAt
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ query($id: ID!, $first: Int, $after: CursorKey, $filter: CookieConsentRecordFilt
|
||||
action
|
||||
sdkVersion
|
||||
regulation
|
||||
regulationSource
|
||||
countryCode
|
||||
createdAt
|
||||
}
|
||||
@@ -52,13 +53,14 @@ query($id: ID!, $first: Int, $after: CursorKey, $filter: CookieConsentRecordFilt
|
||||
`
|
||||
|
||||
type consentRecord struct {
|
||||
ID string `json:"id"`
|
||||
VisitorID string `json:"visitorId"`
|
||||
Action string `json:"action"`
|
||||
SDKVersion string `json:"sdkVersion"`
|
||||
Regulation *string `json:"regulation"`
|
||||
CountryCode *string `json:"countryCode"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
ID string `json:"id"`
|
||||
VisitorID string `json:"visitorId"`
|
||||
Action string `json:"action"`
|
||||
SDKVersion string `json:"sdkVersion"`
|
||||
Regulation *string `json:"regulation"`
|
||||
RegulationSource *string `json:"regulationSource"`
|
||||
CountryCode *string `json:"countryCode"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
}
|
||||
|
||||
func NewCmdList(f *cmdutil.Factory) *cobra.Command {
|
||||
@@ -165,15 +167,20 @@ func NewCmdList(f *cmdutil.Factory) *cobra.Command {
|
||||
regulation = *r.Regulation
|
||||
}
|
||||
|
||||
regulationSource := "-"
|
||||
if r.RegulationSource != nil {
|
||||
regulationSource = *r.RegulationSource
|
||||
}
|
||||
|
||||
countryCode := "-"
|
||||
if r.CountryCode != nil {
|
||||
countryCode = *r.CountryCode
|
||||
}
|
||||
|
||||
rows = append(rows, []string{r.ID, r.VisitorID, r.Action, r.SDKVersion, regulation, countryCode, r.CreatedAt})
|
||||
rows = append(rows, []string{r.ID, r.VisitorID, r.Action, r.SDKVersion, regulation, regulationSource, countryCode, r.CreatedAt})
|
||||
}
|
||||
|
||||
t := cmdutil.NewTable("ID", "VISITOR ID", "ACTION", "SDK VERSION", "REGULATION", "COUNTRY", "CREATED AT").Rows(rows...)
|
||||
t := cmdutil.NewTable("ID", "VISITOR ID", "ACTION", "SDK VERSION", "REGULATION", "SOURCE", "COUNTRY", "CREATED AT").Rows(rows...)
|
||||
_, _ = fmt.Fprintln(f.IOStreams.Out, t)
|
||||
|
||||
if totalCount > len(records) {
|
||||
|
||||
@@ -37,6 +37,7 @@ query($id: ID!) {
|
||||
action
|
||||
sdkVersion
|
||||
regulation
|
||||
regulationSource
|
||||
countryCode
|
||||
createdAt
|
||||
}
|
||||
@@ -46,17 +47,18 @@ query($id: ID!) {
|
||||
|
||||
type viewResponse struct {
|
||||
Node *struct {
|
||||
Typename string `json:"__typename"`
|
||||
ID string `json:"id"`
|
||||
VisitorID string `json:"visitorId"`
|
||||
IPAddress *string `json:"ipAddress"`
|
||||
UserAgent *string `json:"userAgent"`
|
||||
ConsentData string `json:"consentData"`
|
||||
Action string `json:"action"`
|
||||
SdkVersion string `json:"sdkVersion"`
|
||||
Regulation *string `json:"regulation"`
|
||||
CountryCode *string `json:"countryCode"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
Typename string `json:"__typename"`
|
||||
ID string `json:"id"`
|
||||
VisitorID string `json:"visitorId"`
|
||||
IPAddress *string `json:"ipAddress"`
|
||||
UserAgent *string `json:"userAgent"`
|
||||
ConsentData string `json:"consentData"`
|
||||
Action string `json:"action"`
|
||||
SdkVersion string `json:"sdkVersion"`
|
||||
Regulation *string `json:"regulation"`
|
||||
RegulationSource *string `json:"regulationSource"`
|
||||
CountryCode *string `json:"countryCode"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
} `json:"node"`
|
||||
}
|
||||
|
||||
@@ -124,6 +126,10 @@ func NewCmdView(f *cmdutil.Factory) *cobra.Command {
|
||||
_, _ = fmt.Fprintf(out, "%s%s\n", label.Render("Regulation:"), *v.Regulation)
|
||||
}
|
||||
|
||||
if v.RegulationSource != nil {
|
||||
_, _ = fmt.Fprintf(out, "%s%s\n", label.Render("Regulation Source:"), *v.RegulationSource)
|
||||
}
|
||||
|
||||
if v.CountryCode != nil {
|
||||
_, _ = fmt.Fprintf(out, "%s%s\n", label.Render("Country Code:"), *v.CountryCode)
|
||||
}
|
||||
|
||||
@@ -36,11 +36,32 @@ const (
|
||||
RegulationPDPL = coredata.RegulationPDPL
|
||||
)
|
||||
|
||||
type RegulationSource = coredata.RegulationSource
|
||||
|
||||
const (
|
||||
RegulationSourceDetected = coredata.RegulationSourceDetected
|
||||
RegulationSourceDefault = coredata.RegulationSourceDefault
|
||||
)
|
||||
|
||||
const (
|
||||
ConsentModeOptIn = "OPT_IN"
|
||||
ConsentModeOptOut = "OPT_OUT"
|
||||
)
|
||||
|
||||
// ResolveRegulation returns the regulation to apply for a visitor along
|
||||
// with its source. It defaults to GDPR when geolocation is unresolved
|
||||
// (cc is nil) or when the resolved country maps to no known regulation,
|
||||
// ensuring the strictest opt-in consent model applies by default.
|
||||
func ResolveRegulation(cc *coredata.CountryCode) (Regulation, RegulationSource) {
|
||||
if cc != nil {
|
||||
if reg := RegulationForCountry(*cc); reg != RegulationNone {
|
||||
return reg, RegulationSourceDetected
|
||||
}
|
||||
}
|
||||
|
||||
return RegulationGDPR, RegulationSourceDefault
|
||||
}
|
||||
|
||||
// RegulationForCountry maps a country code to the applicable privacy
|
||||
// regulation. For countries with no known cookie-consent regulation it
|
||||
// returns RegulationNone.
|
||||
|
||||
74
pkg/cookiebanner/regulation_test.go
Normal file
74
pkg/cookiebanner/regulation_test.go
Normal file
@@ -0,0 +1,74 @@
|
||||
// Copyright (c) 2026 Probo Inc <hello@probo.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.
|
||||
|
||||
package cookiebanner
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.probo.inc/probo/pkg/coredata"
|
||||
)
|
||||
|
||||
func TestResolveRegulation(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
countryCode *coredata.CountryCode
|
||||
wantRegulation Regulation
|
||||
wantSource RegulationSource
|
||||
}{
|
||||
{
|
||||
name: "unresolved geolocation defaults to GDPR",
|
||||
countryCode: nil,
|
||||
wantRegulation: RegulationGDPR,
|
||||
wantSource: RegulationSourceDefault,
|
||||
},
|
||||
{
|
||||
name: "country with no known regulation defaults to GDPR",
|
||||
countryCode: new(coredata.CountryCodeAQ),
|
||||
wantRegulation: RegulationGDPR,
|
||||
wantSource: RegulationSourceDefault,
|
||||
},
|
||||
{
|
||||
name: "EU country resolves to GDPR as detected",
|
||||
countryCode: new(coredata.CountryCodeFR),
|
||||
wantRegulation: RegulationGDPR,
|
||||
wantSource: RegulationSourceDetected,
|
||||
},
|
||||
{
|
||||
name: "US resolves to CCPA as detected",
|
||||
countryCode: new(coredata.CountryCodeUS),
|
||||
wantRegulation: RegulationCCPA,
|
||||
wantSource: RegulationSourceDetected,
|
||||
},
|
||||
{
|
||||
name: "UK resolves to UK GDPR as detected",
|
||||
countryCode: new(coredata.CountryCodeGB),
|
||||
wantRegulation: RegulationUKGDPR,
|
||||
wantSource: RegulationSourceDetected,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
regulation, source := ResolveRegulation(tt.countryCode)
|
||||
require.Equal(t, tt.wantRegulation, regulation)
|
||||
require.Equal(t, tt.wantSource, source)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -96,16 +96,17 @@ type (
|
||||
}
|
||||
|
||||
RecordConsentRequest struct {
|
||||
Version int
|
||||
VisitorID string
|
||||
IPAddress *string
|
||||
UserAgent *string
|
||||
ConsentData json.RawMessage
|
||||
Action coredata.CookieConsentAction
|
||||
SdkVersion string
|
||||
Regulation *Regulation
|
||||
CountryCode *coredata.CountryCode
|
||||
ConsentMode *coredata.CookieConsentMode
|
||||
Version int
|
||||
VisitorID string
|
||||
IPAddress *string
|
||||
UserAgent *string
|
||||
ConsentData json.RawMessage
|
||||
Action coredata.CookieConsentAction
|
||||
SdkVersion string
|
||||
Regulation *Regulation
|
||||
RegulationSource coredata.RegulationSource
|
||||
CountryCode *coredata.CountryCode
|
||||
ConsentMode *coredata.CookieConsentMode
|
||||
}
|
||||
|
||||
DetectedCookie struct {
|
||||
@@ -2076,6 +2077,7 @@ func (s *Service) RecordConsent(
|
||||
Action: req.Action,
|
||||
SdkVersion: req.SdkVersion,
|
||||
Regulation: req.Regulation,
|
||||
RegulationSource: &req.RegulationSource,
|
||||
CountryCode: req.CountryCode,
|
||||
ConsentMode: req.ConsentMode,
|
||||
CreatedAt: time.Now(),
|
||||
|
||||
@@ -42,6 +42,7 @@ type (
|
||||
Action CookieConsentAction `db:"action"`
|
||||
SdkVersion string `db:"sdk_version"`
|
||||
Regulation *Regulation `db:"regulation"`
|
||||
RegulationSource *RegulationSource `db:"regulation_source"`
|
||||
CountryCode *CountryCode `db:"country_code"`
|
||||
ConsentMode *CookieConsentMode `db:"consent_mode"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
@@ -119,6 +120,7 @@ SELECT
|
||||
action,
|
||||
sdk_version,
|
||||
regulation,
|
||||
regulation_source,
|
||||
country_code,
|
||||
consent_mode,
|
||||
created_at
|
||||
@@ -206,6 +208,7 @@ INSERT INTO cookie_consent_records (
|
||||
action,
|
||||
sdk_version,
|
||||
regulation,
|
||||
regulation_source,
|
||||
country_code,
|
||||
consent_mode,
|
||||
created_at
|
||||
@@ -222,6 +225,7 @@ INSERT INTO cookie_consent_records (
|
||||
@action,
|
||||
@sdk_version,
|
||||
@regulation,
|
||||
@regulation_source,
|
||||
@country_code,
|
||||
@consent_mode,
|
||||
@created_at
|
||||
@@ -241,6 +245,7 @@ INSERT INTO cookie_consent_records (
|
||||
"action": r.Action,
|
||||
"sdk_version": r.SdkVersion,
|
||||
"regulation": r.Regulation,
|
||||
"regulation_source": r.RegulationSource,
|
||||
"country_code": r.CountryCode,
|
||||
"consent_mode": r.ConsentMode,
|
||||
"created_at": r.CreatedAt,
|
||||
@@ -273,6 +278,7 @@ SELECT
|
||||
action,
|
||||
sdk_version,
|
||||
regulation,
|
||||
regulation_source,
|
||||
country_code,
|
||||
consent_mode,
|
||||
created_at
|
||||
@@ -327,6 +333,7 @@ SELECT
|
||||
action,
|
||||
sdk_version,
|
||||
regulation,
|
||||
regulation_source,
|
||||
country_code,
|
||||
consent_mode,
|
||||
created_at
|
||||
|
||||
20
pkg/coredata/migrations/20260610T152400Z.sql
Normal file
20
pkg/coredata/migrations/20260610T152400Z.sql
Normal file
@@ -0,0 +1,20 @@
|
||||
-- Copyright (c) 2026 Probo Inc <hello@probo.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.
|
||||
|
||||
-- Record whether the regulation stamped on a consent was detected from the
|
||||
-- visitor's geolocation or defaulted to GDPR (when geolocation was unresolved
|
||||
-- or mapped to no known regulation). Pre-existing rows stay NULL.
|
||||
CREATE TYPE regulation_source AS ENUM ('DETECTED', 'DEFAULT');
|
||||
|
||||
ALTER TABLE cookie_consent_records ADD COLUMN regulation_source regulation_source;
|
||||
84
pkg/coredata/regulation_source.go
Normal file
84
pkg/coredata/regulation_source.go
Normal file
@@ -0,0 +1,84 @@
|
||||
// Copyright (c) 2026 Probo Inc <hello@probo.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.
|
||||
|
||||
package coredata
|
||||
|
||||
import (
|
||||
"encoding"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// RegulationSource records whether the regulation applied to a consent
|
||||
// was detected from the visitor's geolocation or defaulted because
|
||||
// geolocation was unresolved or mapped to no known regulation.
|
||||
type RegulationSource string
|
||||
|
||||
const (
|
||||
RegulationSourceDetected RegulationSource = "DETECTED"
|
||||
RegulationSourceDefault RegulationSource = "DEFAULT"
|
||||
)
|
||||
|
||||
var (
|
||||
_ fmt.Stringer = RegulationSource("")
|
||||
_ encoding.TextMarshaler = RegulationSource("")
|
||||
_ encoding.TextUnmarshaler = (*RegulationSource)(nil)
|
||||
)
|
||||
|
||||
func RegulationSources() []RegulationSource {
|
||||
return []RegulationSource{
|
||||
RegulationSourceDetected,
|
||||
RegulationSourceDefault,
|
||||
}
|
||||
}
|
||||
|
||||
func (v RegulationSource) IsValid() bool {
|
||||
switch v {
|
||||
case
|
||||
RegulationSourceDetected,
|
||||
RegulationSourceDefault:
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (v RegulationSource) String() string {
|
||||
return string(v)
|
||||
}
|
||||
|
||||
func (v RegulationSource) MarshalText() ([]byte, error) {
|
||||
return []byte(v.String()), nil
|
||||
}
|
||||
|
||||
func (v *RegulationSource) UnmarshalText(text []byte) error {
|
||||
val := RegulationSource(text)
|
||||
if !val.IsValid() {
|
||||
return fmt.Errorf("invalid RegulationSource value: %q", string(text))
|
||||
}
|
||||
|
||||
*v = val
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ParseRegulationSource(s string) (RegulationSource, error) {
|
||||
switch RegulationSource(s) {
|
||||
case RegulationSourceDetected:
|
||||
return RegulationSourceDetected, nil
|
||||
case RegulationSourceDefault:
|
||||
return RegulationSourceDefault, nil
|
||||
default:
|
||||
return "", fmt.Errorf("invalid RegulationSource value: %q", s)
|
||||
}
|
||||
}
|
||||
@@ -96,6 +96,18 @@ enum Regulation
|
||||
)
|
||||
}
|
||||
|
||||
enum RegulationSource
|
||||
@goModel(model: "go.probo.inc/probo/pkg/coredata.RegulationSource") {
|
||||
DETECTED
|
||||
@goEnum(
|
||||
value: "go.probo.inc/probo/pkg/coredata.RegulationSourceDetected"
|
||||
)
|
||||
DEFAULT
|
||||
@goEnum(
|
||||
value: "go.probo.inc/probo/pkg/coredata.RegulationSourceDefault"
|
||||
)
|
||||
}
|
||||
|
||||
enum CookieConsentRecordOrderField
|
||||
@goModel(
|
||||
model: "go.probo.inc/probo/pkg/coredata.CookieConsentRecordOrderField"
|
||||
@@ -131,6 +143,7 @@ type CookieConsentRecord implements Node {
|
||||
action: CookieConsentAction!
|
||||
sdkVersion: String!
|
||||
regulation: Regulation
|
||||
regulationSource: RegulationSource
|
||||
countryCode: CountryCode
|
||||
createdAt: Datetime!
|
||||
}
|
||||
|
||||
@@ -75,14 +75,15 @@ func NewCookieConsentRecord(r *coredata.CookieConsentRecord) *CookieConsentRecor
|
||||
CookieBannerVersion: &CookieBannerVersion{
|
||||
ID: r.CookieBannerVersionID,
|
||||
},
|
||||
VisitorID: r.VisitorID,
|
||||
IPAddress: r.IPAddress,
|
||||
UserAgent: r.UserAgent,
|
||||
ConsentData: string(r.ConsentData),
|
||||
Action: r.Action,
|
||||
SdkVersion: r.SdkVersion,
|
||||
Regulation: r.Regulation,
|
||||
CountryCode: r.CountryCode,
|
||||
CreatedAt: r.CreatedAt,
|
||||
VisitorID: r.VisitorID,
|
||||
IPAddress: r.IPAddress,
|
||||
UserAgent: r.UserAgent,
|
||||
ConsentData: string(r.ConsentData),
|
||||
Action: r.Action,
|
||||
SdkVersion: r.SdkVersion,
|
||||
Regulation: r.Regulation,
|
||||
RegulationSource: r.RegulationSource,
|
||||
CountryCode: r.CountryCode,
|
||||
CreatedAt: r.CreatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,11 +76,7 @@ func (h *Handler) handleGetConfig(w http.ResponseWriter, r *http.Request) {
|
||||
lang := r.URL.Query().Get("lang")
|
||||
sdkVersion := sdkVersionFromContext(r.Context())
|
||||
cc := h.resolveCountryCode(r)
|
||||
|
||||
var regulation cookiebanner.Regulation
|
||||
if cc != nil {
|
||||
regulation = cookiebanner.RegulationForCountry(*cc)
|
||||
}
|
||||
regulation, _ := cookiebanner.ResolveRegulation(cc)
|
||||
|
||||
config, err := h.cookieBannerSvc.GetActiveBannerConfig(r.Context(), bannerID, lang, regulation, sdkVersion)
|
||||
if err != nil {
|
||||
@@ -197,29 +193,22 @@ func (h *Handler) handlePostConsent(w http.ResponseWriter, r *http.Request) {
|
||||
ua := r.UserAgent()
|
||||
sdkVersion := sdkVersionFromContext(r.Context())
|
||||
cc := h.resolveCountryCode(r)
|
||||
regulation, regulationSource := cookiebanner.ResolveRegulation(cc)
|
||||
|
||||
var (
|
||||
regulation *cookiebanner.Regulation
|
||||
resolvedRegulation cookiebanner.Regulation
|
||||
)
|
||||
if cc != nil {
|
||||
resolvedRegulation = cookiebanner.RegulationForCountry(*cc)
|
||||
regulation = &resolvedRegulation
|
||||
}
|
||||
|
||||
cm := coredata.CookieConsentMode(cookiebanner.ConsentModeForRegulation(resolvedRegulation))
|
||||
cm := coredata.CookieConsentMode(cookiebanner.ConsentModeForRegulation(regulation))
|
||||
|
||||
req := cookiebanner.RecordConsentRequest{
|
||||
Version: body.Version,
|
||||
VisitorID: body.VisitorID,
|
||||
IPAddress: &ip,
|
||||
UserAgent: &ua,
|
||||
ConsentData: body.ConsentData,
|
||||
Action: body.Action,
|
||||
SdkVersion: sdkVersion,
|
||||
Regulation: regulation,
|
||||
CountryCode: cc,
|
||||
ConsentMode: &cm,
|
||||
Version: body.Version,
|
||||
VisitorID: body.VisitorID,
|
||||
IPAddress: &ip,
|
||||
UserAgent: &ua,
|
||||
ConsentData: body.ConsentData,
|
||||
Action: body.Action,
|
||||
SdkVersion: sdkVersion,
|
||||
Regulation: ®ulation,
|
||||
RegulationSource: regulationSource,
|
||||
CountryCode: cc,
|
||||
ConsentMode: &cm,
|
||||
}
|
||||
|
||||
record, err := h.cookieBannerSvc.RecordConsent(r.Context(), bannerID, req)
|
||||
|
||||
@@ -216,6 +216,13 @@ components:
|
||||
- PDPL
|
||||
go.probo.inc/mcpgen/type: go.probo.inc/probo/pkg/coredata.Regulation
|
||||
|
||||
RegulationSource:
|
||||
type: string
|
||||
enum:
|
||||
- DETECTED
|
||||
- DEFAULT
|
||||
go.probo.inc/mcpgen/type: go.probo.inc/probo/pkg/coredata.RegulationSource
|
||||
|
||||
CountryCode:
|
||||
type: string
|
||||
enum:
|
||||
@@ -9715,6 +9722,10 @@ components:
|
||||
$ref: "#/components/schemas/Regulation"
|
||||
description: Applicable regulation
|
||||
nullable: true
|
||||
regulation_source:
|
||||
$ref: "#/components/schemas/RegulationSource"
|
||||
description: Whether the regulation was detected from geolocation or defaulted to GDPR
|
||||
nullable: true
|
||||
country_code:
|
||||
$ref: "#/components/schemas/CountryCode"
|
||||
description: Visitor country code (ISO 3166-1 alpha-2)
|
||||
|
||||
@@ -36,6 +36,7 @@ func NewCookieConsentRecord(r *coredata.CookieConsentRecord) *CookieConsentRecor
|
||||
Action: CookieConsentRecordAction(r.Action),
|
||||
SdkVersion: r.SdkVersion,
|
||||
Regulation: r.Regulation,
|
||||
RegulationSource: r.RegulationSource,
|
||||
CountryCode: r.CountryCode,
|
||||
CreatedAt: r.CreatedAt,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user