From 424209444ffb2890ccc41401fa39d4f2e36d4dd1 Mon Sep 17 00:00:00 2001 From: "mojo-machine[bot]" <111131124+mojo-machine[bot]@users.noreply.github.com> Date: Wed, 15 May 2024 14:10:27 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=84=20Sync=20from=20monorepo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/wearemojo/mojo/commit/576647ee7ab204fa108c22336c6167939c7d36cd --- lib/datahappy/datahappy.go | 4 +++- lib/datahappy/track.go | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/datahappy/datahappy.go b/lib/datahappy/datahappy.go index 7e373cd..6efe9b9 100644 --- a/lib/datahappy/datahappy.go +++ b/lib/datahappy/datahappy.go @@ -16,16 +16,18 @@ var library = &Library{ type Client struct { client *jsonclient.Client + ProjectID string AuthToken string } -func NewClient(baseURL, authToken string) *Client { +func NewClient(baseURL, projectID, authToken string) *Client { return &Client{ client: jsonclient.NewClient( baseURL, httpclient.NewClient(5*time.Second, nil), ), + ProjectID: projectID, AuthToken: authToken, } } diff --git a/lib/datahappy/track.go b/lib/datahappy/track.go index 6bdef98..8059078 100644 --- a/lib/datahappy/track.go +++ b/lib/datahappy/track.go @@ -17,6 +17,7 @@ const ( ) type TrackRequest struct { + ProjectID string `json:"projectId"` Type RequestType `json:"type"` AnonymousID string `json:"anonymousId,omitempty"` UserID string `json:"userId,omitempty"` @@ -34,6 +35,10 @@ func (c *Client) Track(ctx context.Context, req *TrackRequest) error { // ensure no mutation of the original request req = ptr.ShallowCopy(req) + if req.ProjectID == "" { + req.ProjectID = c.ProjectID + } + if req.Type == "" { req.Type = RequestTypeTrack }