mirror of
https://github.com/foomo/sesamy-cli.git
synced 2025-10-16 12:35:36 +00:00
84 lines
1.7 KiB
Go
84 lines
1.7 KiB
Go
package trigger
|
|
|
|
import (
|
|
"google.golang.org/api/tagmanager/v2"
|
|
)
|
|
|
|
func ConversionName(v string) string {
|
|
return "Pinterest Conversion - " + v
|
|
}
|
|
|
|
type (
|
|
EventOptions struct {
|
|
consentMode *tagmanager.Variable
|
|
}
|
|
EventOption func(*EventOptions)
|
|
)
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
// ~ Options
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
func ConversionWithConsentMode(mode *tagmanager.Variable) EventOption {
|
|
return func(o *EventOptions) {
|
|
o.consentMode = mode
|
|
}
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
// ~ Constructor
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
func NewConversion(name string, opts ...EventOption) *tagmanager.Trigger {
|
|
o := &EventOptions{}
|
|
for _, opt := range opts {
|
|
if opt != nil {
|
|
opt(o)
|
|
}
|
|
}
|
|
|
|
var filter []*tagmanager.Condition
|
|
if o.consentMode != nil {
|
|
filter = append(filter,
|
|
&tagmanager.Condition{
|
|
Parameter: []*tagmanager.Parameter{
|
|
{
|
|
Key: "arg0",
|
|
Type: "template",
|
|
Value: "{{" + o.consentMode.Name + "}}",
|
|
},
|
|
{
|
|
Key: "arg1",
|
|
Type: "template",
|
|
Value: "granted",
|
|
},
|
|
},
|
|
Type: "equals",
|
|
},
|
|
)
|
|
}
|
|
|
|
return &tagmanager.Trigger{
|
|
Type: "customEvent",
|
|
Name: ConversionName(name),
|
|
CustomEventFilter: []*tagmanager.Condition{
|
|
{
|
|
Parameter: []*tagmanager.Parameter{
|
|
{
|
|
Key: "arg0",
|
|
Type: "template",
|
|
Value: "{{_event}}",
|
|
},
|
|
{
|
|
Key: "arg1",
|
|
Type: "template",
|
|
Value: name,
|
|
},
|
|
},
|
|
Type: "equals",
|
|
},
|
|
},
|
|
Filter: filter,
|
|
}
|
|
}
|