diff --git a/README.md b/README.md index 9e66360..e7d694a 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ $ brew install foomo/tap/sesamy-cli Add a `sesamy.yaml` configuration ```yaml -# yaml-language-server: $schema=https://raw.githubusercontent.com/foomo/sesamy-cli/v0.3.0/sesamy.yaml +# yaml-language-server: $schema=https://raw.githubusercontent.com/foomo/sesamy-cli/v0.4.1/sesamy.yaml version: '1.0' # Whether to redact the visitor ip @@ -211,6 +211,12 @@ googleAds: conversionLinker: # Enable provider enabled: true + # Google Consent settings + googleConsent: + # Enable consent mode + enabled: true + # Consent mode name + mode: ad_storage # --- Umami settings umami: @@ -298,7 +304,7 @@ cookiebot: enabled: true # Name of the manually installed Cookiebot CMP tag template # "https://tagmanager.google.com/gallery/#/owners/cybotcorp/templates/gtm-templates-cookiebot-cmp - templateName: "Cookiebot CMP" + templateName: Cookiebot CMP # Cookiebot id cookiebotId: '' # CDN Region (eu, com) diff --git a/pkg/config/conversionlinker.go b/pkg/config/conversionlinker.go index 73041c6..6c9bebf 100644 --- a/pkg/config/conversionlinker.go +++ b/pkg/config/conversionlinker.go @@ -1,5 +1,6 @@ package config type ConversionLinker struct { - Enabled bool `json:"enabled" yaml:"enabled"` + Enabled bool `json:"enabled" yaml:"enabled"` + GoogleConsent GoogleConsent `json:"googleConsent" yaml:"googleConsent"` } diff --git a/pkg/provider/conversionlinker/constants.go b/pkg/provider/conversionlinker/constants.go index 21c4978..479e124 100644 --- a/pkg/provider/conversionlinker/constants.go +++ b/pkg/provider/conversionlinker/constants.go @@ -1,6 +1,7 @@ package conversionlinker const ( - Tag = "cl" - Name = "Conversion Linker" + Tag = "cl" + Name = "Conversion Linker" + NameConversionLinkerTrigger = "Conversion Linker" ) diff --git a/pkg/provider/conversionlinker/server.go b/pkg/provider/conversionlinker/server.go index f3e583f..7c7e66a 100644 --- a/pkg/provider/conversionlinker/server.go +++ b/pkg/provider/conversionlinker/server.go @@ -3,11 +3,14 @@ package conversionlinker import ( "github.com/foomo/sesamy-cli/pkg/config" containertag "github.com/foomo/sesamy-cli/pkg/provider/conversionlinker/server/tag" + "github.com/foomo/sesamy-cli/pkg/provider/conversionlinker/server/trigger" + "github.com/foomo/sesamy-cli/pkg/provider/googleconsent" + googleconsentvariable "github.com/foomo/sesamy-cli/pkg/provider/googleconsent/server/variable" "github.com/foomo/sesamy-cli/pkg/tagmanager" - servertrigger "github.com/foomo/sesamy-cli/pkg/tagmanager/server/trigger" + "github.com/pkg/errors" ) -func Server(tm *tagmanager.TagManager, events config.ConversionLinker) error { +func Server(tm *tagmanager.TagManager, cfg config.ConversionLinker) error { { if folder, err := tm.UpsertFolder("Sesamy - " + Name); err != nil { return err @@ -16,7 +19,24 @@ func Server(tm *tagmanager.TagManager, events config.ConversionLinker) error { } } - if _, err := tm.UpsertTag(containertag.NewConversionLinker(Name, servertrigger.AllPages)); err != nil { + var eventTriggerOpts []trigger.ConversionLinkerEventOption + if cfg.GoogleConsent.Enabled { + if err := googleconsent.ServerEnsure(tm); err != nil { + return err + } + consentVariable, err := tm.LookupVariable(googleconsentvariable.GoogleConsentModeName(cfg.GoogleConsent.Mode)) + if err != nil { + return err + } + eventTriggerOpts = append(eventTriggerOpts, trigger.ConversionLinkerEventWithConsentMode(consentVariable)) + } + + eventTrigger, err := tm.UpsertTrigger(trigger.NewConversionLinkerEvent(NameConversionLinkerTrigger, eventTriggerOpts...)) + if err != nil { + return errors.Wrap(err, "failed to upsert event trigger: "+NameConversionLinkerTrigger) + } + + if _, err := tm.UpsertTag(containertag.NewConversionLinker(Name, eventTrigger)); err != nil { return err } diff --git a/pkg/provider/conversionlinker/server/trigger/conversionlinkerevent.go b/pkg/provider/conversionlinker/server/trigger/conversionlinkerevent.go new file mode 100644 index 0000000..e74fb38 --- /dev/null +++ b/pkg/provider/conversionlinker/server/trigger/conversionlinkerevent.go @@ -0,0 +1,54 @@ +package trigger + +import ( + "google.golang.org/api/tagmanager/v2" +) + +type ( + ConversionLinkerEventOptions struct { + consentMode *tagmanager.Variable + } + ConversionLinkerEventOption func(*ConversionLinkerEventOptions) +) + +func ConversionLinkerEventWithConsentMode(mode *tagmanager.Variable) ConversionLinkerEventOption { + return func(o *ConversionLinkerEventOptions) { + o.consentMode = mode + } +} + +func NewConversionLinkerEvent(name string, opts ...ConversionLinkerEventOption) *tagmanager.Trigger { + o := &ConversionLinkerEventOptions{} + for _, opt := range opts { + if opt != nil { + opt(o) + } + } + + var filter []*tagmanager.Condition + if o.consentMode != nil { + filter = append(filter, + &tagmanager.Condition{ + Parameter: []*tagmanager.Parameter{ + { + Key: "arg0", + Type: "template", + Value: "{{" + o.consentMode.Name + "}}", + }, + { + Key: "arg1", + Type: "template", + Value: "granted", + }, + }, + Type: "equals", + }, + ) + } + + return &tagmanager.Trigger{ + Type: "serverPageview", + Name: name, + Filter: filter, + } +} diff --git a/pkg/provider/emarsys/server/trigger/event.go b/pkg/provider/emarsys/server/trigger/emarsysevent.go similarity index 100% rename from pkg/provider/emarsys/server/trigger/event.go rename to pkg/provider/emarsys/server/trigger/emarsysevent.go diff --git a/sesamy.schema.json b/sesamy.schema.json index 7f3431e..c9f77a5 100644 --- a/sesamy.schema.json +++ b/sesamy.schema.json @@ -7,6 +7,84 @@ "properties": { "enabled": { "type": "boolean" + }, + "googleConsent": { + "type": "object", + "properties": { + "enabled": { + "type": "boolean" + }, + "mode": { + "type": "string" + } + } + } + } + }, + "cookiebot": { + "type": "object", + "properties": { + "AdvertiserConsentModeEnabled": { + "type": "boolean" + }, + "cdnRegion": { + "type": "string" + }, + "cookiebotId": { + "type": "string" + }, + "enabled": { + "type": "boolean" + }, + "templateName": { + "type": "string" + }, + "urlPassthrough": { + "type": "boolean" + } + } + }, + "emarsys": { + "type": "object", + "properties": { + "enabled": { + "type": "boolean" + }, + "googleConsent": { + "type": "object", + "properties": { + "enabled": { + "type": "boolean" + }, + "mode": { + "type": "string" + } + } + }, + "merchantId": { + "type": "string" + }, + "serverContainer": { + "type": "object", + "properties": { + "packages": { + "type": "array", + "items": { + "type": "object", + "properties": { + "path": { + "type": "string" + }, + "types": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + } + } } } }, @@ -19,6 +97,17 @@ "enabled": { "type": "boolean" }, + "googleConsent": { + "type": "object", + "properties": { + "enabled": { + "type": "boolean" + }, + "mode": { + "type": "string" + } + } + }, "pixelId": { "type": "string" }, @@ -87,6 +176,17 @@ }, "enabled": { "type": "boolean" + }, + "googleConsent": { + "type": "object", + "properties": { + "enabled": { + "type": "boolean" + }, + "mode": { + "type": "string" + } + } } } }, @@ -96,6 +196,31 @@ "enabled": { "type": "boolean" }, + "googleConsent": { + "type": "object", + "properties": { + "enabled": { + "type": "boolean" + }, + "mode": { + "type": "string" + } + } + }, + "googleGTag": { + "type": "object", + "properties": { + "ecommerceItems": { + "type": "boolean" + }, + "enabled": { + "type": "boolean" + }, + "priority": { + "type": "integer" + } + } + }, "serverContainer": { "type": "object", "properties": { @@ -290,6 +415,17 @@ "endpointUrl": { "type": "string" }, + "googleConsent": { + "type": "object", + "properties": { + "enabled": { + "type": "boolean" + }, + "mode": { + "type": "string" + } + } + }, "serverContainer": { "type": "object", "properties": { diff --git a/sesamy.yaml b/sesamy.yaml index 5a55ff6..4842990 100644 --- a/sesamy.yaml +++ b/sesamy.yaml @@ -127,6 +127,20 @@ googleTag: googleAnalytics: # Enable provider enabled: true + # Google GTag.js settings + googleGTag: + # Provision custom client + enabled: true + # Client priority + priority: 10 + # Patch ecommerce items + ecommerceItems: true + # Google Consent settings + googleConsent: + # Enable consent mode + enabled: true + # Consent mode name + mode: analytics_storage # Google Tag Manager web container settings webContainer: # Contemplate package config for generated events @@ -148,6 +162,12 @@ googleAnalytics: googleAds: # Enable provider enabled: true + # Google Consent settings + googleConsent: + # Enable consent mode + enabled: true + # Consent mode name + mode: ad_storage # Google Ads Conversion settings conversion: # Google Ads Conversion Tracking ID @@ -167,6 +187,12 @@ googleAds: conversionLinker: # Enable provider enabled: true + # Google Consent settings + googleConsent: + # Enable consent mode + enabled: true + # Consent mode name + mode: ad_storage # --- Umami settings umami: @@ -178,6 +204,12 @@ umami: websiteId: '' # Endpoint url of the umami api endpointUrl: https://umami.your-domain.com + # Google Consent settings + googleConsent: + # Enable consent mode + enabled: true + # Consent mode name + mode: analytics_storage # Google Tag Manager server container settings serverContainer: # Contemplate package config for generated events @@ -199,6 +231,12 @@ facebook: # Code used to verify that your server events are received correctly by Conversions API testEventToken: '' # Google Tag Manager server container settings + # Google Consent settings + googleConsent: + # Enable consent mode + enabled: true + # Consent mode name + mode: ad_storage serverContainer: # Contemplate package config for generated events packages: @@ -213,3 +251,41 @@ facebook: - BeginCheckout - GenerateLead - ViewItem + +# --- Emarsys +emarsys: + # Enable provider + enabled: true + # Emarsys merchant id + merchantId: '' + # Google Consent settings + googleConsent: + # Enable consent mode + enabled: true + # Consent mode name + mode: analytics_storage + # Google Tag Manager server container settings + serverContainer: + # Contemplate package config for generated events + packages: + - path: github.com/foomo/sesamy-go/pkg/event + types: + - Purchase + - ViewItem + - ViewItemList + +# --- Cookiebot CMP +cookiebot: + # Enable provider + enabled: true + # Name of the manually installed Cookiebot CMP tag template + # "https://tagmanager.google.com/gallery/#/owners/cybotcorp/templates/gtm-templates-cookiebot-cmp + templateName: Cookiebot CMP + # Cookiebot id + cookiebotId: '' + # CDN Region (eu, com) + cdnRegion: eu + # Enable URL passthrough + urlPassthrough: false + # Enable advertiser consent mode + AdvertiserConsentModeEnabled: false