mirror of
https://github.com/foomo/sesamy-cli.git
synced 2025-10-16 12:35:36 +00:00
feat: add web container variables
This commit is contained in:
parent
f742f71a0b
commit
7a4829e3b5
@ -7,6 +7,7 @@ import (
|
||||
emarsysprovider "github.com/foomo/sesamy-cli/pkg/provider/emarsys"
|
||||
googleanaylticsprovider "github.com/foomo/sesamy-cli/pkg/provider/googleanalytics"
|
||||
googletagprovider "github.com/foomo/sesamy-cli/pkg/provider/googletag"
|
||||
googletagmanagerprovider "github.com/foomo/sesamy-cli/pkg/provider/googletagmanager"
|
||||
hotjarprovider "github.com/foomo/sesamy-cli/pkg/provider/hotjar"
|
||||
"github.com/foomo/sesamy-cli/pkg/tagmanager"
|
||||
"github.com/pkg/errors"
|
||||
@ -53,6 +54,12 @@ func NewWeb(root *cobra.Command) {
|
||||
}
|
||||
}
|
||||
|
||||
if pkgcmd.Tag(googletagmanagerprovider.Tag, tags) {
|
||||
if err := googletagmanagerprovider.Web(tm, cfg.GoogleTagManager); err != nil {
|
||||
return errors.Wrap(err, "failed to provision google tag manager")
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.GoogleAnalytics.Enabled && pkgcmd.Tag(googleanaylticsprovider.Tag, tags) {
|
||||
l.Info("🅿️ Running provider", "name", googleanaylticsprovider.Name, "tag", googleanaylticsprovider.Tag)
|
||||
if err := googleanaylticsprovider.Web(tm, cfg.GoogleAnalytics); err != nil {
|
||||
|
||||
@ -7,6 +7,8 @@ type GoogleTagManager struct {
|
||||
WebContainer GoogleTagManagerContainer `json:"webContainer" yaml:"webContainer"`
|
||||
// Google Tag Manager server container settings
|
||||
ServerContainer GoogleTagManagerContainer `json:"serverContainer" yaml:"serverContainer"`
|
||||
// Google Tag Manager web container variables
|
||||
WebContaienrVariables GoogleTagManagerWebContainerVariables `json:"webContainerVariables" yaml:"webContainerVariables"`
|
||||
// Google Tag Manager server container variables
|
||||
ServerContaienrVariables GoogleTagManagerServerContainerVariables `json:"serverContainerVariables" yaml:"serverContainerVariables"`
|
||||
}
|
||||
|
||||
8
pkg/config/googletagmanagerwebcontainervariables.go
Normal file
8
pkg/config/googletagmanagerwebcontainervariables.go
Normal file
@ -0,0 +1,8 @@
|
||||
package config
|
||||
|
||||
type GoogleTagManagerWebContainerVariables struct {
|
||||
// List of event data variables
|
||||
DataLayer []string `json:"dataLayer" yaml:"dataLayer"`
|
||||
// Map of lookup table variables
|
||||
LookupTables map[string]LookupTable `json:"lookupTables" yaml:"lookupTables"`
|
||||
}
|
||||
@ -32,7 +32,7 @@ func Web(tm *tagmanager.TagManager, cfg config.GoogleTag) error {
|
||||
|
||||
eventSettings := map[string]*api.Variable{}
|
||||
for k, v := range cfg.DataLayerVariables {
|
||||
dlv, err := tm.UpsertVariable(variable.NewDataLayerVariable(v))
|
||||
dlv, err := tm.UpsertVariable(variable.NewDataLayer(v))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -91,7 +91,7 @@ func CreateWebDatalayerVariables(tm *tagmanager.TagManager, parameters map[strin
|
||||
var err error
|
||||
variables := make(map[string]*api.Variable, len(parameters))
|
||||
for parameterName, parameterValue := range parameters {
|
||||
if variables[parameterName], err = tm.UpsertVariable(variable.NewDataLayerVariable(parameterValue)); err != nil {
|
||||
if variables[parameterName], err = tm.UpsertVariable(variable.NewDataLayer(parameterValue)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,7 +5,8 @@ import (
|
||||
"github.com/foomo/sesamy-cli/pkg/provider/googletagmanager/server/client"
|
||||
"github.com/foomo/sesamy-cli/pkg/provider/googletagmanager/server/variable"
|
||||
"github.com/foomo/sesamy-cli/pkg/tagmanager"
|
||||
variable2 "github.com/foomo/sesamy-cli/pkg/tagmanager/server/variable"
|
||||
commonvariable "github.com/foomo/sesamy-cli/pkg/tagmanager/common/variable"
|
||||
servervariable "github.com/foomo/sesamy-cli/pkg/tagmanager/server/variable"
|
||||
)
|
||||
|
||||
func Server(tm *tagmanager.TagManager, cfg config.GoogleTagManager, enableGeoResolution bool) error {
|
||||
@ -36,12 +37,12 @@ func Server(tm *tagmanager.TagManager, cfg config.GoogleTagManager, enableGeoRes
|
||||
|
||||
{ // create variables
|
||||
for _, value := range cfg.ServerContaienrVariables.EventData {
|
||||
if _, err := tm.UpsertVariable(variable2.NewEventData(value)); err != nil {
|
||||
if _, err := tm.UpsertVariable(servervariable.NewEventData(value)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for key, value := range cfg.ServerContaienrVariables.LookupTables {
|
||||
if _, err := tm.UpsertVariable(variable2.NewLookupTable(key, value)); err != nil {
|
||||
if _, err := tm.UpsertVariable(commonvariable.NewLookupTable(key, value)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
33
pkg/provider/googletagmanager/web.go
Normal file
33
pkg/provider/googletagmanager/web.go
Normal file
@ -0,0 +1,33 @@
|
||||
package googletagmanager
|
||||
|
||||
import (
|
||||
"github.com/foomo/sesamy-cli/pkg/config"
|
||||
"github.com/foomo/sesamy-cli/pkg/tagmanager"
|
||||
commonvariable "github.com/foomo/sesamy-cli/pkg/tagmanager/common/variable"
|
||||
"github.com/foomo/sesamy-cli/pkg/tagmanager/web/variable"
|
||||
)
|
||||
|
||||
func Web(tm *tagmanager.TagManager, cfg config.GoogleTagManager) error {
|
||||
{ // create folder
|
||||
if folder, err := tm.UpsertFolder("Sesamy - " + Name); err != nil {
|
||||
return err
|
||||
} else {
|
||||
tm.SetFolderName(folder.Name)
|
||||
}
|
||||
}
|
||||
|
||||
{ // create variables
|
||||
for _, value := range cfg.WebContaienrVariables.DataLayer {
|
||||
if _, err := tm.UpsertVariable(variable.NewDataLayer(value)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for key, value := range cfg.WebContaienrVariables.LookupTables {
|
||||
if _, err := tm.UpsertVariable(commonvariable.NewLookupTable(key, value)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -4,13 +4,13 @@ import (
|
||||
"google.golang.org/api/tagmanager/v2"
|
||||
)
|
||||
|
||||
func DataLayerVariableName(v string) string {
|
||||
func DataLayerName(v string) string {
|
||||
return "dlv." + v
|
||||
}
|
||||
|
||||
func NewDataLayerVariable(name string) *tagmanager.Variable {
|
||||
func NewDataLayer(name string) *tagmanager.Variable {
|
||||
return &tagmanager.Variable{
|
||||
Name: DataLayerVariableName(name),
|
||||
Name: DataLayerName(name),
|
||||
Parameter: []*tagmanager.Parameter{
|
||||
{
|
||||
Key: "dataLayerVersion",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user