From 8e4d93c264d4d150b7770a76da71e720d730fb26 Mon Sep 17 00:00:00 2001 From: Kevin Franklin Kim Date: Mon, 29 Apr 2024 10:59:32 +0200 Subject: [PATCH] feat: add send_page_view option --- Makefile | 4 +--- cmd/tagmanagerweb.go | 11 ++++++++-- main.go | 21 ------------------- pkg/config/google.go | 12 +++++------ pkg/config/gt.go | 6 ++++++ pkg/tagmanager/tag/googletag.go | 37 +++++++++++++++++++++++++++++++-- 6 files changed, 57 insertions(+), 34 deletions(-) create mode 100644 pkg/config/gt.go diff --git a/Makefile b/Makefile index f592787..57ff798 100644 --- a/Makefile +++ b/Makefile @@ -18,10 +18,8 @@ ## === Tasks === -## === Tasks === - .PHONY: doc -## Run tests +## Open go docs doc: @open "http://localhost:6060/pkg/github.com/foomo/sesamy-cli/" @godoc -http=localhost:6060 -play diff --git a/cmd/tagmanagerweb.go b/cmd/tagmanagerweb.go index 618a2f0..0c89284 100644 --- a/cmd/tagmanagerweb.go +++ b/cmd/tagmanagerweb.go @@ -1,6 +1,8 @@ package cmd import ( + "strconv" + "github.com/foomo/sesamy-cli/internal" "github.com/foomo/sesamy-cli/pkg/tagmanager" client "github.com/foomo/sesamy-cli/pkg/tagmanager/tag" @@ -60,7 +62,7 @@ var tagmanagerWebCmd = &cobra.Command{ var serverContainerURL *tagmanager2.Variable { name := p.Variables.ConstantName("Server Container URL") - if serverContainerURL, err = c.UpsertVariable(variable.NewConstant(name, cfg.Google.ServerContainerURL)); err != nil { + if serverContainerURL, err = c.UpsertVariable(variable.NewConstant(name, cfg.Google.GT.ServerContainerURL)); err != nil { return err } } @@ -77,7 +79,9 @@ var tagmanagerWebCmd = &cobra.Command{ { name := p.Tags.GoogleTagName("Google Tag") - if _, err = c.UpsertTag(client.NewGoogleTag(name, ga4MeasurementID, googleTagSettings)); err != nil { + if _, err = c.UpsertTag(client.NewGoogleTag(name, ga4MeasurementID, googleTagSettings, map[string]string{ + "enable_page_views": strconv.FormatBool(cfg.Google.GT.EnablePageViews), + })); err != nil { return err } } @@ -120,6 +124,8 @@ var tagmanagerWebCmd = &cobra.Command{ }, } +var filter string + func init() { tagmanagerCmd.AddCommand(tagmanagerWebCmd) @@ -132,4 +138,5 @@ func init() { // Cobra supports local flags which will only run when this command // is called directly, e.g.: // tagmanagerWebCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") + tagmanagerWebCmd.Flags().StringVar(&filter, "filter", "", "Filter tag manager") } diff --git a/main.go b/main.go index d3260ce..a50f920 100644 --- a/main.go +++ b/main.go @@ -1,24 +1,3 @@ -/* -Copyright © 2024 NAME HERE - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ package main import "github.com/foomo/sesamy-cli/cmd" diff --git a/pkg/config/google.go b/pkg/config/google.go index f268734..b735afb 100644 --- a/pkg/config/google.go +++ b/pkg/config/google.go @@ -1,10 +1,10 @@ package config type Google struct { - GA4 GA4 `yaml:"ga4"` - GTM GTM `yaml:"gtm"` - RequestQuota int `yaml:"request_quota"` - CredentialsFile string `yaml:"credentials_file"` - CredentialsJSON string `yaml:"credentials_json"` - ServerContainerURL string `yaml:"server_container_url"` + GT GT `yaml:"gt"` + GA4 GA4 `yaml:"ga4"` + GTM GTM `yaml:"gtm"` + RequestQuota int `yaml:"request_quota"` + CredentialsFile string `yaml:"credentials_file"` + CredentialsJSON string `yaml:"credentials_json"` } diff --git a/pkg/config/gt.go b/pkg/config/gt.go new file mode 100644 index 0000000..b12fc4b --- /dev/null +++ b/pkg/config/gt.go @@ -0,0 +1,6 @@ +package config + +type GT struct { + ServerContainerURL string `yaml:"server_container_url"` + EnablePageViews bool `yaml:"enable_page_views"` +} diff --git a/pkg/tagmanager/tag/googletag.go b/pkg/tagmanager/tag/googletag.go index 3b3214f..d87226d 100644 --- a/pkg/tagmanager/tag/googletag.go +++ b/pkg/tagmanager/tag/googletag.go @@ -4,8 +4,8 @@ import ( "google.golang.org/api/tagmanager/v2" ) -func NewGoogleTag(name string, measurementID *tagmanager.Variable, configSettings *tagmanager.Variable) *tagmanager.Tag { - return &tagmanager.Tag{ +func NewGoogleTag(name string, measurementID *tagmanager.Variable, configSettings *tagmanager.Variable, extraConfigSettings map[string]string) *tagmanager.Tag { + ret := &tagmanager.Tag{ FiringTriggerId: []string{"2147479573"}, // TODO Name: name, Parameter: []*tagmanager.Parameter{ @@ -19,7 +19,40 @@ func NewGoogleTag(name string, measurementID *tagmanager.Variable, configSetting Type: "template", Value: "{{" + configSettings.Name + "}}", }, + { + Key: "configSettingsTable", + Type: "template", + Value: "{{" + configSettings.Name + "}}", + }, }, Type: "googtag", } + + if len(extraConfigSettings) > 0 { + var list []*tagmanager.Parameter + for k, v := range extraConfigSettings { + list = append(list, &tagmanager.Parameter{ + Type: "map", + Map: []*tagmanager.Parameter{ + { + Key: "parameter", + Type: "template", + Value: k, + }, + { + Key: "parameterValue", + Type: "template", + Value: v, + }, + }, + }) + } + ret.Parameter = append(ret.Parameter, &tagmanager.Parameter{ + Key: "configSettingsTable", + Type: "list", + List: list, + }) + } + + return ret }