feat(cookiebot): add region settings

This commit is contained in:
Kevin Franklin Kim 2025-03-17 09:30:37 +01:00
parent 2983e5ee7d
commit 741c6bb44e
No known key found for this signature in database
6 changed files with 207 additions and 64 deletions

View File

@ -429,6 +429,20 @@ cookiebot:
urlPassthrough: false
# Enable advertiser consent mode
advertiserConsentModeEnabled: false
# Default Consent state
regionSettings:
# Region (leave blank to apply globally)
- region: ''
# Default consent for functionality_storage and personalization_storage
preferences: denied
# Default consent for analytics_storage
statistics: denied
# Default consent for ad_storage
marketing: denied
# Default consent ad_user_data
adUserData: denied
# Default consent ad_personalization
adPersonalization: denied
```
## Caveats

View File

@ -2,10 +2,17 @@ package config
type Cookiebot struct {
// Enable provider
Enabled bool `json:"enabled" yaml:"enabled"`
TemplateName string `json:"templateName" yaml:"templateName"`
CookiebotID string `json:"cookiebotId" yaml:"cookiebotId"`
CDNRegion string `json:"cdnRegion" yaml:"cdnRegion"`
URLPassthrough bool `json:"urlPassthrough" yaml:"urlPassthrough"`
AdvertiserConsentModeEnabled bool `json:"advertiserConsentModeEnabled" yaml:"advertiserConsentModeEnabled"`
Enabled bool `json:"enabled" yaml:"enabled"`
// Name of the manually installed Cookiebot CMP tag template
TemplateName string `json:"templateName" yaml:"templateName"`
// Create an account on Cookiebot.com and copy 'Domain Group ID' from the tab 'Your Scripts' in Cookiebot
CookiebotID string `json:"cookiebotId" yaml:"cookiebotId"`
// Select which CDN region Cookiebot uses
CDNRegion string `json:"cdnRegion" yaml:"cdnRegion"`
// When using URL passthrough, a few query parameters may be appended to links as users navigate through pages on your website
URLPassthrough bool `json:"urlPassthrough" yaml:"urlPassthrough"`
// If enabled, Google will deduce ad_storage, ad_user_data and ad_personalization data from the TC string.
AdvertiserConsentModeEnabled bool `json:"advertiserConsentModeEnabled" yaml:"advertiserConsentModeEnabled"`
// Default Consent state
RegionSettings []CookiebotRegionSetting `json:"regionSettings" yaml:"regionSettings"`
}

View File

@ -0,0 +1,16 @@
package config
type CookiebotRegionSetting struct {
// Region (leave blank to apply globally)
Region string `json:"region" yaml:"region"`
// Default consent for functionality_storage and personalization_storage
Preferences string `json:"preferences" yaml:"preferences"`
// Default consent for analytics_storage
Statistics string `json:"statistics" yaml:"statistics"`
// Default consent for ad_storage
Marketing string `json:"marketing" yaml:"marketing"`
// Default consent ad_user_data
AdUserData string `json:"adUserData" yaml:"adUserData"`
// Default consent ad_personalization
AdPersonalization string `json:"adPersonalization" yaml:"adPersonalization"`
}

View File

@ -10,62 +10,109 @@ import (
)
func NewCookiebotInitialization(name string, cfg config.Cookiebot, template *tagmanager.CustomTemplate) *tagmanager.Tag {
parameter := []*tagmanager.Parameter{
{
Key: "adsDataRedaction",
Type: "template",
Value: "dynamic",
},
{
Key: "addGeoRegion",
Type: "boolean",
Value: "false",
},
{
Key: "serial",
Type: "template",
Value: cfg.CookiebotID,
},
{
Key: "iabFramework",
Type: "boolean",
Value: "false",
},
{
Key: "cdnRegion",
Type: "template",
Value: cfg.CDNRegion,
},
{
Key: "advertiserConsentModeEnabled",
Type: "boolean",
Value: "true",
},
{
Key: "language",
Type: "template",
Value: "auto",
},
{
Key: "urlPassthrough",
Type: "boolean",
Value: strconv.FormatBool(cfg.URLPassthrough),
},
{
Key: "consentModeEnabled",
Type: "boolean",
Value: "true",
},
{
Key: "waitForUpdate",
Type: "template",
Value: "2000",
},
}
if len(cfg.RegionSettings) > 0 {
param := &tagmanager.Parameter{
Key: "regionSettings",
Type: "list",
}
for _, setting := range cfg.RegionSettings {
param.List = append(param.List, &tagmanager.Parameter{
Map: []*tagmanager.Parameter{
{
Key: "region",
Type: "template",
Value: setting.Region,
},
{
Key: "defaultConsentPreferences",
Type: "template",
Value: setting.Preferences,
},
{
Key: "defaultConsentStatistics",
Type: "template",
Value: setting.Statistics,
},
{
Key: "defaultConsentMarketing",
Type: "template",
Value: setting.Marketing,
},
{
Key: "defaultConsentMarketingAdUserData",
Type: "template",
Value: setting.AdUserData,
},
{
Key: "defaultConsentMarketingAdPersonalization",
Type: "template",
Value: setting.AdPersonalization,
},
},
Type: "map",
})
}
parameter = append(parameter, param)
}
return &tagmanager.Tag{
Name: name,
FiringTriggerId: []string{trigger.IDConsentInitializtion},
TagFiringOption: "oncePerEvent",
Parameter: []*tagmanager.Parameter{
{
Key: "adsDataRedaction",
Type: "template",
Value: "dynamic",
},
{
Key: "addGeoRegion",
Type: "boolean",
Value: "false",
},
{
Key: "serial",
Type: "template",
Value: cfg.CookiebotID,
},
{
Key: "iabFramework",
Type: "boolean",
Value: "false",
},
{
Key: "cdnRegion",
Type: "template",
Value: cfg.CDNRegion,
},
{
Key: "advertiserConsentModeEnabled",
Type: "boolean",
Value: "true",
},
{
Key: "language",
Type: "template",
Value: "auto",
},
{
Key: "urlPassthrough",
Type: "boolean",
Value: strconv.FormatBool(cfg.URLPassthrough),
},
{
Key: "consentModeEnabled",
Type: "boolean",
Value: "true",
},
{
Key: "waitForUpdate",
Type: "template",
Value: "2000",
},
},
Type: utils.TemplateType(template),
Parameter: parameter,
Type: utils.TemplateType(template),
}
}

View File

@ -9,6 +9,12 @@
},
"type": "array"
},
"[]config.CookiebotRegionSetting": {
"items": {
"$ref": "#/$defs/github.com.foomo.sesamy-cli.pkg.config.CookiebotRegionSetting"
},
"type": "array"
},
"[]string": {
"items": {
"type": "string"
@ -137,19 +143,58 @@
"description": "Enable provider"
},
"templateName": {
"type": "string"
"type": "string",
"description": "Name of the manually installed Cookiebot CMP tag template"
},
"cookiebotId": {
"type": "string"
"type": "string",
"description": "Create an account on Cookiebot.com and copy 'Domain Group ID' from the tab 'Your Scripts' in Cookiebot"
},
"cdnRegion": {
"type": "string"
"type": "string",
"description": "Select which CDN region Cookiebot uses"
},
"urlPassthrough": {
"type": "boolean"
"type": "boolean",
"description": "When using URL passthrough, a few query parameters may be appended to links as users navigate through pages on your website"
},
"advertiserConsentModeEnabled": {
"type": "boolean"
"type": "boolean",
"description": "If enabled, Google will deduce ad_storage, ad_user_data and ad_personalization data from the TC string."
},
"regionSettings": {
"$ref": "#/$defs/[]config.CookiebotRegionSetting",
"description": "Default Consent state"
}
},
"additionalProperties": false,
"type": "object"
},
"github.com.foomo.sesamy-cli.pkg.config.CookiebotRegionSetting": {
"properties": {
"region": {
"type": "string",
"description": "Region (leave blank to apply globally)"
},
"preferences": {
"type": "string",
"description": "Default consent for functionality_storage and personalization_storage"
},
"statistics": {
"type": "string",
"description": "Default consent for analytics_storage"
},
"marketing": {
"type": "string",
"description": "Default consent for ad_storage"
},
"adUserData": {
"type": "string",
"description": "Default consent ad_user_data"
},
"adPersonalization": {
"type": "string",
"description": "Default consent ad_personalization"
}
},
"additionalProperties": false,

View File

@ -421,3 +421,17 @@ cookiebot:
urlPassthrough: false
# Enable advertiser consent mode
advertiserConsentModeEnabled: false
# Default Consent state
regionSettings:
# Region (leave blank to apply globally)
- region: ''
# Default consent for functionality_storage and personalization_storage
preferences: denied
# Default consent for analytics_storage
statistics: denied
# Default consent for ad_storage
marketing: denied
# Default consent ad_user_data
adUserData: denied
# Default consent ad_personalization
adPersonalization: denied