From 8bb42d09d9887e617cdd1ee8fae65b7292b547ef Mon Sep 17 00:00:00 2001 From: Stephen Young Date: Mon, 25 Apr 2022 17:46:29 -0400 Subject: [PATCH] pass along anonymous_id only when not blank --- customerio.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/customerio.go b/customerio.go index 33398ed..54ba1e7 100644 --- a/customerio.go +++ b/customerio.go @@ -113,13 +113,17 @@ func (c *CustomerIO) TrackAnonymousCtx(ctx context.Context, anonymousID, eventNa 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