From 8fada67bcd123a55bb2f28244a3f85feb25c4182 Mon Sep 17 00:00:00 2001 From: Kevin Franklin Kim Date: Mon, 27 May 2024 10:57:39 +0200 Subject: [PATCH] wip: add debug mode middleware --- integration/watermill/gtag/publisher.go | 17 +-- integration/watermill/mpv2/publisher.go | 137 ++++++++++-------- .../watermill/mpv2/publishermiddleware.go | 23 +++ integration/watermill/mpv2/subscriber.go | 4 + .../watermill/mpv2/subscribermiddleware.go | 9 ++ pkg/client/mpv2.go | 6 - pkg/client/mpv2middleware.go | 9 ++ pkg/encoding/gtag/decode_test.go | 16 +- pkg/encoding/mpv2/payload.go | 1 + 9 files changed, 142 insertions(+), 80 deletions(-) create mode 100644 integration/watermill/mpv2/publishermiddleware.go diff --git a/integration/watermill/gtag/publisher.go b/integration/watermill/gtag/publisher.go index 930cfaa..7899ef4 100644 --- a/integration/watermill/gtag/publisher.go +++ b/integration/watermill/gtag/publisher.go @@ -20,12 +20,11 @@ var ( type ( Publisher struct { - l *zap.Logger - host string - path string - client *http.Client - marshalMessageFunc PublisherMarshalMessageFunc - closed bool + l *zap.Logger + host string + path string + client *http.Client + closed bool } PublisherOption func(*Publisher) // PublisherMarshalMessageFunc transforms the message into a HTTP request to be sent to the specified url. @@ -65,12 +64,6 @@ func PublisherWithClient(v *http.Client) PublisherOption { } } -func PublisherWithMarshalMessageFunc(v PublisherMarshalMessageFunc) PublisherOption { - return func(o *Publisher) { - o.marshalMessageFunc = v - } -} - // ------------------------------------------------------------------------------------------------ // ~ Getter // ------------------------------------------------------------------------------------------------ diff --git a/integration/watermill/mpv2/publisher.go b/integration/watermill/mpv2/publisher.go index adfb406..738fdf0 100644 --- a/integration/watermill/mpv2/publisher.go +++ b/integration/watermill/mpv2/publisher.go @@ -14,16 +14,16 @@ import ( type ( Publisher struct { - l *zap.Logger - host string - path string - client *http.Client - marshalMessageFunc PublisherMarshalMessageFunc - closed bool + l *zap.Logger + host string + path string + httpClient *http.Client + middlewares []PublisherMiddleware + closed bool } - PublisherOption func(*Publisher) - // PublisherMarshalMessageFunc transforms the message into a HTTP request to be sent to the specified url. - PublisherMarshalMessageFunc func(url string, msg *message.Message) (*http.Request, error) + PublisherOption func(*Publisher) + PublisherHandler func(l *zap.Logger, msg *message.Message) error + PublisherMiddleware func(next PublisherHandler) PublisherHandler ) // ------------------------------------------------------------------------------------------------ @@ -32,10 +32,10 @@ type ( func NewPublisher(l *zap.Logger, host string, opts ...PublisherOption) *Publisher { inst := &Publisher{ - l: l, - host: host, - path: "/mp/collect", - client: http.DefaultClient, + l: l, + host: host, + path: "/mp/collect", + httpClient: http.DefaultClient, } for _, opt := range opts { opt(inst) @@ -53,15 +53,15 @@ func PublisherWithPath(v string) PublisherOption { } } -func PublisherWithClient(v *http.Client) PublisherOption { +func PublisherWithHTTPClient(v *http.Client) PublisherOption { return func(o *Publisher) { - o.client = v + o.httpClient = v } } -func PublisherWithMarshalMessageFunc(v PublisherMarshalMessageFunc) PublisherOption { +func PublisherWithMiddlewares(v ...PublisherMiddleware) PublisherOption { return func(o *Publisher) { - o.marshalMessageFunc = v + o.middlewares = append(o.middlewares, v...) } } @@ -69,8 +69,8 @@ func PublisherWithMarshalMessageFunc(v PublisherMarshalMessageFunc) PublisherOpt // ~ Getter // ------------------------------------------------------------------------------------------------ -func (p *Publisher) Client() *http.Client { - return p.client +func (p *Publisher) HTTPClient() *http.Client { + return p.httpClient } // ------------------------------------------------------------------------------------------------ @@ -83,50 +83,16 @@ func (p *Publisher) Publish(topic string, messages ...*message.Message) error { } for _, msg := range messages { - req, err := http.NewRequestWithContext(msg.Context(), http.MethodPost, fmt.Sprintf("%s%s", p.host, p.path), bytes.NewReader(msg.Payload)) - if err != nil { - return errors.Wrap(err, "failed to create request") + // compose middlewares + next := p.handle + for _, middleware := range p.middlewares { + next = middleware(next) } - for s, s2 := range msg.Metadata { - if s == "Cookie" { - for _, s3 := range strings.Split(s2, "; ") { - val := strings.Split(s3, "=") - req.AddCookie(&http.Cookie{ - Name: val[0], - Value: strings.Join(val[1:], "="), - }) - } - } else { - req.Header.Set(s, s2) - } - } - - l := p.l.With( + // run handler + if err := next(p.l.With( zap.String("message_id", msg.UUID), - ) - - if err := func() error { - resp, err := p.client.Do(req) - if err != nil { - return errors.Wrapf(err, "failed to publish message: %s", msg.UUID) - } - defer resp.Body.Close() - - l = l.With(zap.Int("http_status_code", resp.StatusCode)) - - if resp.StatusCode >= http.StatusBadRequest { - if body, err := io.ReadAll(resp.Body); err == nil { - l = l.With(zap.String("http_response", string(body))) - } - l.Warn("server responded with error") - return errors.Wrap(ErrErrorResponse, resp.Status) - } - - l.Debug("message published") - - return nil - }(); err != nil { + ), msg); err != nil { return err } } @@ -142,3 +108,54 @@ func (p *Publisher) Close() error { p.closed = true return nil } + +// ------------------------------------------------------------------------------------------------ +// ~ Private methods +// ------------------------------------------------------------------------------------------------ + +func (p *Publisher) handle(l *zap.Logger, msg *message.Message) error { + req, err := http.NewRequestWithContext(msg.Context(), http.MethodPost, fmt.Sprintf("%s%s", p.host, p.path), bytes.NewReader(msg.Payload)) + if err != nil { + return errors.Wrap(err, "failed to create request") + } + + for s, s2 := range msg.Metadata { + if s == "Cookie" { + for _, s3 := range strings.Split(s2, "; ") { + val := strings.Split(s3, "=") + req.AddCookie(&http.Cookie{ + Name: val[0], + Value: strings.Join(val[1:], "="), + }) + } + } else { + req.Header.Set(s, s2) + } + } + + if err := func() error { + resp, err := p.httpClient.Do(req) + if err != nil { + return errors.Wrapf(err, "failed to publish message: %s", msg.UUID) + } + defer resp.Body.Close() + + l = l.With(zap.Int("http_status_code", resp.StatusCode)) + + if resp.StatusCode >= http.StatusBadRequest { + if body, err := io.ReadAll(resp.Body); err == nil { + l = l.With(zap.String("http_response", string(body))) + } + l.Warn("server responded with error") + return errors.Wrap(ErrErrorResponse, resp.Status) + } + + l.Debug("message published") + + return nil + }(); err != nil { + return err + } + + return nil +} diff --git a/integration/watermill/mpv2/publishermiddleware.go b/integration/watermill/mpv2/publishermiddleware.go new file mode 100644 index 0000000..81521b5 --- /dev/null +++ b/integration/watermill/mpv2/publishermiddleware.go @@ -0,0 +1,23 @@ +package mpv2 + +import ( + "encoding/json" + + "github.com/ThreeDotsLabs/watermill/message" + "github.com/davecgh/go-spew/spew" + "github.com/foomo/sesamy-go/pkg/encoding/mpv2" + "go.uber.org/zap" +) + +func PublisherMiddlewareDebugMode(next PublisherHandler) PublisherHandler { + return func(l *zap.Logger, msg *message.Message) error { + var payload *mpv2.Payload[any] + if err := json.Unmarshal(msg.Payload, &payload); err != nil { + return err + } + if payload.DebugMode { + spew.Dump(payload.Events) + } + return next(l, msg) + } +} diff --git a/integration/watermill/mpv2/subscriber.go b/integration/watermill/mpv2/subscriber.go index 828fc8d..1cc998c 100644 --- a/integration/watermill/mpv2/subscriber.go +++ b/integration/watermill/mpv2/subscriber.go @@ -58,6 +58,10 @@ func NewSubscriber(l *zap.Logger, opts ...SubscriberOption) *Subscriber { return inst } +// ------------------------------------------------------------------------------------------------ +// ~ Public methods +// ------------------------------------------------------------------------------------------------ + func (s *Subscriber) ServeHTTP(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodPost { http.Error(w, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed) diff --git a/integration/watermill/mpv2/subscribermiddleware.go b/integration/watermill/mpv2/subscribermiddleware.go index bc51b0d..de91fc4 100644 --- a/integration/watermill/mpv2/subscribermiddleware.go +++ b/integration/watermill/mpv2/subscribermiddleware.go @@ -34,6 +34,15 @@ func SubscriberMiddlewareUserID(cookieName string) SubscriberMiddleware { } } +func SubscriberMiddlewareDebugMode(next SubscriberHandler) SubscriberHandler { + return func(l *zap.Logger, r *http.Request, payload *mpv2.Payload[any]) error { + if session.IsGTMDebug(r) { + payload.DebugMode = true + } + return next(l, r, payload) + } +} + func SubscriberMiddlewareTimestamp(next SubscriberHandler) SubscriberHandler { return func(l *zap.Logger, r *http.Request, payload *mpv2.Payload[any]) error { payload.TimestampMicros = time.Now().UnixMicro() diff --git a/pkg/client/mpv2.go b/pkg/client/mpv2.go index e21d8c8..1d02b06 100644 --- a/pkg/client/mpv2.go +++ b/pkg/client/mpv2.go @@ -6,7 +6,6 @@ import ( "fmt" "io" "net/http" - "reflect" "time" "github.com/foomo/sesamy-go/pkg/encoding/mpv2" @@ -95,11 +94,6 @@ func (c *MPv2) HTTPClient() *http.Client { func (c *MPv2) Collect(r *http.Request, events ...sesamy.AnyEvent) error { anyEvents := make([]sesamy.Event[any], len(events)) for i, event := range events { - fmt.Println("-----------") - t := reflect.TypeOf(event) - x := reflect.New(t) - fmt.Println(x) - fmt.Println("-----------") anyEvents[i] = event.AnyEvent() } diff --git a/pkg/client/mpv2middleware.go b/pkg/client/mpv2middleware.go index 3194256..6326941 100644 --- a/pkg/client/mpv2middleware.go +++ b/pkg/client/mpv2middleware.go @@ -20,3 +20,12 @@ func MPv2MiddlewarClientID(next MPv2Handler) MPv2Handler { return next(r, payload) } } + +func MPv2MiddlewarDebugMode(next MPv2Handler) MPv2Handler { + return func(r *http.Request, payload *mpv2.Payload[any]) error { + if session.IsGTMDebug(r) { + payload.DebugMode = true + } + return next(r, payload) + } +} diff --git a/pkg/encoding/gtag/decode_test.go b/pkg/encoding/gtag/decode_test.go index fd8a8dd..33f93e0 100644 --- a/pkg/encoding/gtag/decode_test.go +++ b/pkg/encoding/gtag/decode_test.go @@ -13,6 +13,18 @@ import ( "github.com/stretchr/testify/require" ) +const ( + GTagAddPaymentInfo = "v=2&tid=G-F9XM71K45T>m=45he45m0v9184715813z89184708445za200zb9184708445&_p=1716795486104&_dbg=1&gcd=13l3l3l2l1&npa=1&dma_cps=sypham&dma=1&cid=179294588.1715353601&ecid=788548699&ul=en-us&sr=2056x1329&_fplc=0&ur=&uaa=arm&uab=64&uafvl=Chromium%3B124.0.6367.201%7CGoogle%2520Chrome%3B124.0.6367.201%7CNot-A.Brand%3B99.0.0.0&uamb=0&uam=&uap=macOS&uapv=14.4.1&uaw=0&are=1&frm=0&pscdl=noapi&sst.gcd=13l3l3l2l1&sst.tft=1716795486104&sst.ude=0&_s=2&cu=USD&sid=1716793773&sct=14&seg=1&dl=https%3A%2F%2Fsesamy.local.bestbytes.net%2F%3Fgtm_debug%3D1716795486020&dr=https%3A%2F%2Ftagassistant.google.com%2F&dt=Home&en=add_payment_info&pr1=idSKU_12345~nmStan%20and%20Friends%20Tee~afGoogle%20Merchandise%20Store~cpSUMMER_FUN~ds2.22~lp0~brGoogle~caApparel~c2Adult~c3Shirts~c4Crew~c5Short%20sleeve~lirelated_products~lnRelated%20Products~vagreen~loChIJIQBpAG2ahYAR_6128GcTUEo~pr10.01~qt3&ep.enable_page_views=false&ep.coupon=SUMMER_FUN&ep.payment_type=Credit%20Card&epn.value=30.03&_et=169&tfd=28197&richsstsse" + GTagAddShippingInfo = "v=2&tid=G-F9XM71K45T>m=45he45m0v9184715813z89184708445za200zb9184708445&_p=1716795486104&_dbg=1&gcd=13l3l3l2l1&npa=1&dma_cps=sypham&dma=1&cid=179294588.1715353601&ecid=788548699&ul=en-us&sr=2056x1329&_fplc=0&ur=&uaa=arm&uab=64&uafvl=Chromium%3B124.0.6367.201%7CGoogle%2520Chrome%3B124.0.6367.201%7CNot-A.Brand%3B99.0.0.0&uamb=0&uam=&uap=macOS&uapv=14.4.1&uaw=0&are=1&frm=0&pscdl=noapi&sst.gcd=13l3l3l2l1&sst.tft=1716795486104&sst.ude=0&_s=3&cu=USD&sid=1716793773&sct=14&seg=1&dl=https%3A%2F%2Fsesamy.local.bestbytes.net%2F%3Fgtm_debug%3D1716795486020&dr=https%3A%2F%2Ftagassistant.google.com%2F&dt=Home&en=add_shipping_info&pr1=idSKU_12345~nmStan%20and%20Friends%20Tee~afGoogle%20Merchandise%20Store~cpSUMMER_FUN~ds2.22~lp0~brGoogle~caApparel~c2Adult~c3Shirts~c4Crew~c5Short%20sleeve~lirelated_products~lnRelated%20Products~vagreen~loChIJIQBpAG2ahYAR_6128GcTUEo~pr10.01~qt3&ep.enable_page_views=false&ep.coupon=SUMMER_FUN&ep.shipping_tier=Ground&epn.value=30.03&_et=2112&tfd=114276&richsstsse" + GTagAddToCart = "v=2&tid=G-F9XM71K45T>m=45he45m0v9184715813z89184708445za200zb9184708445&_p=1716795486104&_dbg=1&gcd=13l3l3l2l1&npa=1&dma_cps=sypham&dma=1&cid=179294588.1715353601&ecid=788548699&ul=en-us&sr=2056x1329&_fplc=0&ur=&uaa=arm&uab=64&uafvl=Chromium%3B124.0.6367.201%7CGoogle%2520Chrome%3B124.0.6367.201%7CNot-A.Brand%3B99.0.0.0&uamb=0&uam=&uap=macOS&uapv=14.4.1&uaw=0&are=1&frm=0&pscdl=noapi&sst.gcd=13l3l3l2l1&sst.tft=1716795486104&sst.ude=0&_s=4&cu=USD&sid=1716793773&sct=14&seg=1&dl=https%3A%2F%2Fsesamy.local.bestbytes.net%2F%3Fgtm_debug%3D1716795486020&dr=https%3A%2F%2Ftagassistant.google.com%2F&dt=Home&en=add_to_cart&pr1=idSKU_12345~nmStan%20and%20Friends%20Tee~afGoogle%20Merchandise%20Store~cpSUMMER_FUN~ds2.22~lp0~brGoogle~caApparel~c2Adult~c3Shirts~c4Crew~c5Short%20sleeve~lirelated_products~lnRelated%20Products~vagreen~loChIJIQBpAG2ahYAR_6128GcTUEo~pr10.01~qt3&ep.enable_page_views=false&epn.value=30.03&_et=1255&tfd=145479&richsstsse" + GTagAddToWishlist = "v=2&tid=G-F9XM71K45T>m=45he45m0v9184715813z89184708445za200zb9184708445&_p=1716795486104&_dbg=1&gcd=13l3l3l2l1&npa=1&dma_cps=sypham&dma=1&cid=179294588.1715353601&ecid=788548699&ul=en-us&sr=2056x1329&_fplc=0&ur=&uaa=arm&uab=64&uafvl=Chromium%3B124.0.6367.201%7CGoogle%2520Chrome%3B124.0.6367.201%7CNot-A.Brand%3B99.0.0.0&uamb=0&uam=&uap=macOS&uapv=14.4.1&uaw=0&are=1&frm=0&pscdl=noapi&sst.gcd=13l3l3l2l1&sst.tft=1716795486104&sst.ude=0&_s=5&cu=USD&sid=1716793773&sct=14&seg=1&dl=https%3A%2F%2Fsesamy.local.bestbytes.net%2F%3Fgtm_debug%3D1716795486020&dr=https%3A%2F%2Ftagassistant.google.com%2F&dt=Home&en=add_to_wishlist&pr1=idSKU_12345~nmStan%20and%20Friends%20Tee~afGoogle%20Merchandise%20Store~cpSUMMER_FUN~ds2.22~lp0~brGoogle~caApparel~c2Adult~c3Shirts~c4Crew~c5Short%20sleeve~lirelated_products~lnRelated%20Products~vagreen~loChIJIQBpAG2ahYAR_6128GcTUEo~pr10.01~qt3&ep.enable_page_views=false&epn.value=30.03&_et=2081&tfd=175581&richsstsse" + GTagAddBeginCheckout = "v=2&tid=G-F9XM71K45T>m=45he45m0v9184715813z89184708445za200zb9184708445&_p=1716795486104&_dbg=1&gcd=13l3l3l2l1&npa=1&dma_cps=sypham&dma=1&cid=179294588.1715353601&ecid=788548699&ul=en-us&sr=2056x1329&_fplc=0&ur=&uaa=arm&uab=64&uafvl=Chromium%3B124.0.6367.201%7CGoogle%2520Chrome%3B124.0.6367.201%7CNot-A.Brand%3B99.0.0.0&uamb=0&uam=&uap=macOS&uapv=14.4.1&uaw=0&are=1&frm=0&pscdl=noapi&sst.gcd=13l3l3l2l1&sst.tft=1716795486104&sst.ude=0&_s=6&cu=USD&sid=1716793773&sct=14&seg=1&dl=https%3A%2F%2Fsesamy.local.bestbytes.net%2F%3Fgtm_debug%3D1716795486020&dr=https%3A%2F%2Ftagassistant.google.com%2F&dt=Home&en=begin_checkout&pr1=idSKU_12345~nmStan%20and%20Friends%20Tee~afGoogle%20Merchandise%20Store~cpSUMMER_FUN~ds2.22~lp0~brGoogle~caApparel~c2Adult~c3Shirts~c4Crew~c5Short%20sleeve~lirelated_products~lnRelated%20Products~vagreen~loChIJIQBpAG2ahYAR_6128GcTUEo~pr10.01~qt3&ep.enable_page_views=false&ep.coupon=SUMMER_FUN&epn.value=30.03&_et=1649&tfd=210309&richsstsse" + GTagGenerateLead = "v=2&tid=G-F9XM71K45T>m=45he45m0v9184715813z89184708445za200zb9184708445&_p=1716795486104&_dbg=1&gcd=13l3l3l2l1&npa=1&dma_cps=sypham&dma=1&cid=179294588.1715353601&ecid=788548699&ul=en-us&sr=2056x1329&_fplc=0&ur=&uaa=arm&uab=64&uafvl=Chromium%3B124.0.6367.201%7CGoogle%2520Chrome%3B124.0.6367.201%7CNot-A.Brand%3B99.0.0.0&uamb=0&uam=&uap=macOS&uapv=14.4.1&uaw=0&are=1&frm=0&pscdl=noapi&sst.gcd=13l3l3l2l1&sst.tft=1716795486104&sst.ude=0&_s=7&cu=USD&sid=1716793773&sct=14&seg=1&dl=https%3A%2F%2Fsesamy.local.bestbytes.net%2F%3Fgtm_debug%3D1716795486020&dr=https%3A%2F%2Ftagassistant.google.com%2F&dt=Home&en=generate_lead&ep.enable_page_views=false&epn.value=99.99&_et=1680&tfd=247472&richsstsse" + GTagJoinGroup = "v=2&tid=G-F9XM71K45T>m=45he45m0v9184715813z89184708445za200zb9184708445&_p=1716795486104&_dbg=1&gcd=13l3l3l2l1&npa=1&dma_cps=sypham&dma=1&cid=179294588.1715353601&ecid=788548699&ul=en-us&sr=2056x1329&_fplc=0&ur=&uaa=arm&uab=64&uafvl=Chromium%3B124.0.6367.201%7CGoogle%2520Chrome%3B124.0.6367.201%7CNot-A.Brand%3B99.0.0.0&uamb=0&uam=&uap=macOS&uapv=14.4.1&uaw=0&are=1&frm=0&pscdl=noapi&sst.gcd=13l3l3l2l1&sst.tft=1716795486104&sst.ude=0&_s=8&sid=1716793773&sct=14&seg=1&dl=https%3A%2F%2Fsesamy.local.bestbytes.net%2F%3Fgtm_debug%3D1716795486020&dr=https%3A%2F%2Ftagassistant.google.com%2F&dt=Home&en=join_group&ep.enable_page_views=false&ep.group_id=G_12345&_et=1510&tfd=265924&richsstsse" + GTagLevelEnd = "v=2&tid=G-F9XM71K45T>m=45he45m0v9184715813z89184708445za200zb9184708445&_p=1716795486104&_dbg=1&gcd=13l3l3l2l1&npa=1&dma_cps=sypham&dma=1&cid=179294588.1715353601&ecid=788548699&ul=en-us&sr=2056x1329&_fplc=0&ur=&uaa=arm&uab=64&uafvl=Chromium%3B124.0.6367.201%7CGoogle%2520Chrome%3B124.0.6367.201%7CNot-A.Brand%3B99.0.0.0&uamb=0&uam=&uap=macOS&uapv=14.4.1&uaw=0&are=1&frm=0&pscdl=noapi&sst.gcd=13l3l3l2l1&sst.tft=1716795486104&sst.ude=0&_s=9&sid=1716793773&sct=14&seg=1&dl=https%3A%2F%2Fsesamy.local.bestbytes.net%2F%3Fgtm_debug%3D1716795486020&dr=https%3A%2F%2Ftagassistant.google.com%2F&dt=Home&en=level_end&ep.enable_page_views=false&ep.level_name=The%20journey%20begins...&ep.success=true&_et=2950&tfd=296976&richsstsse" + GTagLevelStart = "v=2&tid=G-F9XM71K45T>m=45he45m0v9184715813z89184708445za200zb9184708445&_p=1716795486104&_dbg=1&gcd=13l3l3l2l1&npa=1&dma_cps=sypham&dma=1&cid=179294588.1715353601&ecid=788548699&ul=en-us&sr=2056x1329&_fplc=0&ur=&uaa=arm&uab=64&uafvl=Chromium%3B124.0.6367.201%7CGoogle%2520Chrome%3B124.0.6367.201%7CNot-A.Brand%3B99.0.0.0&uamb=0&uam=&uap=macOS&uapv=14.4.1&uaw=0&are=1&frm=0&pscdl=noapi&sst.gcd=13l3l3l2l1&sst.tft=1716795486104&sst.ude=0&_s=10&sid=1716793773&sct=14&seg=1&dl=https%3A%2F%2Fsesamy.local.bestbytes.net%2F%3Fgtm_debug%3D1716795486020&dr=https%3A%2F%2Ftagassistant.google.com%2F&dt=Home&en=level_start&ep.enable_page_views=false&ep.level_name=The%20journey%20begins...&_et=1266&tfd=321602&richsstsse" +) + func TestDecode(t *testing.T) { testingx.Tags(t, tagx.Short) @@ -28,8 +40,8 @@ func TestDecode(t *testing.T) { }, { name: "add_to_cart", - args: "v=2&tid=G-123456>m=45je42s0v9175354889z89175348963za200&_p=1709297934217&_dbg=1&gcd=13l3l3l3l1&npa=0&dma_cps=sypham&dma=1&cid=1220643501.1708014725&ul=en-us&sr=3840x1600&_fplc=0&ur=DE-BY&uaa=arm&uab=64&uafvl=Chromium&uamb=0&uam=&uap=macOS&uapv=14.3.1&uaw=0&are=1&pscdl=noapi&_eu=IA&sst.uc=DE&sst.etld=google.de&sst.gcsub=region1&sst.gcd=13l3l3l3l1&sst.tft=1709297934217&_s=8&cu=USD&sid=1709296380&sct=7&seg=1&dl=https%3A%2F%2Fsniffer.cloud.bestbytes.net%2F%3Fgtm_debug%3D1709297933868&dr=https%3A%2F%2Ftagassistant.google.com%2F&dt=Server%20Side%20Tracking%20Prototype%20(codename%3A%20sniffer)&en=add_to_cart&pr1=idSKU_12345~nmStan%20and%20Friends%20Tee~afGoogle%20Store~cpSUMMER_FUN~ds2.22~lp5~brGoogle~caApparel~c2Adult~c3Shirts~c4Crew~c5Short%20sleeve~lirelated_products~lnRelated%20products~vagreen~loChIJIQBpAG2ahYAR_6128GcTUEo~pr10.01~qt3&epn.value=30.03&tfd=15129&richsstsse", - want: `{"consent":{"google_consent_default":"13l3l3l3l1"},"campaign":{},"ecommerce":{"currency":"USD","items":[{"affiliation":"Google Store","coupon":"SUMMER_FUN","discount":"2.22","item_brand":"Google","item_category":"Apparel","item_category2":"Adult","item_category3":"Shirts","item_category4":"Crew","item_category5":"Short sleeve","item_id":"SKU_12345","item_list_id":"related_products","item_list_name":"Related products","item_name":"Stan and Friends Tee","item_variant":"green","item_list_position":"5","location_id":"ChIJIQBpAG2ahYAR_6128GcTUEo","price":"10.01","quantity":"3"}]},"client_hints":{"screen_resolution":"3840x1600","user_language":"en-us","user_agent_architecture":"arm","user_agent_bitness":"64","user_agent_full_version_list":"Chromium","user_agent_mobile":"0","user_agent_model":"","user_agent_platform":"macOS","user_agent_platform_version":"14.3.1","user_agent_wow_64":"0","user_region":"DE-BY"},"protocol_version":"2","tracking_id":"G-123456","gtmhash_info":"45je42s0v9175354889z89175348963za200","is_debug":"1","client_id":"1220643501.1708014725","richsstsse":"","document_location":"https://sniffer.cloud.bestbytes.net/?gtm_debug=1709297933868","document_title":"Server Side Tracking Prototype (codename: sniffer)","document_referrer":"https://tagassistant.google.com/","event_name":"add_to_cart","event_parameter_number":{"value":"30.03"},"session_id":"1709296380","non_personalized_ads":"0","sst":{"etld":"google.de","gcsub":"region1","uc":"DE","tft":"1709297934217","gcd":"13l3l3l3l1"}}`, + args: GTagAddToCart, + want: `{"consent":{"google_consent_default":"13l3l3l2l1"},"campaign":{},"ecommerce":{"currency":"USD","items":[{"affiliation":"Google Merchandise Store","coupon":"SUMMER_FUN","discount":"2.22","item_brand":"Google","item_category":"Apparel","item_category2":"Adult","item_category3":"Shirts","item_category4":"Crew","item_category5":"Short sleeve","item_id":"SKU_12345","item_list_id":"related_products","item_list_name":"Related Products","item_name":"Stan and Friends Tee","item_variant":"green","item_list_position":"0","location_id":"ChIJIQBpAG2ahYAR_6128GcTUEo","price":"10.01","quantity":"3"}]},"client_hints":{"screen_resolution":"2056x1329","user_language":"en-us","user_agent_architecture":"arm","user_agent_bitness":"64","user_agent_full_version_list":"Chromium;124.0.6367.201|Google%20Chrome;124.0.6367.201|Not-A.Brand;99.0.0.0","user_agent_mobile":"0","user_agent_model":"","user_agent_platform":"macOS","user_agent_platform_version":"14.4.1","user_agent_wow_64":"0","user_region":""},"protocol_version":"2","tracking_id":"G-F9XM71K45T","gtmhash_info":"45he45m0v9184715813z89184708445za200zb9184708445","client_id":"179294588.1715353601","richsstsse":"","document_location":"https://sesamy.local.bestbytes.net/?gtm_debug=1716795486020","document_title":"Home","document_referrer":"https://tagassistant.google.com/","is_debug":"1","event_name":"add_to_cart","event_parameter":{"enable_page_views":"false"},"event_parameter_number":{"value":"30.03"},"session_id":"1716793773","non_personalized_ads":"1","sst":{"tft":"1716795486104","gcd":"13l3l3l2l1","ude":"0"}}`, }, { name: "select_item", diff --git a/pkg/encoding/mpv2/payload.go b/pkg/encoding/mpv2/payload.go index 5d0eb3d..a61531a 100644 --- a/pkg/encoding/mpv2/payload.go +++ b/pkg/encoding/mpv2/payload.go @@ -14,4 +14,5 @@ type Payload[P any] struct { NonPersonalizedAds bool `json:"non_personalized_ads,omitempty"` Events []sesamy.Event[P] `json:"events,omitempty"` UserData *UserData `json:"user_data,omitempty"` + DebugMode bool `json:"debug_mode,omitempty"` }