diff --git a/customerio.go b/customerio.go index b8eaf52..54ba1e7 100644 --- a/customerio.go +++ b/customerio.go @@ -110,19 +110,20 @@ func (c *CustomerIO) Track(customerID string, eventName string, data map[string] // TrackAnonymousCtx sends a single event to Customer.io for the anonymous user func (c *CustomerIO) TrackAnonymousCtx(ctx context.Context, anonymousID, eventName string, data map[string]interface{}) error { - if anonymousID == "" { - return ParamError{Param: "anonymousID"} - } if eventName == "" { return ParamError{Param: "eventName"} } - return c.request(ctx, "POST", - fmt.Sprintf("%s/api/v1/events", c.URL), - map[string]interface{}{ - "name": eventName, - "anonymous_id": anonymousID, - "data": data, - }) + + payload := map[string]interface{}{ + "name": eventName, + "data": data, + } + + if anonymousID != "" { + payload["anonymous_id"] = anonymousID + } + + return c.request(ctx, "POST", fmt.Sprintf("%s/api/v1/events", c.URL), payload) } // TrackAnonymous sends a single event to Customer.io for the anonymous user