Skip to content

Commit

Permalink
Merge pull request #45 from foomo/sesamy-cli-0.4.1
Browse files Browse the repository at this point in the history
Sesamy cli 0.4.1
  • Loading branch information
franklinkim authored Aug 27, 2024
2 parents 612f42e + 70906e4 commit 29900c5
Show file tree
Hide file tree
Showing 8 changed files with 302 additions and 8 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion pkg/config/conversionlinker.go
Original file line number Diff line number Diff line change
@@ -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"`
}
5 changes: 3 additions & 2 deletions pkg/provider/conversionlinker/constants.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package conversionlinker

const (
Tag = "cl"
Name = "Conversion Linker"
Tag = "cl"
Name = "Conversion Linker"
NameConversionLinkerTrigger = "Conversion Linker"
)
26 changes: 23 additions & 3 deletions pkg/provider/conversionlinker/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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,
}
}
136 changes: 136 additions & 0 deletions sesamy.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
}
}
}
}
}
},
Expand All @@ -19,6 +97,17 @@
"enabled": {
"type": "boolean"
},
"googleConsent": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean"
},
"mode": {
"type": "string"
}
}
},
"pixelId": {
"type": "string"
},
Expand Down Expand Up @@ -87,6 +176,17 @@
},
"enabled": {
"type": "boolean"
},
"googleConsent": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean"
},
"mode": {
"type": "string"
}
}
}
}
},
Expand All @@ -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": {
Expand Down Expand Up @@ -290,6 +415,17 @@
"endpointUrl": {
"type": "string"
},
"googleConsent": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean"
},
"mode": {
"type": "string"
}
}
},
"serverContainer": {
"type": "object",
"properties": {
Expand Down
Loading

0 comments on commit 29900c5

Please sign in to comment.