From 233db213501be5e147cdc30f864d9aa80f09d30f Mon Sep 17 00:00:00 2001 From: Kevin Franklin Kim Date: Mon, 17 Mar 2025 09:29:25 +0100 Subject: [PATCH 1/3] fix(emarsys): use test for initialization --- .../emarsys/server/template/emarsysinitializationclientdata.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/provider/emarsys/server/template/emarsysinitializationclientdata.go b/pkg/provider/emarsys/server/template/emarsysinitializationclientdata.go index e91730b..c062397 100644 --- a/pkg/provider/emarsys/server/template/emarsysinitializationclientdata.go +++ b/pkg/provider/emarsys/server/template/emarsysinitializationclientdata.go @@ -79,7 +79,7 @@ const headers = { 'user-agent': getRequestHeader('user-agent'), }; -let query = ['xp=1', 'cp=1']; +let query = ['xp=1', 'cp=1', 'test=true']; if (sessionId) query.push('s='+encodeUriComponent(sessionId)); if (visitorId) query.push('vi='+encodeUriComponent(visitorId)); if (pageViewId) query.push('pv='+encodeUriComponent(pageViewId)); From 2983e5ee7dfe6194809170a47785eab602f7dba1 Mon Sep 17 00:00:00 2001 From: Kevin Franklin Kim Date: Mon, 17 Mar 2025 09:30:02 +0100 Subject: [PATCH 2/3] feat(emarsys): add search param --- .../emarsys/server/template/emarsyswebextendtagdata.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/provider/emarsys/server/template/emarsyswebextendtagdata.go b/pkg/provider/emarsys/server/template/emarsyswebextendtagdata.go index 5e85b2e..eb74e29 100644 --- a/pkg/provider/emarsys/server/template/emarsyswebextendtagdata.go +++ b/pkg/provider/emarsys/server/template/emarsyswebextendtagdata.go @@ -81,6 +81,7 @@ ___SANDBOXED_JS_FOR_SERVER___ const Math = require('Math'); const JSON = require('JSON'); +const parseUrl = require('parseUrl'); const setCookie = require('setCookie'); const sendHttpGet = require('sendHttpGet'); const setResponseBody = require('setResponseBody'); @@ -142,6 +143,7 @@ function mapEventData() { referrer: eventData.page_referrer || null, orderId: null, order: null, + search: null, category: null, view: null, cart: null, @@ -150,6 +152,7 @@ function mapEventData() { switch (eventData.event_name) { case 'page_view': { mappedData.cart = serializeItems(eventData.items || []); + mappedData.search = ((parseUrl(eventData.page_location) || {}).searchParams || {}).q || null; break; } case 'view_item': { @@ -237,6 +240,9 @@ function serializeData(mappedData) { slist.push("ca=" + encodeUriComponent(mappedData.cart)); slist.push("cv=1"); } + if (mappedData.search) { + slist.push("q=" + encodeUriComponent(mappedData.search)); + } if (mappedData.referrer) { slist.push("prev_url=" + encodeUriComponent(mappedData.referrer)); } From 741c6bb44ec992a4c6b737a9bd636ee1fc7dbca2 Mon Sep 17 00:00:00 2001 From: Kevin Franklin Kim Date: Mon, 17 Mar 2025 09:30:37 +0100 Subject: [PATCH 3/3] feat(cookiebot): add region settings --- README.md | 14 ++ pkg/config/cookiebot.go | 19 ++- pkg/config/cookiebotregionsetting.go | 16 ++ .../web/tag/cookiebotinitialization.go | 153 ++++++++++++------ sesamy.schema.json | 55 ++++++- sesamy.yaml | 14 ++ 6 files changed, 207 insertions(+), 64 deletions(-) create mode 100644 pkg/config/cookiebotregionsetting.go diff --git a/README.md b/README.md index 2e847dd..c73f162 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/pkg/config/cookiebot.go b/pkg/config/cookiebot.go index 625b967..977da16 100644 --- a/pkg/config/cookiebot.go +++ b/pkg/config/cookiebot.go @@ -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"` } diff --git a/pkg/config/cookiebotregionsetting.go b/pkg/config/cookiebotregionsetting.go new file mode 100644 index 0000000..1a0eaf2 --- /dev/null +++ b/pkg/config/cookiebotregionsetting.go @@ -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"` +} diff --git a/pkg/provider/cookiebot/web/tag/cookiebotinitialization.go b/pkg/provider/cookiebot/web/tag/cookiebotinitialization.go index fd5754d..db15b72 100644 --- a/pkg/provider/cookiebot/web/tag/cookiebotinitialization.go +++ b/pkg/provider/cookiebot/web/tag/cookiebotinitialization.go @@ -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), } } diff --git a/sesamy.schema.json b/sesamy.schema.json index cebb57b..7c64f4f 100644 --- a/sesamy.schema.json +++ b/sesamy.schema.json @@ -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, diff --git a/sesamy.yaml b/sesamy.yaml index 3f52124..e95561a 100644 --- a/sesamy.yaml +++ b/sesamy.yaml @@ -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