Merge pull request #104 from foomo/feature/v0.17.1

v0.18.0
This commit is contained in:
Kevin Franklin Kim 2025-03-17 09:35:32 +01:00 committed by GitHub
commit 339f91085d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 214 additions and 65 deletions

View File

@ -429,6 +429,20 @@ cookiebot:
urlPassthrough: false urlPassthrough: false
# Enable advertiser consent mode # Enable advertiser consent mode
advertiserConsentModeEnabled: false 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 ## Caveats

View File

@ -2,10 +2,17 @@ package config
type Cookiebot struct { type Cookiebot struct {
// Enable provider // Enable provider
Enabled bool `json:"enabled" yaml:"enabled"` Enabled bool `json:"enabled" yaml:"enabled"`
TemplateName string `json:"templateName" yaml:"templateName"` // Name of the manually installed Cookiebot CMP tag template
CookiebotID string `json:"cookiebotId" yaml:"cookiebotId"` TemplateName string `json:"templateName" yaml:"templateName"`
CDNRegion string `json:"cdnRegion" yaml:"cdnRegion"` // Create an account on Cookiebot.com and copy 'Domain Group ID' from the tab 'Your Scripts' in Cookiebot
URLPassthrough bool `json:"urlPassthrough" yaml:"urlPassthrough"` CookiebotID string `json:"cookiebotId" yaml:"cookiebotId"`
AdvertiserConsentModeEnabled bool `json:"advertiserConsentModeEnabled" yaml:"advertiserConsentModeEnabled"` // 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 { 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{ return &tagmanager.Tag{
Name: name, Name: name,
FiringTriggerId: []string{trigger.IDConsentInitializtion}, FiringTriggerId: []string{trigger.IDConsentInitializtion},
TagFiringOption: "oncePerEvent", TagFiringOption: "oncePerEvent",
Parameter: []*tagmanager.Parameter{ Parameter: parameter,
{ Type: utils.TemplateType(template),
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),
} }
} }

View File

@ -79,7 +79,7 @@ const headers = {
'user-agent': getRequestHeader('user-agent'), '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 (sessionId) query.push('s='+encodeUriComponent(sessionId));
if (visitorId) query.push('vi='+encodeUriComponent(visitorId)); if (visitorId) query.push('vi='+encodeUriComponent(visitorId));
if (pageViewId) query.push('pv='+encodeUriComponent(pageViewId)); if (pageViewId) query.push('pv='+encodeUriComponent(pageViewId));

View File

@ -81,6 +81,7 @@ ___SANDBOXED_JS_FOR_SERVER___
const Math = require('Math'); const Math = require('Math');
const JSON = require('JSON'); const JSON = require('JSON');
const parseUrl = require('parseUrl');
const setCookie = require('setCookie'); const setCookie = require('setCookie');
const sendHttpGet = require('sendHttpGet'); const sendHttpGet = require('sendHttpGet');
const setResponseBody = require('setResponseBody'); const setResponseBody = require('setResponseBody');
@ -142,6 +143,7 @@ function mapEventData() {
referrer: eventData.page_referrer || null, referrer: eventData.page_referrer || null,
orderId: null, orderId: null,
order: null, order: null,
search: null,
category: null, category: null,
view: null, view: null,
cart: null, cart: null,
@ -150,6 +152,7 @@ function mapEventData() {
switch (eventData.event_name) { switch (eventData.event_name) {
case 'page_view': { case 'page_view': {
mappedData.cart = serializeItems(eventData.items || []); mappedData.cart = serializeItems(eventData.items || []);
mappedData.search = ((parseUrl(eventData.page_location) || {}).searchParams || {}).q || null;
break; break;
} }
case 'view_item': { case 'view_item': {
@ -237,6 +240,9 @@ function serializeData(mappedData) {
slist.push("ca=" + encodeUriComponent(mappedData.cart)); slist.push("ca=" + encodeUriComponent(mappedData.cart));
slist.push("cv=1"); slist.push("cv=1");
} }
if (mappedData.search) {
slist.push("q=" + encodeUriComponent(mappedData.search));
}
if (mappedData.referrer) { if (mappedData.referrer) {
slist.push("prev_url=" + encodeUriComponent(mappedData.referrer)); slist.push("prev_url=" + encodeUriComponent(mappedData.referrer));
} }

View File

@ -9,6 +9,12 @@
}, },
"type": "array" "type": "array"
}, },
"[]config.CookiebotRegionSetting": {
"items": {
"$ref": "#/$defs/github.com.foomo.sesamy-cli.pkg.config.CookiebotRegionSetting"
},
"type": "array"
},
"[]string": { "[]string": {
"items": { "items": {
"type": "string" "type": "string"
@ -137,19 +143,58 @@
"description": "Enable provider" "description": "Enable provider"
}, },
"templateName": { "templateName": {
"type": "string" "type": "string",
"description": "Name of the manually installed Cookiebot CMP tag template"
}, },
"cookiebotId": { "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": { "cdnRegion": {
"type": "string" "type": "string",
"description": "Select which CDN region Cookiebot uses"
}, },
"urlPassthrough": { "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": { "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, "additionalProperties": false,

View File

@ -421,3 +421,17 @@ cookiebot:
urlPassthrough: false urlPassthrough: false
# Enable advertiser consent mode # Enable advertiser consent mode
advertiserConsentModeEnabled: false 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