Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(provider/googleads): configurable conversion labels #68

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions pkg/config/googleads.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ type GoogleAds struct {
// Enable provider
Enabled bool `json:"enabled" yaml:"enabled"`
// Google Consent settings
GoogleConsent GoogleConsent `json:"googleConsent" yaml:"googleConsent"`
ConversionID string `json:"conversionId" yaml:"conversionId"`
Conversion GoogleAdsConversion `json:"conversion" yaml:"conversion"`
Remarketing GoogleAdsRemarketing `json:"remarketing" yaml:"remarketing"`
GoogleConsent GoogleConsent `json:"googleConsent" yaml:"googleConsent"`
// Conversion id
ConversionID string `json:"conversionId" yaml:"conversionId"`
// Google Ads Conversion settings
Conversion GoogleAdsConversion `json:"conversion" yaml:"conversion"`
// Google Ads Remarketing settings
Remarketing GoogleAdsRemarketing `json:"remarketing" yaml:"remarketing"`
}
21 changes: 18 additions & 3 deletions pkg/config/googleadsconversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,23 @@ import (

type GoogleAdsConversion struct {
// Enable provider
Enabled bool `json:"enabled" yaml:"enabled"`
ConversionLabel string `json:"conversionLabel" yaml:"conversionLabel"`
Enabled bool `json:"enabled" yaml:"enabled"`
// Google Tag Manager server container settings
ServerContainer contemplate.Config `json:"serverContainer" yaml:"serverContainer"`
ServerContainer ServerContainer `json:"serverContainer" yaml:"serverContainer"`
}

type ServerContainer struct {
contemplate.Config `json:",inline" yaml:",squash"`
Settings map[string]GoogleAdsConversionTracking `json:"settings" yaml:"settings"`
}

type GoogleAdsConversionTracking struct {
Label string `json:"label" yaml:"label"`
}

func (s *ServerContainer) Setting(eventName string) GoogleAdsConversionTracking {
if value, ok := s.Settings[eventName]; ok {
return value
}
return GoogleAdsConversionTracking{}
}
1 change: 0 additions & 1 deletion pkg/provider/googleads/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const (
Tag = "gads"
Name = "Google Ads"
NameConversionIDConstant = "GAds Conversion ID"
NameConversionLabelConstant = "GAds Conversion Label"
NameGoogleAdsRemarketingTag = "Google Ads Remarketing"
NameGoogleAdsRemarketingTrigger = "Google Ads Remarketing"
)
9 changes: 2 additions & 7 deletions pkg/provider/googleads/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ func Server(l *slog.Logger, tm *tagmanager.TagManager, cfg config.GoogleAds) err

// conversion
if cfg.Conversion.Enabled {
conversionLabel, err := tm.UpsertVariable(commonvariable.NewConstant(NameConversionLabelConstant, cfg.Conversion.ConversionLabel))
if err != nil {
return err
}

value, err := tm.UpsertVariable(variable.NewEventData("value"))
if err != nil {
return err
Expand All @@ -47,7 +42,7 @@ func Server(l *slog.Logger, tm *tagmanager.TagManager, cfg config.GoogleAds) err
}

{ // create tags
eventParameters, err := utils.LoadEventParams(cfg.Conversion.ServerContainer)
eventParameters, err := utils.LoadEventParams(cfg.Conversion.ServerContainer.Config)
if err != nil {
return err
}
Expand All @@ -70,7 +65,7 @@ func Server(l *slog.Logger, tm *tagmanager.TagManager, cfg config.GoogleAds) err
return errors.Wrap(err, "failed to upsert event trigger: "+event)
}

if _, err := tm.UpsertTag(servertagx.NewGoogleAdsConversionTracking(event, value, currency, conversionID, conversionLabel, eventTrigger)); err != nil {
if _, err := tm.UpsertTag(servertagx.NewGoogleAdsConversionTracking(event, value, currency, conversionID, cfg.Conversion.ServerContainer.Setting(event), eventTrigger)); err != nil {
return err
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tag

import (
"github.com/foomo/sesamy-cli/pkg/config"
"github.com/foomo/sesamy-cli/pkg/utils"
"google.golang.org/api/tagmanager/v2"
)
Expand All @@ -9,7 +10,7 @@ func GoogleAdsConversionTrackingName(v string) string {
return "GAds Conversion - " + v
}

func NewGoogleAdsConversionTracking(name string, value, currency, conversionID, conversionLabel *tagmanager.Variable, triggers ...*tagmanager.Trigger) *tagmanager.Tag {
func NewGoogleAdsConversionTracking(name string, value, currency, conversionID *tagmanager.Variable, settings config.GoogleAdsConversionTracking, triggers ...*tagmanager.Trigger) *tagmanager.Tag {
return &tagmanager.Tag{
FiringTriggerId: utils.TriggerIDs(triggers),
Name: GoogleAdsConversionTrackingName(name),
Expand Down Expand Up @@ -48,7 +49,7 @@ func NewGoogleAdsConversionTracking(name string, value, currency, conversionID,
{
Key: "conversionLabel",
Type: "template",
Value: "{{" + conversionLabel.Name + "}}",
Value: settings.Label,
},
{
Key: "rdp",
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/tracify/server/template/tracifytagdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ function mapEventData() {

// Anonymized email address (optional, if available)
if (eventData.user_id) {
event.identity_dataidentity[anonymize(eventData.user_id)] = 1;
event.identity_data[anonymize(eventData.user_id)] = 1;
}
// Anonymized session id
if (remoteAddress && userAgent) {
Expand Down
1 change: 1 addition & 0 deletions pkg/tagmanager/tagmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func New(ctx context.Context, l *slog.Logger, accountID string, container config
notes: "Managed by Sesamy. DO NOT EDIT.",
folderName: "Sesamy",
clientOptions: []option.ClientOption{
option.WithLogger(l),
option.WithRequestReason("Sesamy container provisioning"),
},
}
Expand Down
41 changes: 34 additions & 7 deletions sesamy.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,16 @@
"description": "Google Consent settings"
},
"conversionId": {
"type": "string"
"type": "string",
"description": "Conversion id"
},
"conversion": {
"$ref": "#/$defs/github.com.foomo.sesamy-cli.pkg.config.GoogleAdsConversion"
"$ref": "#/$defs/github.com.foomo.sesamy-cli.pkg.config.GoogleAdsConversion",
"description": "Google Ads Conversion settings"
},
"remarketing": {
"$ref": "#/$defs/github.com.foomo.sesamy-cli.pkg.config.GoogleAdsRemarketing"
"$ref": "#/$defs/github.com.foomo.sesamy-cli.pkg.config.GoogleAdsRemarketing",
"description": "Google Ads Remarketing settings"
}
},
"additionalProperties": false,
Expand All @@ -267,17 +270,23 @@
"type": "boolean",
"description": "Enable provider"
},
"conversionLabel": {
"type": "string"
},
"serverContainer": {
"$ref": "#/$defs/github.com.foomo.gocontemplate.pkg.contemplate.Config",
"$ref": "#/$defs/github.com.foomo.sesamy-cli.pkg.config.ServerContainer",
"description": "Google Tag Manager server container settings"
}
},
"additionalProperties": false,
"type": "object"
},
"github.com.foomo.sesamy-cli.pkg.config.GoogleAdsConversionTracking": {
"properties": {
"label": {
"type": "string"
}
},
"additionalProperties": false,
"type": "object"
},
"github.com.foomo.sesamy-cli.pkg.config.GoogleAdsRemarketing": {
"properties": {
"enabled": {
Expand Down Expand Up @@ -410,6 +419,18 @@
"additionalProperties": false,
"type": "object"
},
"github.com.foomo.sesamy-cli.pkg.config.ServerContainer": {
"properties": {
"packages": {
"$ref": "#/$defs/[]*contemplate.PackageConfig"
},
"settings": {
"$ref": "#/$defs/map[string]config.GoogleAdsConversionTracking"
}
},
"additionalProperties": false,
"type": "object"
},
"github.com.foomo.sesamy-cli.pkg.config.Tracify": {
"properties": {
"enabled": {
Expand Down Expand Up @@ -474,6 +495,12 @@
},
"additionalProperties": false,
"type": "object"
},
"map[string]config.GoogleAdsConversionTracking": {
"additionalProperties": {
"$ref": "#/$defs/github.com.foomo.sesamy-cli.pkg.config.GoogleAdsConversionTracking"
},
"type": "object"
}
}
}
Loading