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

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

View File

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

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