-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from foomo/microsoft
fix(provider/microsoftads): add provider
- Loading branch information
Showing
13 changed files
with
1,208 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package config | ||
|
||
type MicrosoftAds struct { | ||
// Enable provider | ||
Enabled bool `json:"enabled" yaml:"enabled"` | ||
// Google Consent settings | ||
GoogleConsent GoogleConsent `json:"googleConsent" yaml:"googleConsent"` | ||
// Microsoft Ads UET Tag ID | ||
TagID string `json:"tagId" yaml:"tagId"` | ||
// Microsoft Ads Conversion settings | ||
Conversion MicrosoftAdsConversion `json:"conversion" yaml:"conversion"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/foomo/gocontemplate/pkg/contemplate" | ||
) | ||
|
||
type MicrosoftAdsConversion struct { | ||
// Enable provider | ||
Enabled bool `json:"enabled" yaml:"enabled"` | ||
// Google Tag Manager server container settings | ||
ServerContainer MicrosoftAdsServerContainer `json:"serverContainer" yaml:"serverContainer"` | ||
} | ||
|
||
type MicrosoftAdsServerContainer struct { | ||
contemplate.Config `json:",inline" yaml:",squash"` | ||
Settings map[string]MicrosoftAdsConversionTag `json:"settings" yaml:"settings"` | ||
} | ||
|
||
type MicrosoftAdsConversionTag struct { | ||
PageType string `json:"pageType" yaml:"pageType"` | ||
EventType string `json:"eventType" yaml:"eventType"` | ||
} | ||
|
||
func (s *MicrosoftAdsServerContainer) Setting(eventName string) MicrosoftAdsConversionTag { | ||
if value, ok := s.Settings[eventName]; ok { | ||
return value | ||
} | ||
return MicrosoftAdsConversionTag{} | ||
} |
200 changes: 0 additions & 200 deletions
200
pkg/provider/microsoft/server/template/data/conversion/code.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package facebook | ||
|
||
const ( | ||
Tag = "mads" | ||
Name = "Microsoft Ads" | ||
NameTagIDConstant = "Microsoft UET Tag ID" | ||
NameConversionsTagTemplate = "Microsoft Ads Conversions" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package facebook | ||
|
||
import ( | ||
"log/slog" | ||
|
||
"github.com/foomo/sesamy-cli/pkg/config" | ||
"github.com/foomo/sesamy-cli/pkg/provider/googleconsent" | ||
googleconsentvariable "github.com/foomo/sesamy-cli/pkg/provider/googleconsent/server/variable" | ||
servertagx "github.com/foomo/sesamy-cli/pkg/provider/microsoftads/server/tag" | ||
"github.com/foomo/sesamy-cli/pkg/provider/microsoftads/server/template" | ||
"github.com/foomo/sesamy-cli/pkg/provider/microsoftads/server/trigger" | ||
"github.com/foomo/sesamy-cli/pkg/tagmanager" | ||
commonvariable "github.com/foomo/sesamy-cli/pkg/tagmanager/common/variable" | ||
"github.com/foomo/sesamy-cli/pkg/utils" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func Server(l *slog.Logger, tm *tagmanager.TagManager, cfg config.MicrosoftAds) error { | ||
{ // create folder | ||
if folder, err := tm.UpsertFolder("Sesamy - " + Name); err != nil { | ||
return err | ||
} else { | ||
tm.SetFolderName(folder.Name) | ||
} | ||
} | ||
|
||
tagID, err := tm.UpsertVariable(commonvariable.NewConstant(NameTagIDConstant, cfg.TagID)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if cfg.Conversion.Enabled { | ||
tagTemplate, err := tm.UpsertCustomTemplate(template.NewConversionTag(NameConversionsTagTemplate)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
{ // create tags | ||
eventParameters, err := utils.LoadEventParams(cfg.Conversion.ServerContainer.Config) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for event := range eventParameters { | ||
var eventTriggerOpts []trigger.ConversionEventOption | ||
if cfg.GoogleConsent.Enabled { | ||
if err := googleconsent.ServerEnsure(tm); err != nil { | ||
return err | ||
} | ||
consentVariable, err := tm.LookupVariable(googleconsentvariable.GoogleConsentModeName(cfg.GoogleConsent.Mode)) | ||
if err != nil { | ||
return err | ||
} | ||
eventTriggerOpts = append(eventTriggerOpts, trigger.ConversionEventWithConsentMode(consentVariable)) | ||
} | ||
|
||
eventTrigger, err := tm.UpsertTrigger(trigger.NewConversionEvent(event, eventTriggerOpts...)) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to upsert event trigger: "+event) | ||
} | ||
|
||
if _, err := tm.UpsertTag(servertagx.NewConversion(event, tagID, tagTemplate, cfg.Conversion.ServerContainer.Setting(event), eventTrigger)); err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.