mirror of
https://github.com/foomo/sesamy-cli.git
synced 2026-08-16 14:40:24 +00:00
Merge pull request #73 from foomo/sesamy-cli-0.9.0
feat(tagmanager): add mpv2 user data transformation
This commit is contained in:
@@ -12,6 +12,7 @@ func NewTagmanager(root *cobra.Command) *cobra.Command {
|
||||
Short: "Provision Google Tag Manager containers",
|
||||
}
|
||||
|
||||
tagmanager.NewTags(cmd)
|
||||
tagmanager.NewServer(cmd)
|
||||
tagmanager.NewWeb(cmd)
|
||||
root.AddCommand(cmd)
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package tagmanager
|
||||
|
||||
import (
|
||||
conversionlinkerprovider "github.com/foomo/sesamy-cli/pkg/provider/conversionlinker"
|
||||
criteoprovider "github.com/foomo/sesamy-cli/pkg/provider/criteo"
|
||||
emarsysprovider "github.com/foomo/sesamy-cli/pkg/provider/emarsys"
|
||||
facebookprovider "github.com/foomo/sesamy-cli/pkg/provider/facebook"
|
||||
googleadsprovider "github.com/foomo/sesamy-cli/pkg/provider/googleads"
|
||||
googleanalyticsprovider "github.com/foomo/sesamy-cli/pkg/provider/googleanalytics"
|
||||
googletagmanagerprovider "github.com/foomo/sesamy-cli/pkg/provider/googletagmanager"
|
||||
microsoftadsprovider "github.com/foomo/sesamy-cli/pkg/provider/microsoftads"
|
||||
tracifyprovider "github.com/foomo/sesamy-cli/pkg/provider/tracify"
|
||||
umamiprovider "github.com/foomo/sesamy-cli/pkg/provider/umami"
|
||||
"github.com/pterm/pterm"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// NewTags represents the tags command
|
||||
func NewTags(root *cobra.Command) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "tags",
|
||||
Short: "Print out all available tags",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
// Define the data for the first table
|
||||
data := pterm.TableData{
|
||||
{"Name", "Tag"},
|
||||
{conversionlinkerprovider.Name, conversionlinkerprovider.Tag},
|
||||
{criteoprovider.Name, criteoprovider.Tag},
|
||||
{emarsysprovider.Name, emarsysprovider.Tag},
|
||||
{facebookprovider.Name, facebookprovider.Tag},
|
||||
{googleadsprovider.Name, googleadsprovider.Tag},
|
||||
{googleanalyticsprovider.Name, googleanalyticsprovider.Tag},
|
||||
{googletagmanagerprovider.Name, googletagmanagerprovider.Tag},
|
||||
{microsoftadsprovider.Name, microsoftadsprovider.Tag},
|
||||
{tracifyprovider.Name, tracifyprovider.Tag},
|
||||
{umamiprovider.Name, umamiprovider.Tag},
|
||||
}
|
||||
|
||||
return pterm.DefaultTable.WithHasHeader().WithData(data).Render()
|
||||
},
|
||||
}
|
||||
|
||||
root.AddCommand(cmd)
|
||||
|
||||
return cmd
|
||||
}
|
||||
+23
-10
@@ -4,14 +4,27 @@ import (
|
||||
"github.com/foomo/gocontemplate/pkg/contemplate"
|
||||
)
|
||||
|
||||
type Facebook struct {
|
||||
// Enable provider
|
||||
Enabled bool `json:"enabled" yaml:"enabled"`
|
||||
PixelID string `json:"pixelId" yaml:"pixelId"`
|
||||
APIAccessToken string `json:"apiAccessToken" yaml:"apiAccessToken"`
|
||||
TestEventToken string `json:"testEventToken" yaml:"testEventToken"`
|
||||
// Google Consent settings
|
||||
GoogleConsent GoogleConsent `json:"googleConsent" yaml:"googleConsent"`
|
||||
// Google Tag Manager server container settings
|
||||
ServerContainer contemplate.Config `json:"serverContainer" yaml:"serverContainer"`
|
||||
type (
|
||||
Facebook struct {
|
||||
// Enable provider
|
||||
Enabled bool `json:"enabled" yaml:"enabled"`
|
||||
PixelID string `json:"pixelId" yaml:"pixelId"`
|
||||
APIAccessToken string `json:"apiAccessToken" yaml:"apiAccessToken"`
|
||||
TestEventToken string `json:"testEventToken" yaml:"testEventToken"`
|
||||
// Google Consent settings
|
||||
GoogleConsent GoogleConsent `json:"googleConsent" yaml:"googleConsent"`
|
||||
// Google Tag Manager server container settings
|
||||
ServerContainer FacebookServerContainer `json:"serverContainer" yaml:"serverContainer"`
|
||||
}
|
||||
FacebookServerContainer struct {
|
||||
contemplate.Config `json:",inline" yaml:",squash"`
|
||||
Settings map[string]FacebookConversionAPITag `json:"settings" yaml:"settings"`
|
||||
}
|
||||
)
|
||||
|
||||
func (s *FacebookServerContainer) Setting(eventName string) FacebookConversionAPITag {
|
||||
if value, ok := s.Settings[eventName]; ok {
|
||||
return value
|
||||
}
|
||||
return FacebookConversionAPITag{}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package config
|
||||
|
||||
type FacebookConversionAPITag struct {
|
||||
// Extend Meta Pixel cookies (fbp/fbc)
|
||||
ExtendCookies bool `json:"extendCookies" yaml:"extendCookies"`
|
||||
// Enable Use of HTTP Only Secure Cookie (gtmeec) to Enhance Event Data
|
||||
EnableEventEnhancement bool `json:"enableEventEnhancement" yaml:"enableEventEnhancement"`
|
||||
}
|
||||
@@ -4,23 +4,20 @@ import (
|
||||
"github.com/foomo/gocontemplate/pkg/contemplate"
|
||||
)
|
||||
|
||||
type GoogleAdsConversion struct {
|
||||
// Enable provider
|
||||
Enabled bool `json:"enabled" yaml:"enabled"`
|
||||
// Google Tag Manager server container settings
|
||||
ServerContainer ServerContainer `json:"serverContainer" yaml:"serverContainer"`
|
||||
}
|
||||
type (
|
||||
GoogleAdsConversion struct {
|
||||
// Enable provider
|
||||
Enabled bool `json:"enabled" yaml:"enabled"`
|
||||
// Google Tag Manager server container settings
|
||||
ServerContainer GoogleAdsConversionServerContainer `json:"serverContainer" yaml:"serverContainer"`
|
||||
}
|
||||
GoogleAdsConversionServerContainer struct {
|
||||
contemplate.Config `json:",inline" yaml:",squash"`
|
||||
Settings map[string]GoogleAdsConversionTracking `json:"settings" yaml:"settings"`
|
||||
}
|
||||
)
|
||||
|
||||
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 {
|
||||
func (s *GoogleAdsConversionServerContainer) Setting(eventName string) GoogleAdsConversionTracking {
|
||||
if value, ok := s.Settings[eventName]; ok {
|
||||
return value
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package config
|
||||
|
||||
type GoogleAdsConversionTracking struct {
|
||||
Label string `json:"label" yaml:"label"`
|
||||
}
|
||||
@@ -11,6 +11,8 @@ type Tracify struct {
|
||||
Token string `json:"token" yaml:"token"`
|
||||
// Tracify customer site id
|
||||
CustomerSiteID string `json:"customerSiteId" yaml:"customerSiteId"`
|
||||
// Enable stating mode
|
||||
StagingModeEnabled bool `json:"stagingModeEnabled" yaml:"stagingModeEnabled"`
|
||||
// Google Consent settings
|
||||
GoogleConsent GoogleConsent `json:"googleConsent" yaml:"googleConsent"`
|
||||
// Google Tag Manager server container settings
|
||||
|
||||
@@ -47,7 +47,7 @@ func Server(l *slog.Logger, tm *tagmanager.TagManager, cfg config.Facebook) erro
|
||||
}
|
||||
|
||||
{ // create tags
|
||||
eventParameters, err := utils.LoadEventParams(cfg.ServerContainer)
|
||||
eventParameters, err := utils.LoadEventParams(cfg.ServerContainer.Config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -70,7 +70,7 @@ func Server(l *slog.Logger, tm *tagmanager.TagManager, cfg config.Facebook) erro
|
||||
return errors.Wrap(err, "failed to upsert event trigger: "+event)
|
||||
}
|
||||
|
||||
if _, err := tm.UpsertTag(servertagx.NewConversionsAPITag(event, pixelID, apiAccessToken, testEventToken, template, eventTrigger)); err != nil {
|
||||
if _, err := tm.UpsertTag(servertagx.NewConversionsAPITag(event, pixelID, apiAccessToken, testEventToken, cfg.ServerContainer.Setting(event), template, eventTrigger)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package tag
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/foomo/sesamy-cli/pkg/config"
|
||||
"github.com/foomo/sesamy-cli/pkg/utils"
|
||||
"google.golang.org/api/tagmanager/v2"
|
||||
)
|
||||
@@ -9,7 +12,7 @@ func ConversionsAPITagName(v string) string {
|
||||
return "FB Conversion - " + v
|
||||
}
|
||||
|
||||
func NewConversionsAPITag(name string, pixelID, apiAccessToken, testEventCode *tagmanager.Variable, template *tagmanager.CustomTemplate, triggers ...*tagmanager.Trigger) *tagmanager.Tag {
|
||||
func NewConversionsAPITag(name string, pixelID, apiAccessToken, testEventCode *tagmanager.Variable, settings config.FacebookConversionAPITag, template *tagmanager.CustomTemplate, triggers ...*tagmanager.Trigger) *tagmanager.Tag {
|
||||
return &tagmanager.Tag{
|
||||
FiringTriggerId: utils.TriggerIDs(triggers),
|
||||
Name: ConversionsAPITagName(name),
|
||||
@@ -33,12 +36,12 @@ func NewConversionsAPITag(name string, pixelID, apiAccessToken, testEventCode *t
|
||||
{
|
||||
Key: "enableEventEnhancement",
|
||||
Type: "boolean",
|
||||
Value: "false",
|
||||
Value: strconv.FormatBool(settings.EnableEventEnhancement),
|
||||
},
|
||||
{
|
||||
Key: "extendCookies",
|
||||
Type: "boolean",
|
||||
Value: "false",
|
||||
Value: strconv.FormatBool(settings.ExtendCookies),
|
||||
},
|
||||
{
|
||||
Key: "actionSource",
|
||||
|
||||
@@ -7,6 +7,8 @@ const (
|
||||
NameGoogleAnalyticsGA4ClientTrigger = "Google Analytics GA4 Client"
|
||||
NameGoogleGTagClientTemplate = "Google gtag.js"
|
||||
NameGoogleGTagClient = "Google gtag.js"
|
||||
NameMPv2UserDataTransformation = "MPv2 User Data"
|
||||
NameJSONRequestValueTemplate = "JSON Request Value"
|
||||
NameMeasurementProtocolGA4Client = "Measurement Protocol GA4"
|
||||
NameMeasurementProtocolGA4ClientTrigger = "Measurement Protocol GA4 Client"
|
||||
)
|
||||
|
||||
@@ -2,15 +2,18 @@ package googleanalytics
|
||||
|
||||
import (
|
||||
"github.com/foomo/sesamy-cli/pkg/config"
|
||||
client2 "github.com/foomo/sesamy-cli/pkg/provider/googleanalytics/server/client"
|
||||
googleanalyticsclient "github.com/foomo/sesamy-cli/pkg/provider/googleanalytics/server/client"
|
||||
containertag "github.com/foomo/sesamy-cli/pkg/provider/googleanalytics/server/tag"
|
||||
template2 "github.com/foomo/sesamy-cli/pkg/provider/googleanalytics/server/template"
|
||||
googleanalyticstemplate "github.com/foomo/sesamy-cli/pkg/provider/googleanalytics/server/template"
|
||||
"github.com/foomo/sesamy-cli/pkg/provider/googleanalytics/server/trigger"
|
||||
"github.com/foomo/sesamy-cli/pkg/provider/googleconsent"
|
||||
googleconsentvariable "github.com/foomo/sesamy-cli/pkg/provider/googleconsent/server/variable"
|
||||
"github.com/foomo/sesamy-cli/pkg/tagmanager"
|
||||
serverclient "github.com/foomo/sesamy-cli/pkg/tagmanager/server/client"
|
||||
servertemplate "github.com/foomo/sesamy-cli/pkg/tagmanager/server/template"
|
||||
servertransformation "github.com/foomo/sesamy-cli/pkg/tagmanager/server/transformation"
|
||||
servertrigger "github.com/foomo/sesamy-cli/pkg/tagmanager/server/trigger"
|
||||
servervariable "github.com/foomo/sesamy-cli/pkg/tagmanager/server/variable"
|
||||
"github.com/foomo/sesamy-cli/pkg/utils"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
@@ -43,15 +46,30 @@ func Server(tm *tagmanager.TagManager, cfg config.GoogleAnalytics, redactVisitor
|
||||
if _, err = tm.UpsertTrigger(servertrigger.NewClient(NameMeasurementProtocolGA4ClientTrigger, client)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.GoogleGTag.Enabled {
|
||||
template, err := tm.UpsertCustomTemplate(template2.NewGoogleGTagClient(NameGoogleGTagClientTemplate))
|
||||
userDataTemplate, err := tm.UpsertCustomTemplate(servertemplate.NewJSONRequestValue(NameJSONRequestValueTemplate))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = tm.UpsertClient(client2.NewGoogleGTag(NameGoogleGTagClient, cfg.GoogleGTag, template))
|
||||
userDataVariable, err := tm.UpsertVariable(servervariable.NewMPv2Data("user_data", userDataTemplate))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = tm.UpsertTransformation(servertransformation.NewMPv2UserData(NameMPv2UserDataTransformation, userDataVariable, client))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.GoogleGTag.Enabled {
|
||||
template, err := tm.UpsertCustomTemplate(googleanalyticstemplate.NewGoogleGTagClient(NameGoogleGTagClientTemplate))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = tm.UpsertClient(googleanalyticsclient.NewGoogleGTag(NameGoogleGTagClient, cfg.GoogleGTag, template))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -10,13 +10,5 @@ func NewGoogleConsentModeCheck(name string) *tagmanager.CustomTemplate {
|
||||
return &tagmanager.CustomTemplate{
|
||||
Name: name,
|
||||
TemplateData: fmt.Sprintf(GoogleConsentModeCheckData, name),
|
||||
// oogleapi: Error 400: galleryReference: This field is invalid (or unsupported).
|
||||
// GalleryReference: &tagmanager.GalleryReference{
|
||||
// Host: "github.com",
|
||||
// Owner: "analytics-engineers",
|
||||
// Repository: "gtm-server-variable-google-consent-mode-check",
|
||||
// Signature: "8905ba41f72b510484a3ff9dc27dabaf09c029eb1228e2d1435b5cc2e837cc8d",
|
||||
// Version: "a31230ca43cdadea1b97ef7dcf76b8e9f8c04725",
|
||||
// },
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ func Server(l *slog.Logger, tm *tagmanager.TagManager, cfg config.Tracify) error
|
||||
return errors.Wrap(err, "failed to upsert event trigger: "+event)
|
||||
}
|
||||
|
||||
if _, err := tm.UpsertTag(servertagx.NewTracify(event, token, customerSiteID, tagTemplate, eventTrigger)); err != nil {
|
||||
if _, err := tm.UpsertTag(servertagx.NewTracify(event, token, customerSiteID, tagTemplate, cfg, eventTrigger)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package tag
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/foomo/sesamy-cli/pkg/config"
|
||||
"github.com/foomo/sesamy-cli/pkg/utils"
|
||||
"google.golang.org/api/tagmanager/v2"
|
||||
)
|
||||
@@ -9,7 +12,7 @@ func TracifyName(v string) string {
|
||||
return "Tracify - " + v
|
||||
}
|
||||
|
||||
func NewTracify(name string, token, customerSiteID *tagmanager.Variable, template *tagmanager.CustomTemplate, triggers ...*tagmanager.Trigger) *tagmanager.Tag {
|
||||
func NewTracify(name string, token, customerSiteID *tagmanager.Variable, template *tagmanager.CustomTemplate, cfg config.Tracify, triggers ...*tagmanager.Trigger) *tagmanager.Tag {
|
||||
return &tagmanager.Tag{
|
||||
FiringTriggerId: utils.TriggerIDs(triggers),
|
||||
Name: TracifyName(name),
|
||||
@@ -28,7 +31,7 @@ func NewTracify(name string, token, customerSiteID *tagmanager.Variable, templat
|
||||
{
|
||||
Key: "isStagingMode",
|
||||
Type: "boolean",
|
||||
Value: "false",
|
||||
Value: strconv.FormatBool(cfg.StagingModeEnabled),
|
||||
},
|
||||
{
|
||||
Key: "token",
|
||||
|
||||
@@ -7,7 +7,6 @@ const TracifyTagData = `___INFO___
|
||||
"id": "cvt_temp_public_id",
|
||||
"version": 1,
|
||||
"securityGroups": [],
|
||||
"displayName": "Manual Tracify",
|
||||
"displayName": "%s",
|
||||
"brand": {
|
||||
"id": "brand_dummy",
|
||||
@@ -115,6 +114,7 @@ const endpoint = hostname + '/api/v1/events';
|
||||
const remoteAddress = eventData.ip_override || getRemoteAddress();
|
||||
const sessionId = eventData.ga_session_id || eventData.session_id;
|
||||
const userAgent = eventData.user_agent || getRequestHeader('User-Agent');
|
||||
const pageReferer = eventData.page_referrer;
|
||||
const pageLocation = eventData.page_location || getRequestHeader('Referer');
|
||||
const timestamp = (eventData['x-sst-system_properties'] || {}).request_start_time_ms || (eventData.timestamp_micros / 1000) || getTimestampMillis();
|
||||
|
||||
@@ -149,10 +149,12 @@ return sendHttpRequest(endpoint, options, JSON.stringify(body)).then((result) =>
|
||||
// --- Utils ---
|
||||
|
||||
function mapEventData() {
|
||||
const url = parseUrl(pageLocation);
|
||||
|
||||
// https://tracify.dev/events
|
||||
const event = {
|
||||
// The full URL (domain + path) for which the request is served.
|
||||
url: pageLocation || null,
|
||||
url: pageLocation,
|
||||
// The identifier used to indicate on what website the events are occurring.
|
||||
// This id is provided by your account representative.
|
||||
customer_site_id: data.customerSiteId,
|
||||
@@ -163,17 +165,24 @@ function mapEventData() {
|
||||
// The type of event
|
||||
type: '',
|
||||
// Data properties specific to the event type sent
|
||||
data: {},
|
||||
data: {
|
||||
origin: url.hostname,
|
||||
},
|
||||
};
|
||||
|
||||
// Referrer
|
||||
if (pageReferer) {
|
||||
event.data.Referer = pageReferer;
|
||||
}
|
||||
|
||||
// Anonymized email address (optional, if available)
|
||||
if (eventData.user_id) {
|
||||
event.identity_data[anonymize(eventData.user_id)] = 1;
|
||||
}
|
||||
// Anonymized session id
|
||||
if (remoteAddress && userAgent) {
|
||||
if (remoteAddress && userAgent) {
|
||||
event.identity_data[anonymize(remoteAddress+'|'+userAgent)] = 2;
|
||||
}
|
||||
}
|
||||
// Anonymized IP address
|
||||
if (remoteAddress) {
|
||||
event.identity_data[anonymize(remoteAddress)] = 3;
|
||||
@@ -183,46 +192,30 @@ function mapEventData() {
|
||||
event.identity_data[anonymize(userAgent)] = 4;
|
||||
}
|
||||
|
||||
const url = parseUrl(pageLocation);
|
||||
switch (eventData.event_name) {
|
||||
case 'tracify_page_view': {
|
||||
event.type = 'pageview';
|
||||
event.data = {
|
||||
origin: url.hostname,
|
||||
};
|
||||
event.data = mapUrlParams(url.searchParams, event.data);
|
||||
break;
|
||||
}
|
||||
case 'tracify_product_view': {
|
||||
event.type = 'productview';
|
||||
event.data = {
|
||||
origin: url.hostname,
|
||||
};
|
||||
event.data = mapUrlParams(url.searchParams, event.data);
|
||||
break;
|
||||
}
|
||||
// standard evens
|
||||
case 'page_view': {
|
||||
event.type = 'pageview';
|
||||
event.data = {
|
||||
origin: url.hostname,
|
||||
};
|
||||
event.data = mapUrlParams(url.searchParams, event.data);
|
||||
break;
|
||||
}
|
||||
case 'view_item': {
|
||||
event.type = 'productview';
|
||||
event.data = {
|
||||
origin: url.hostname,
|
||||
};
|
||||
event.data = mapUrlParams(url.searchParams, event.data);
|
||||
break;
|
||||
}
|
||||
case 'add_to_cart': {
|
||||
event.type = 'addtocart';
|
||||
event.data = {
|
||||
origin: url.hostname,
|
||||
};
|
||||
event.data = mapItems(eventData.items || [], event.data);
|
||||
break;
|
||||
}
|
||||
@@ -241,7 +234,6 @@ function mapEventData() {
|
||||
case 'conversion': {
|
||||
event.type = 'conversion';
|
||||
event.data = {
|
||||
origin: url.hostname,
|
||||
conversion_id: makeString(eventData.transaction_id),
|
||||
currency: eventData.currency,
|
||||
cc: eventData.currency, // required due to API bug
|
||||
@@ -255,14 +247,14 @@ function mapEventData() {
|
||||
}
|
||||
|
||||
function isConsentGivenOrNotRequired() {
|
||||
if (data.analyticsStorageConsent !== 'required') {
|
||||
return true;
|
||||
}
|
||||
if (eventData.consent_state) {
|
||||
return !!eventData.consent_state.analytics_storage;
|
||||
}
|
||||
const xGaGcs = eventData['x-ga-gcs'] || ''; // x-ga-gcs is a string like "G101"
|
||||
return xGaGcs[3] === '1';
|
||||
if (data.analyticsStorageConsent !== 'required') {
|
||||
return true;
|
||||
}
|
||||
if (eventData.consent_state) {
|
||||
return !!eventData.consent_state.analytics_storage;
|
||||
}
|
||||
const xGaGcs = eventData['x-ga-gcs'] || ''; // x-ga-gcs is a string like "G101"
|
||||
return xGaGcs[3] === '1';
|
||||
}
|
||||
|
||||
function mapItems(items, val) {
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package template
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"google.golang.org/api/tagmanager/v2"
|
||||
)
|
||||
|
||||
func NewJSONRequestValue(name string) *tagmanager.CustomTemplate {
|
||||
return &tagmanager.CustomTemplate{
|
||||
Name: name,
|
||||
TemplateData: fmt.Sprintf(JSONRequestValueData, name),
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,89 @@
|
||||
package transformation
|
||||
|
||||
import (
|
||||
"google.golang.org/api/tagmanager/v2"
|
||||
)
|
||||
|
||||
func NewMPv2UserData(name string, variable *tagmanager.Variable, client *tagmanager.Client) *tagmanager.Transformation {
|
||||
return &tagmanager.Transformation{
|
||||
Name: name,
|
||||
Parameter: []*tagmanager.Parameter{
|
||||
{
|
||||
Key: "matchingConditionsEnabled",
|
||||
Type: "boolean",
|
||||
Value: "true",
|
||||
},
|
||||
{
|
||||
Key: "allTagsExcept",
|
||||
Type: "boolean",
|
||||
Value: "true",
|
||||
},
|
||||
{
|
||||
Key: "booleanExpressionString",
|
||||
Type: "template",
|
||||
},
|
||||
{
|
||||
Key: "augmentEventTable",
|
||||
List: []*tagmanager.Parameter{
|
||||
{
|
||||
IsWeakReference: false,
|
||||
Map: []*tagmanager.Parameter{
|
||||
{
|
||||
Key: "paramName",
|
||||
Type: "template",
|
||||
Value: "user_data",
|
||||
},
|
||||
{
|
||||
Key: "paramValue",
|
||||
Type: "template",
|
||||
Value: "{{" + variable.Name + "}}",
|
||||
},
|
||||
},
|
||||
Type: "map",
|
||||
},
|
||||
},
|
||||
Type: "list",
|
||||
},
|
||||
{
|
||||
Key: "affectedTags",
|
||||
Type: "list",
|
||||
},
|
||||
{
|
||||
Key: "affectedTagTypes",
|
||||
Type: "list",
|
||||
},
|
||||
{
|
||||
Key: "matchingConditionsTable",
|
||||
List: []*tagmanager.Parameter{
|
||||
{
|
||||
Map: []*tagmanager.Parameter{
|
||||
{
|
||||
Key: "variableName",
|
||||
Type: "template",
|
||||
Value: "Client Name",
|
||||
},
|
||||
{
|
||||
Key: "variableReference",
|
||||
Type: "template",
|
||||
Value: "{{Client Name}}",
|
||||
},
|
||||
{
|
||||
Key: "expressionType",
|
||||
Type: "template",
|
||||
Value: "EQUALS",
|
||||
},
|
||||
{
|
||||
Key: "expressionValue",
|
||||
Type: "template",
|
||||
Value: client.Name,
|
||||
},
|
||||
},
|
||||
Type: "map",
|
||||
},
|
||||
},
|
||||
Type: "list",
|
||||
},
|
||||
},
|
||||
Type: "tf_augment_event",
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package variable
|
||||
|
||||
import (
|
||||
"github.com/foomo/sesamy-cli/pkg/utils"
|
||||
"google.golang.org/api/tagmanager/v2"
|
||||
)
|
||||
|
||||
func MPv2DataName(v string) string {
|
||||
return "mpv2." + v
|
||||
}
|
||||
|
||||
func NewMPv2Data(name string, template *tagmanager.CustomTemplate) *tagmanager.Variable {
|
||||
return &tagmanager.Variable{
|
||||
Name: name,
|
||||
Parameter: []*tagmanager.Parameter{
|
||||
{
|
||||
Key: "key",
|
||||
Type: "template",
|
||||
Value: name,
|
||||
},
|
||||
},
|
||||
Type: utils.TemplateType(template),
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@ type (
|
||||
triggers map[string]*tagmanager.Trigger
|
||||
tags map[string]*tagmanager.Tag
|
||||
customTemplates map[string]*tagmanager.CustomTemplate
|
||||
transformations map[string]*tagmanager.Transformation
|
||||
}
|
||||
Option func(*TagManager)
|
||||
)
|
||||
@@ -304,6 +305,19 @@ func (t *TagManager) LookupTemplate(name string) (*tagmanager.CustomTemplate, er
|
||||
return elems[name], nil
|
||||
}
|
||||
|
||||
func (t *TagManager) LookupTransformation(name string) (*tagmanager.Transformation, error) {
|
||||
elems, err := t.LoadTransformations()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, ok := elems[name]; !ok {
|
||||
return nil, ErrNotFound
|
||||
}
|
||||
|
||||
return elems[name], nil
|
||||
}
|
||||
|
||||
func (t *TagManager) LoadTriggers() (map[string]*tagmanager.Trigger, error) {
|
||||
if t.triggers == nil {
|
||||
t.l.Info("🛄 Loading list", "type", "Trigger")
|
||||
@@ -384,6 +398,24 @@ func (t *TagManager) LoadCustomTemplates() (map[string]*tagmanager.CustomTemplat
|
||||
return t.customTemplates, nil
|
||||
}
|
||||
|
||||
func (t *TagManager) LoadTransformations() (map[string]*tagmanager.Transformation, error) {
|
||||
if t.transformations == nil {
|
||||
t.l.Info("🛄 Loading list", "type", "Transformation")
|
||||
r, err := t.Service().Accounts.Containers.Workspaces.Transformations.List(t.WorkspacePath()).Do()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res := map[string]*tagmanager.Transformation{}
|
||||
for _, value := range r.Transformation {
|
||||
res[value.Name] = value
|
||||
}
|
||||
t.transformations = res
|
||||
}
|
||||
|
||||
return t.transformations, nil
|
||||
}
|
||||
|
||||
func (t *TagManager) UpsertClient(item *tagmanager.Client) (*tagmanager.Client, error) {
|
||||
l := t.l.With("type", "Client", "name", item.Name)
|
||||
|
||||
@@ -419,6 +451,41 @@ func (t *TagManager) UpsertClient(item *tagmanager.Client) (*tagmanager.Client,
|
||||
return t.LookupClient(item.Name)
|
||||
}
|
||||
|
||||
func (t *TagManager) UpsertTransformation(item *tagmanager.Transformation) (*tagmanager.Transformation, error) {
|
||||
l := t.l.With("type", "Transformation", "name", item.Name)
|
||||
|
||||
folder, err := t.LookupFolder(t.folderName)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to retrieve folder")
|
||||
}
|
||||
item.ParentFolderId = folder.FolderId
|
||||
|
||||
item.Notes = t.Notes(item)
|
||||
item.AccountId = t.AccountID()
|
||||
item.ContainerId = t.ContainerID()
|
||||
item.WorkspaceId = t.WorkspaceID()
|
||||
|
||||
cache, err := t.LookupTransformation(item.Name)
|
||||
if err != nil && !errors.Is(err, ErrNotFound) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if cache == nil {
|
||||
l.Info("🚀 New")
|
||||
t.transformations[item.Name], err = t.Service().Accounts.Containers.Workspaces.Transformations.Create(t.WorkspacePath(), item).Do()
|
||||
} else if item.Notes == cache.Notes {
|
||||
l.Info("✅ OK", "id", cache.TransformationId)
|
||||
} else {
|
||||
l.Info("🔄 Update", "id", cache.TransformationId)
|
||||
t.transformations[item.Name], err = t.Service().Accounts.Containers.Workspaces.Transformations.Update(t.WorkspacePath()+"/transformations/"+cache.TransformationId, item).Do()
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return t.LookupTransformation(item.Name)
|
||||
}
|
||||
|
||||
func (t *TagManager) UpsertFolder(name string) (*tagmanager.Folder, error) {
|
||||
l := t.l.With("type", "Folder", "name", name)
|
||||
|
||||
|
||||
+50
-14
@@ -220,13 +220,39 @@
|
||||
"description": "Google Consent settings"
|
||||
},
|
||||
"serverContainer": {
|
||||
"$ref": "#/$defs/github.com.foomo.gocontemplate.pkg.contemplate.Config",
|
||||
"$ref": "#/$defs/github.com.foomo.sesamy-cli.pkg.config.FacebookServerContainer",
|
||||
"description": "Google Tag Manager server container settings"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"type": "object"
|
||||
},
|
||||
"github.com.foomo.sesamy-cli.pkg.config.FacebookConversionAPITag": {
|
||||
"properties": {
|
||||
"extendCookies": {
|
||||
"type": "boolean",
|
||||
"description": "Extend Meta Pixel cookies (fbp/fbc)"
|
||||
},
|
||||
"enableEventEnhancement": {
|
||||
"type": "boolean",
|
||||
"description": "Enable Use of HTTP Only Secure Cookie (gtmeec) to Enhance Event Data"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"type": "object"
|
||||
},
|
||||
"github.com.foomo.sesamy-cli.pkg.config.FacebookServerContainer": {
|
||||
"properties": {
|
||||
"packages": {
|
||||
"$ref": "#/$defs/[]*contemplate.PackageConfig"
|
||||
},
|
||||
"settings": {
|
||||
"$ref": "#/$defs/map[string]config.FacebookConversionAPITag"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"type": "object"
|
||||
},
|
||||
"github.com.foomo.sesamy-cli.pkg.config.GoogleAPI": {
|
||||
"properties": {
|
||||
"credentials": {
|
||||
@@ -275,13 +301,25 @@
|
||||
"description": "Enable provider"
|
||||
},
|
||||
"serverContainer": {
|
||||
"$ref": "#/$defs/github.com.foomo.sesamy-cli.pkg.config.ServerContainer",
|
||||
"$ref": "#/$defs/github.com.foomo.sesamy-cli.pkg.config.GoogleAdsConversionServerContainer",
|
||||
"description": "Google Tag Manager server container settings"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"type": "object"
|
||||
},
|
||||
"github.com.foomo.sesamy-cli.pkg.config.GoogleAdsConversionServerContainer": {
|
||||
"properties": {
|
||||
"packages": {
|
||||
"$ref": "#/$defs/[]*contemplate.PackageConfig"
|
||||
},
|
||||
"settings": {
|
||||
"$ref": "#/$defs/map[string]config.GoogleAdsConversionTracking"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"type": "object"
|
||||
},
|
||||
"github.com.foomo.sesamy-cli.pkg.config.GoogleAdsConversionTracking": {
|
||||
"properties": {
|
||||
"label": {
|
||||
@@ -483,18 +521,6 @@
|
||||
"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": {
|
||||
@@ -509,6 +535,10 @@
|
||||
"type": "string",
|
||||
"description": "Tracify customer site id"
|
||||
},
|
||||
"stagingModeEnabled": {
|
||||
"type": "boolean",
|
||||
"description": "Enable stating mode"
|
||||
},
|
||||
"googleConsent": {
|
||||
"$ref": "#/$defs/github.com.foomo.sesamy-cli.pkg.config.GoogleConsent",
|
||||
"description": "Google Consent settings"
|
||||
@@ -560,6 +590,12 @@
|
||||
"additionalProperties": false,
|
||||
"type": "object"
|
||||
},
|
||||
"map[string]config.FacebookConversionAPITag": {
|
||||
"additionalProperties": {
|
||||
"$ref": "#/$defs/github.com.foomo.sesamy-cli.pkg.config.FacebookConversionAPITag"
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"map[string]config.GoogleAdsConversionTracking": {
|
||||
"additionalProperties": {
|
||||
"$ref": "#/$defs/github.com.foomo.sesamy-cli.pkg.config.GoogleAdsConversionTracking"
|
||||
|
||||
@@ -94,6 +94,15 @@ func TestNewClient_Server(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
{ // --- Transformations ---
|
||||
t.Run("list transformations", func(t *testing.T) {
|
||||
cmd := c.Service().Accounts.Containers.Workspaces.Transformations.List(c.WorkspacePath())
|
||||
if r, err := cmd.Do(); assert.NoError(t, err) {
|
||||
dump(t, r)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
{ // --- Tags ---
|
||||
t.Run("list tags", func(t *testing.T) {
|
||||
cmd := c.Service().Accounts.Containers.Workspaces.Tags.List(c.WorkspacePath())
|
||||
@@ -113,7 +122,7 @@ func TestNewClient_Server(t *testing.T) {
|
||||
cmd := c.Service().Accounts.Containers.Workspaces.Templates.List(c.WorkspacePath())
|
||||
if r, err := cmd.Do(); assert.NoError(t, err) {
|
||||
dump(t, r)
|
||||
fmt.Println(r.Template[3].TemplateData)
|
||||
fmt.Println(r.Template[8].TemplateData)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user