mirror of
https://github.com/foomo/sesamy-cli.git
synced 2026-08-13 05:00:23 +00:00
feat: add server event data
This commit is contained in:
@@ -2,8 +2,8 @@ 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/tagmanager"
|
||||
servertag "github.com/foomo/sesamy-cli/pkg/tagmanager/server/tag"
|
||||
servertrigger "github.com/foomo/sesamy-cli/pkg/tagmanager/server/trigger"
|
||||
)
|
||||
|
||||
@@ -16,10 +16,8 @@ func Server(tm *tagmanager.TagManager, events config.ConversionLinker) error {
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
if _, err := tm.UpsertTag(servertag.NewConversionLinker(Name, servertrigger.AllPages)); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := tm.UpsertTag(containertag.NewConversionLinker(Name, servertrigger.AllPages)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"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/foomo/sesamy-cli/pkg/tagmanager/server/variable"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@@ -32,6 +33,16 @@ func Server(l *slog.Logger, tm *tagmanager.TagManager, cfg config.GoogleAds) err
|
||||
return err
|
||||
}
|
||||
|
||||
value, err := tm.UpsertVariable(variable.NewEventData("value"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
currency, err := tm.UpsertVariable(variable.NewEventData("currency"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
{ // create tags
|
||||
eventParameters, err := googletag.CreateServerEventTriggers(tm, cfg.Conversion.ServerContainer)
|
||||
if err != nil {
|
||||
@@ -44,7 +55,7 @@ func Server(l *slog.Logger, tm *tagmanager.TagManager, cfg config.GoogleAds) err
|
||||
return errors.Wrap(err, "failed to lookup event trigger: "+event)
|
||||
}
|
||||
|
||||
if _, err := tm.UpsertTag(servertagx.NewGoogleAdsConversionTracking(event, conversionID, conversionLabel, eventTrigger)); err != nil {
|
||||
if _, err := tm.UpsertTag(servertagx.NewGoogleAdsConversionTracking(event, value, currency, conversionID, conversionLabel, eventTrigger)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ func GoogleAdsConversionTrackingName(v string) string {
|
||||
return "GAds Conversion - " + v
|
||||
}
|
||||
|
||||
func NewGoogleAdsConversionTracking(name string, conversionID, conversionLabel *tagmanager.Variable, triggers ...*tagmanager.Trigger) *tagmanager.Tag {
|
||||
func NewGoogleAdsConversionTracking(name string, value, currency, conversionID, conversionLabel *tagmanager.Variable, triggers ...*tagmanager.Trigger) *tagmanager.Tag {
|
||||
return &tagmanager.Tag{
|
||||
FiringTriggerId: utils.TriggerIDs(triggers),
|
||||
Name: GoogleAdsConversionTrackingName(name),
|
||||
@@ -33,7 +33,7 @@ func NewGoogleAdsConversionTracking(name string, conversionID, conversionLabel *
|
||||
{
|
||||
Key: "conversionValue",
|
||||
Type: "template",
|
||||
Value: "{{value}}",
|
||||
Value: "{{" + value.Name + "}}",
|
||||
},
|
||||
{
|
||||
Key: "conversionId",
|
||||
@@ -43,7 +43,7 @@ func NewGoogleAdsConversionTracking(name string, conversionID, conversionLabel *
|
||||
{
|
||||
Key: "currencyCode",
|
||||
Type: "template",
|
||||
Value: "{{currency}}",
|
||||
Value: "{{" + currency.Name + "}}",
|
||||
},
|
||||
{
|
||||
Key: "conversionLabel",
|
||||
|
||||
@@ -2,11 +2,11 @@ package googleanalytics
|
||||
|
||||
import (
|
||||
"github.com/foomo/sesamy-cli/pkg/config"
|
||||
containertag "github.com/foomo/sesamy-cli/pkg/provider/googleanalytics/server/tag"
|
||||
"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"
|
||||
serverclient "github.com/foomo/sesamy-cli/pkg/tagmanager/server/client"
|
||||
servertag "github.com/foomo/sesamy-cli/pkg/tagmanager/server/tag"
|
||||
servertrigger "github.com/foomo/sesamy-cli/pkg/tagmanager/server/trigger"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
@@ -54,7 +54,7 @@ func Server(tm *tagmanager.TagManager, cfg config.GoogleAnalytics, redactVisitor
|
||||
return errors.Wrap(err, "failed to lookup event trigger: "+event)
|
||||
}
|
||||
|
||||
if _, err := tm.UpsertTag(servertag.NewGoogleAnalyticsGA4(event, redactVisitorIP, eventTrigger)); err != nil {
|
||||
if _, err := tm.UpsertTag(containertag.NewGoogleAnalyticsGA4(event, redactVisitorIP, eventTrigger)); err != nil {
|
||||
return errors.Wrap(err, "failed to upsert google analytics ga4 tag: "+event)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@ package googleanalytics
|
||||
|
||||
import (
|
||||
"github.com/foomo/sesamy-cli/pkg/config"
|
||||
containertag "github.com/foomo/sesamy-cli/pkg/provider/googleanalytics/web/tag"
|
||||
"github.com/foomo/sesamy-cli/pkg/provider/googletag"
|
||||
commonvariable "github.com/foomo/sesamy-cli/pkg/provider/googletag/web/variable"
|
||||
"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"
|
||||
webtag "github.com/foomo/sesamy-cli/pkg/tagmanager/web/tag"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@@ -41,7 +41,7 @@ func Web(tm *tagmanager.TagManager, cfg config.GoogleAnalytics) error {
|
||||
return errors.Wrap(err, "failed to lookup google tag event setting: "+event)
|
||||
}
|
||||
|
||||
if _, err := tm.UpsertTag(webtag.NewGoogleAnalyticsGA4Event(event, tagID, eventSettings, eventTrigger)); err != nil {
|
||||
if _, err := tm.UpsertTag(containertag.NewGoogleAnalyticsGA4Event(event, tagID, eventSettings, eventTrigger)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package client
|
||||
package tag
|
||||
|
||||
import (
|
||||
"google.golang.org/api/tagmanager/v2"
|
||||
@@ -3,10 +3,12 @@ package googletag
|
||||
import (
|
||||
"github.com/foomo/gocontemplate/pkg/contemplate"
|
||||
"github.com/foomo/sesamy-cli/pkg/config"
|
||||
webtag "github.com/foomo/sesamy-cli/pkg/provider/googletag/web/tag"
|
||||
containervariable "github.com/foomo/sesamy-cli/pkg/provider/googletag/web/variable"
|
||||
"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"
|
||||
webtag "github.com/foomo/sesamy-cli/pkg/tagmanager/web/tag"
|
||||
"github.com/foomo/sesamy-cli/pkg/tagmanager/web/variable"
|
||||
"github.com/foomo/sesamy-cli/pkg/utils"
|
||||
api "google.golang.org/api/tagmanager/v2"
|
||||
)
|
||||
@@ -36,7 +38,7 @@ func Web(tm *tagmanager.TagManager, cfg config.GoogleTag) error {
|
||||
return err
|
||||
}
|
||||
|
||||
settingsVariable, err := tm.UpsertVariable(commonvariable.NewGoogleTagSettings(NameGoogleTagSettings, settings))
|
||||
settingsVariable, err := tm.UpsertVariable(containervariable.NewGoogleTagConfigurationSettings(NameGoogleTagSettings, settings))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -65,12 +67,12 @@ func CreateWebEventTriggers(tm *tagmanager.TagManager, cfg contemplate.Config) (
|
||||
|
||||
settings := make(map[string]*api.Variable, len(parameters))
|
||||
for _, parameter := range parameters {
|
||||
if settings[parameter], err = tm.UpsertVariable(commonvariable.NewGoogleTagEventModel(parameter)); err != nil {
|
||||
if settings[parameter], err = tm.UpsertVariable(variable.NewDataLayerVariable(parameter)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := tm.UpsertVariable(commonvariable.NewGoogleTagEventSettings(event, settings)); err != nil {
|
||||
if _, err := tm.UpsertVariable(containervariable.NewGoogleTagEventSettings(event, settings)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import (
|
||||
"google.golang.org/api/tagmanager/v2"
|
||||
)
|
||||
|
||||
func NewGoogleTagSettings(name string, variables map[string]string) *tagmanager.Variable {
|
||||
func NewGoogleTagConfigurationSettings(name string, variables map[string]string) *tagmanager.Variable {
|
||||
parameters := make([]string, 0, len(variables))
|
||||
for k := range variables {
|
||||
parameters = append(parameters, k)
|
||||
@@ -0,0 +1,14 @@
|
||||
package variable
|
||||
|
||||
import (
|
||||
"github.com/foomo/sesamy-cli/pkg/tagmanager/web/variable"
|
||||
"google.golang.org/api/tagmanager/v2"
|
||||
)
|
||||
|
||||
func GoogleTagEventModelName(v string) string {
|
||||
return variable.DataLayerVariableName("eventModel." + v)
|
||||
}
|
||||
|
||||
func NewGoogleTagEventModel(v string) *tagmanager.Variable {
|
||||
return variable.NewDataLayerVariable("eventModel." + v)
|
||||
}
|
||||
@@ -3,10 +3,10 @@ package umami
|
||||
import (
|
||||
"github.com/foomo/sesamy-cli/pkg/config"
|
||||
"github.com/foomo/sesamy-cli/pkg/provider/googletag"
|
||||
servertemplate "github.com/foomo/sesamy-cli/pkg/provider/umami/server/template"
|
||||
containertag "github.com/foomo/sesamy-cli/pkg/provider/umami/server/tag"
|
||||
containertemplate "github.com/foomo/sesamy-cli/pkg/provider/umami/server/template"
|
||||
"github.com/foomo/sesamy-cli/pkg/tagmanager"
|
||||
commontrigger "github.com/foomo/sesamy-cli/pkg/tagmanager/common/trigger"
|
||||
servertag "github.com/foomo/sesamy-cli/pkg/tagmanager/server/tag"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@@ -19,7 +19,7 @@ func Server(tm *tagmanager.TagManager, cfg config.Umami) error {
|
||||
}
|
||||
}
|
||||
|
||||
template, err := tm.UpsertCustomTemplate(servertemplate.NewUmami(Name))
|
||||
template, err := tm.UpsertCustomTemplate(containertemplate.NewUmami(Name))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -36,7 +36,7 @@ func Server(tm *tagmanager.TagManager, cfg config.Umami) error {
|
||||
return errors.Wrap(err, "failed to lookup event trigger: "+event)
|
||||
}
|
||||
|
||||
if _, err := tm.UpsertTag(servertag.NewUmami(event, cfg, template, eventTrigger)); err != nil {
|
||||
if _, err := tm.UpsertTag(containertag.NewUmami(event, cfg, template, eventTrigger)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package variable
|
||||
|
||||
import (
|
||||
"google.golang.org/api/tagmanager/v2"
|
||||
)
|
||||
|
||||
func EventDataName(v string) string {
|
||||
return "event." + v
|
||||
}
|
||||
|
||||
func NewEventData(name string) *tagmanager.Variable {
|
||||
return &tagmanager.Variable{
|
||||
Name: EventDataName(name),
|
||||
Parameter: []*tagmanager.Parameter{
|
||||
{
|
||||
Key: "setDefaultValue",
|
||||
Type: "boolean",
|
||||
Value: "false",
|
||||
},
|
||||
{
|
||||
Key: "keyPath",
|
||||
Type: "template",
|
||||
Value: name,
|
||||
},
|
||||
},
|
||||
Type: "ed",
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -4,13 +4,13 @@ import (
|
||||
"google.golang.org/api/tagmanager/v2"
|
||||
)
|
||||
|
||||
func GoogleTagEventModelName(v string) string {
|
||||
return "dlv.eventModel." + v
|
||||
func DataLayerVariableName(v string) string {
|
||||
return "dlv." + v
|
||||
}
|
||||
|
||||
func NewGoogleTagEventModel(name string) *tagmanager.Variable {
|
||||
func NewDataLayerVariable(name string) *tagmanager.Variable {
|
||||
return &tagmanager.Variable{
|
||||
Name: GoogleTagEventModelName(name),
|
||||
Name: DataLayerVariableName(name),
|
||||
Parameter: []*tagmanager.Parameter{
|
||||
{
|
||||
Key: "dataLayerVersion",
|
||||
@@ -46,6 +46,15 @@ func TestNewClient_Server(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
{ // --- Variables ---
|
||||
t.Run("list variables", func(t *testing.T) {
|
||||
cmd := c.Service().Accounts.Containers.Workspaces.Variables.List(c.WorkspacePath())
|
||||
if r, err := cmd.Do(); assert.NoError(t, err) {
|
||||
dump(t, r)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
{ // --- Built-In Variables ---
|
||||
t.Run("list built-in variables", func(t *testing.T) {
|
||||
cmd := c.Service().Accounts.Containers.Workspaces.BuiltInVariables.List(c.WorkspacePath())
|
||||
@@ -53,7 +62,7 @@ func TestNewClient_Server(t *testing.T) {
|
||||
dump(t, r)
|
||||
}
|
||||
})
|
||||
t.Run("list built-in variables", func(t *testing.T) {
|
||||
t.Run("create built-in variables", func(t *testing.T) {
|
||||
cmd := c.Service().Accounts.Containers.Workspaces.BuiltInVariables.Create(c.WorkspacePath()).Type()
|
||||
if r, err := cmd.Do(); assert.NoError(t, err) {
|
||||
dump(t, r)
|
||||
|
||||
Reference in New Issue
Block a user