-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from foomo/sesamy-cli-0.3.1
feat: add emarsys support
- Loading branch information
Showing
36 changed files
with
1,966 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/foomo/gocontemplate/pkg/contemplate" | ||
) | ||
|
||
type Emarsys struct { | ||
Enabled bool `json:"enabled" yaml:"enabled"` | ||
MerchantID string `json:"merchantId" yaml:"merchantId"` | ||
NewPageViewEvent string `json:"newPageViewEvent" yaml:"newPageViewEvent"` | ||
WebContainer contemplate.Config `json:"webContainer" yaml:"webContainer"` | ||
ServerContainer contemplate.Config `json:"serverContainer" yaml:"serverContainer"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package config | ||
|
||
type GoogleGTag struct { | ||
Enabled bool `json:"enabled" yaml:"enabled"` | ||
Priority int64 `json:"priority" yaml:"priority"` | ||
EcommerceItems bool `json:"ecommerceItems" yaml:"ecommerceItems"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
package config | ||
|
||
type GoogleTag struct { | ||
TagID string `json:"tagId" yaml:"tagId"` | ||
DebugMode bool `json:"debugMode" yaml:"debugMode"` | ||
SendPageView bool `json:"sendPageView" yaml:"sendPageView"` | ||
// WebContainer contemplate.Config `json:"webContainer" yaml:"webContainer"` | ||
// ServerContainer contemplate.Config `json:"serverContainer" yaml:"serverContainer"` | ||
TypeScript TypeScript `json:"typeScript" yaml:"typeScript"` | ||
TagID string `json:"tagId" yaml:"tagId"` | ||
DebugMode bool `json:"debugMode" yaml:"debugMode"` | ||
SendPageView bool `json:"sendPageView" yaml:"sendPageView"` | ||
TypeScript TypeScript `json:"typeScript" yaml:"typeScript"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package emarsys | ||
|
||
const ( | ||
Tag = "emarsys" | ||
Name = "Emarsys" | ||
NameMerchantIDConstant = "Emarsys Merchant ID" | ||
NameWebEmarsysInitalizationTag = "Emarsys Initialization" | ||
NameWebEmarsysInitalizationTagTemplate = "Emarsys Initialization" | ||
NameServerEmarsysClient = "Emarsys Initialization" | ||
NameServerEmarsysWebExtendTagTemplate = "Emarsys Web Extend" | ||
NameServerEmarsysInitalizationClientTemplate = "Emarsys Initialization" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package emarsys | ||
|
||
import ( | ||
"log/slog" | ||
|
||
"github.com/foomo/sesamy-cli/pkg/config" | ||
serverclientx "github.com/foomo/sesamy-cli/pkg/provider/emarsys/server/client" | ||
servertagx "github.com/foomo/sesamy-cli/pkg/provider/emarsys/server/tag" | ||
"github.com/foomo/sesamy-cli/pkg/provider/emarsys/server/template" | ||
"github.com/foomo/sesamy-cli/pkg/provider/googletag" | ||
"github.com/foomo/sesamy-cli/pkg/tagmanager" | ||
commontrigger "github.com/foomo/sesamy-cli/pkg/tagmanager/common/trigger" | ||
commonvariable "github.com/foomo/sesamy-cli/pkg/tagmanager/common/variable" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func Server(l *slog.Logger, tm *tagmanager.TagManager, cfg config.Emarsys) error { | ||
{ // create folder | ||
if folder, err := tm.UpsertFolder("Sesamy - " + Name); err != nil { | ||
return err | ||
} else { | ||
tm.SetFolderName(folder.Name) | ||
} | ||
} | ||
|
||
{ // conversion | ||
merchantID, err := tm.UpsertVariable(commonvariable.NewConstant(NameMerchantIDConstant, cfg.MerchantID)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
tagTemplate, err := tm.UpsertCustomTemplate(template.NewEmarsysWebExtendTag(NameServerEmarsysWebExtendTagTemplate)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
clientTemplate, err := tm.UpsertCustomTemplate(template.NewEmarsysInitializationClient(NameServerEmarsysInitalizationClientTemplate)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = tm.UpsertClient(serverclientx.NewEmarsys(NameServerEmarsysClient, cfg, clientTemplate)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
{ // create tags | ||
eventParameters, err := googletag.CreateServerEventTriggers(tm, cfg.ServerContainer) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for event := range eventParameters { | ||
eventTrigger, err := tm.LookupTrigger(commontrigger.EventName(event)) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to lookup event trigger: "+event) | ||
} | ||
|
||
if _, err := tm.UpsertTag(servertagx.NewEmarsys(event, cfg.NewPageViewEvent == eventTrigger.Name, merchantID, tagTemplate, eventTrigger)); err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package client | ||
|
||
import ( | ||
"github.com/foomo/sesamy-cli/pkg/config" | ||
"github.com/foomo/sesamy-cli/pkg/utils" | ||
"google.golang.org/api/tagmanager/v2" | ||
) | ||
|
||
func NewEmarsys(name string, cfg config.Emarsys, template *tagmanager.CustomTemplate) *tagmanager.Client { | ||
return &tagmanager.Client{ | ||
Name: name, | ||
Parameter: []*tagmanager.Parameter{ | ||
{ | ||
Key: "merchantId", | ||
Type: "template", | ||
Value: cfg.MerchantID, | ||
}, | ||
}, | ||
Type: utils.TemplateType(template), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package tag | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/foomo/sesamy-cli/pkg/utils" | ||
"google.golang.org/api/tagmanager/v2" | ||
) | ||
|
||
func EmarsysName(v string) string { | ||
return "Emarsys - " + v | ||
} | ||
|
||
func NewEmarsys(name string, isNewPageView bool, merchantID *tagmanager.Variable, template *tagmanager.CustomTemplate, triggers ...*tagmanager.Trigger) *tagmanager.Tag { | ||
return &tagmanager.Tag{ | ||
FiringTriggerId: utils.TriggerIDs(triggers), | ||
Name: EmarsysName(name), | ||
TagFiringOption: "oncePerEvent", | ||
Parameter: []*tagmanager.Parameter{ | ||
{ | ||
Key: "adStorageConsent", | ||
Type: "template", | ||
Value: "optional", | ||
}, | ||
{ | ||
Key: "isNewPageView", | ||
Type: "boolean", | ||
Value: strconv.FormatBool(isNewPageView), | ||
}, | ||
{ | ||
Key: "merchantId", | ||
Type: "template", | ||
Value: "{{" + merchantID.Name + "}}", | ||
}, | ||
{ | ||
Key: "isTestMode", | ||
Type: "boolean", | ||
Value: "false", | ||
}, | ||
{ | ||
Key: "isDebugMode", | ||
Type: "boolean", | ||
Value: "false", | ||
}, | ||
}, | ||
Type: utils.TemplateType(template), | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
pkg/provider/emarsys/server/template/emarsysinitalizationclient.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package template | ||
|
||
import ( | ||
"fmt" | ||
|
||
"google.golang.org/api/tagmanager/v2" | ||
) | ||
|
||
func NewEmarsysInitializationClient(name string) *tagmanager.CustomTemplate { | ||
return &tagmanager.CustomTemplate{ | ||
Name: name, | ||
TemplateData: fmt.Sprintf(EmarsysInitializationClientData, name), | ||
} | ||
} |
Oops, something went wrong.