From 96437bf4c05b85b9e309f44d6d54c2bf561ba8a7 Mon Sep 17 00:00:00 2001 From: Stephen Young Date: Fri, 22 Apr 2022 14:14:05 -0400 Subject: [PATCH 1/2] allow blank anonymous ids --- customerio.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/customerio.go b/customerio.go index b8eaf52..33398ed 100644 --- a/customerio.go +++ b/customerio.go @@ -110,9 +110,6 @@ 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"} } From 8bb42d09d9887e617cdd1ee8fae65b7292b547ef Mon Sep 17 00:00:00 2001 From: Stephen Young Date: Mon, 25 Apr 2022 17:46:29 -0400 Subject: [PATCH 2/2] 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