Skip to content

Commit

Permalink
feat: add send_page_view option
Browse files Browse the repository at this point in the history
  • Loading branch information
franklinkim committed Apr 29, 2024
1 parent 58d345b commit 8e4d93c
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 34 deletions.
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions cmd/tagmanagerweb.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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
}
}
Expand Down Expand Up @@ -120,6 +124,8 @@ var tagmanagerWebCmd = &cobra.Command{
},
}

var filter string

func init() {
tagmanagerCmd.AddCommand(tagmanagerWebCmd)

Expand All @@ -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")
}
21 changes: 0 additions & 21 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
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"
Expand Down
12 changes: 6 additions & 6 deletions pkg/config/google.go
Original file line number Diff line number Diff line change
@@ -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"`
}
6 changes: 6 additions & 0 deletions pkg/config/gt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package config

type GT struct {
ServerContainerURL string `yaml:"server_container_url"`
EnablePageViews bool `yaml:"enable_page_views"`
}
37 changes: 35 additions & 2 deletions pkg/tagmanager/tag/googletag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
}

0 comments on commit 8e4d93c

Please sign in to comment.