mirror of
https://github.com/foomo/sesamy-cli.git
synced 2025-10-16 12:35:36 +00:00
feat: add send_page_view option
This commit is contained in:
parent
58d345bb61
commit
8e4d93c264
4
Makefile
4
Makefile
@ -18,10 +18,8 @@
|
|||||||
|
|
||||||
## === Tasks ===
|
## === Tasks ===
|
||||||
|
|
||||||
## === Tasks ===
|
|
||||||
|
|
||||||
.PHONY: doc
|
.PHONY: doc
|
||||||
## Run tests
|
## Open go docs
|
||||||
doc:
|
doc:
|
||||||
@open "http://localhost:6060/pkg/github.com/foomo/sesamy-cli/"
|
@open "http://localhost:6060/pkg/github.com/foomo/sesamy-cli/"
|
||||||
@godoc -http=localhost:6060 -play
|
@godoc -http=localhost:6060 -play
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/foomo/sesamy-cli/internal"
|
"github.com/foomo/sesamy-cli/internal"
|
||||||
"github.com/foomo/sesamy-cli/pkg/tagmanager"
|
"github.com/foomo/sesamy-cli/pkg/tagmanager"
|
||||||
client "github.com/foomo/sesamy-cli/pkg/tagmanager/tag"
|
client "github.com/foomo/sesamy-cli/pkg/tagmanager/tag"
|
||||||
@ -60,7 +62,7 @@ var tagmanagerWebCmd = &cobra.Command{
|
|||||||
var serverContainerURL *tagmanager2.Variable
|
var serverContainerURL *tagmanager2.Variable
|
||||||
{
|
{
|
||||||
name := p.Variables.ConstantName("Server Container URL")
|
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
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,7 +79,9 @@ var tagmanagerWebCmd = &cobra.Command{
|
|||||||
|
|
||||||
{
|
{
|
||||||
name := p.Tags.GoogleTagName("Google Tag")
|
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
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -120,6 +124,8 @@ var tagmanagerWebCmd = &cobra.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var filter string
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
tagmanagerCmd.AddCommand(tagmanagerWebCmd)
|
tagmanagerCmd.AddCommand(tagmanagerWebCmd)
|
||||||
|
|
||||||
@ -132,4 +138,5 @@ func init() {
|
|||||||
// Cobra supports local flags which will only run when this command
|
// Cobra supports local flags which will only run when this command
|
||||||
// is called directly, e.g.:
|
// is called directly, e.g.:
|
||||||
// tagmanagerWebCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
// tagmanagerWebCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
||||||
|
tagmanagerWebCmd.Flags().StringVar(&filter, "filter", "", "Filter tag manager")
|
||||||
}
|
}
|
||||||
|
|||||||
21
main.go
21
main.go
@ -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
|
package main
|
||||||
|
|
||||||
import "github.com/foomo/sesamy-cli/cmd"
|
import "github.com/foomo/sesamy-cli/cmd"
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
type Google struct {
|
type Google struct {
|
||||||
GA4 GA4 `yaml:"ga4"`
|
GT GT `yaml:"gt"`
|
||||||
GTM GTM `yaml:"gtm"`
|
GA4 GA4 `yaml:"ga4"`
|
||||||
RequestQuota int `yaml:"request_quota"`
|
GTM GTM `yaml:"gtm"`
|
||||||
CredentialsFile string `yaml:"credentials_file"`
|
RequestQuota int `yaml:"request_quota"`
|
||||||
CredentialsJSON string `yaml:"credentials_json"`
|
CredentialsFile string `yaml:"credentials_file"`
|
||||||
ServerContainerURL string `yaml:"server_container_url"`
|
CredentialsJSON string `yaml:"credentials_json"`
|
||||||
}
|
}
|
||||||
|
|||||||
6
pkg/config/gt.go
Normal file
6
pkg/config/gt.go
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
type GT struct {
|
||||||
|
ServerContainerURL string `yaml:"server_container_url"`
|
||||||
|
EnablePageViews bool `yaml:"enable_page_views"`
|
||||||
|
}
|
||||||
@ -4,8 +4,8 @@ import (
|
|||||||
"google.golang.org/api/tagmanager/v2"
|
"google.golang.org/api/tagmanager/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewGoogleTag(name string, measurementID *tagmanager.Variable, configSettings *tagmanager.Variable) *tagmanager.Tag {
|
func NewGoogleTag(name string, measurementID *tagmanager.Variable, configSettings *tagmanager.Variable, extraConfigSettings map[string]string) *tagmanager.Tag {
|
||||||
return &tagmanager.Tag{
|
ret := &tagmanager.Tag{
|
||||||
FiringTriggerId: []string{"2147479573"}, // TODO
|
FiringTriggerId: []string{"2147479573"}, // TODO
|
||||||
Name: name,
|
Name: name,
|
||||||
Parameter: []*tagmanager.Parameter{
|
Parameter: []*tagmanager.Parameter{
|
||||||
@ -19,7 +19,40 @@ func NewGoogleTag(name string, measurementID *tagmanager.Variable, configSetting
|
|||||||
Type: "template",
|
Type: "template",
|
||||||
Value: "{{" + configSettings.Name + "}}",
|
Value: "{{" + configSettings.Name + "}}",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Key: "configSettingsTable",
|
||||||
|
Type: "template",
|
||||||
|
Value: "{{" + configSettings.Name + "}}",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Type: "googtag",
|
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
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user