diff --git a/integration/watermill/gtm/publisher.go b/integration/watermill/gtm/publisher.go index 2b6f5d7..37523e7 100644 --- a/integration/watermill/gtm/publisher.go +++ b/integration/watermill/gtm/publisher.go @@ -2,6 +2,7 @@ package gtm import ( "encoding/json" + "fmt" "net/http" "github.com/ThreeDotsLabs/watermill/message" @@ -83,19 +84,20 @@ func (p *Publisher) Publish(topic string, messages ...*message.Message) error { return err } + // NOTE: `richsstsse` seems to be last parameter in the query to let's ensure it stays that way var richsstsse bool if values.Has("richsstsse") { - values.Del("richsstsse") richsstsse = true + values.Del("richsstsse") } - u := p.url + "?" + url := fmt.Sprintf("%s?%s", p.url, values.Encode()) if richsstsse { - u += "&richsstsse" + url += "&richsstsse" } - req, err := http.NewRequestWithContext(msg.Context(), http.MethodPost, u, body) + req, err := http.NewRequestWithContext(msg.Context(), http.MethodPost, url, body) if err != nil { return errors.Wrap(err, "failed to create request") } diff --git a/measurementprotocol/v2/unmarshal.go b/measurementprotocol/v2/unmarshal.go index 0c36d42..1c1dec3 100644 --- a/measurementprotocol/v2/unmarshal.go +++ b/measurementprotocol/v2/unmarshal.go @@ -25,6 +25,13 @@ const ( type Data map[string]any func Marshal(input *Event) (url.Values, io.Reader, error) { + var richsstsse bool + // NOTE: `richsstsse` seems to be last parameter in the query to let's ensure it stays that way + if input.Richsstsse != nil { + richsstsse = true + input.Richsstsse = nil + } + a, err := json.Marshal(input) if err != nil { return nil, nil, err @@ -66,13 +73,22 @@ func Marshal(input *Event) (url.Values, io.Reader, error) { var body []string var reader io.Reader - for len(ret.Encode()) > 2048 { + maxQueryLength := 2048 // + if richsstsse { + maxQueryLength -= len("&richsstsse") + } + for len(ret.Encode()) > maxQueryLength { for s, i := range ret { ret.Del(s) body = append(body, s+"="+i[0]) break } } + + if richsstsse { + ret.Add("richsstsse", "") + } + if len(body) > 0 { reader = bytes.NewReader([]byte(strings.Join(body, "&"))) }