feat: add debug_mode transformation

This commit is contained in:
Kevin Franklin Kim 2025-02-12 11:42:35 +01:00
parent c67e4d4898
commit 036c32ee0c
No known key found for this signature in database
2 changed files with 33 additions and 21 deletions

View File

@ -17,6 +17,7 @@ import (
servervariable "github.com/foomo/sesamy-cli/pkg/tagmanager/server/variable"
"github.com/foomo/sesamy-cli/pkg/utils"
"github.com/pkg/errors"
api "google.golang.org/api/tagmanager/v2"
)
func Server(tm *tagmanager.TagManager, cfg config.GoogleAnalytics, redactVisitorIP, enableGeoResolution bool) error {
@ -69,7 +70,15 @@ func Server(tm *tagmanager.TagManager, cfg config.GoogleAnalytics, redactVisitor
return err
}
_, err = tm.UpsertTransformation(servertransformation.NewMPv2UserData(NameMPv2UserDataTransformation, userDataVariable, client))
debugModeVariable, err := tm.UpsertVariable(servervariable.NewMPv2Data("debug_mode", userDataTemplate))
if err != nil {
return err
}
_, err = tm.UpsertTransformation(servertransformation.NewMPv2UserData(NameMPv2UserDataTransformation, map[string]*api.Variable{
"user_data": userDataVariable,
"debug_mode": debugModeVariable,
}, client))
if err != nil {
return err
}

View File

@ -4,7 +4,27 @@ import (
"google.golang.org/api/tagmanager/v2"
)
func NewMPv2UserData(name string, variable *tagmanager.Variable, client *tagmanager.Client) *tagmanager.Transformation {
func NewMPv2UserData(name string, variables map[string]*tagmanager.Variable, client *tagmanager.Client) *tagmanager.Transformation {
var list []*tagmanager.Parameter
for k, v := range variables {
list = append(list, &tagmanager.Parameter{
IsWeakReference: false,
Map: []*tagmanager.Parameter{
{
Key: "paramName",
Type: "template",
Value: k,
},
{
Key: "paramValue",
Type: "template",
Value: "{{" + v.Name + "}}",
},
},
Type: "map",
})
}
return &tagmanager.Transformation{
Name: name,
Parameter: []*tagmanager.Parameter{
@ -23,25 +43,8 @@ func NewMPv2UserData(name string, variable *tagmanager.Variable, client *tagmana
Type: "template",
},
{
Key: "augmentEventTable",
List: []*tagmanager.Parameter{
{
IsWeakReference: false,
Map: []*tagmanager.Parameter{
{
Key: "paramName",
Type: "template",
Value: "user_data",
},
{
Key: "paramValue",
Type: "template",
Value: "{{" + variable.Name + "}}",
},
},
Type: "map",
},
},
Key: "augmentEventTable",
List: list,
Type: "list",
},
{