diff --git a/integration/watermill/mpv2/metadata.go b/integration/watermill/mpv2/metadata.go new file mode 100644 index 0000000..c174b14 --- /dev/null +++ b/integration/watermill/mpv2/metadata.go @@ -0,0 +1,5 @@ +package mpv2 + +const ( + MetadataRequestQuery = "RequestQuery" +) diff --git a/integration/watermill/mpv2/publisher.go b/integration/watermill/mpv2/publisher.go index 738fdf0..425d74f 100644 --- a/integration/watermill/mpv2/publisher.go +++ b/integration/watermill/mpv2/publisher.go @@ -119,17 +119,20 @@ func (p *Publisher) handle(l *zap.Logger, msg *message.Message) error { return errors.Wrap(err, "failed to create request") } - for s, s2 := range msg.Metadata { - if s == "Cookie" { - for _, s3 := range strings.Split(s2, "; ") { + for key, value := range msg.Metadata { + switch key { + case "Cookie": + for _, s3 := range strings.Split(value, "; ") { val := strings.Split(s3, "=") req.AddCookie(&http.Cookie{ Name: val[0], Value: strings.Join(val[1:], "="), }) } - } else { - req.Header.Set(s, s2) + case MetadataRequestQuery: + req.URL.RawQuery = value + default: + req.Header.Set(key, value) } } diff --git a/integration/watermill/mpv2/subscriber.go b/integration/watermill/mpv2/subscriber.go index 543e66e..e9b0a8a 100644 --- a/integration/watermill/mpv2/subscriber.go +++ b/integration/watermill/mpv2/subscriber.go @@ -119,6 +119,10 @@ func (s *Subscriber) handle(l *zap.Logger, r *http.Request, payload *mpv2.Payloa l = l.With(zap.String("message_id", msg.UUID)) msg.SetContext(context.WithoutCancel(r.Context())) + // store query + msg.Metadata.Set(MetadataRequestQuery, r.URL.RawQuery) + + // store header for name, headers := range r.Header { msg.Metadata.Set(name, strings.Join(headers, ",")) } diff --git a/pkg/client/mpv2.go b/pkg/client/mpv2.go index 772ec9a..8bc797a 100644 --- a/pkg/client/mpv2.go +++ b/pkg/client/mpv2.go @@ -16,11 +16,15 @@ import ( type ( MPv2 struct { - l *zap.Logger - path string - host string - cookies []string - apiSecret string + l *zap.Logger + path string + host string + cookies []string + // To create a new secret, navigate in the Google Analytics UI to: + // Admin > Data Streams > choose your stream > Measurement Protocol > Create + apiSecret string + // Measurement ID. The identifier for a Data Stream. Found in the Google Analytics UI under: + // Admin > Data Streams > choose your stream > Measurement ID measurementID string protocolVersion string httpClient *http.Client @@ -139,6 +143,7 @@ func (c *MPv2) SendRaw(r *http.Request, payload *mpv2.Payload[any]) error { return errors.Wrap(err, "failed to create request") } + // query qry := req.URL.Query() if len(c.apiSecret) > 0 { qry.Add("api_secret", c.apiSecret)