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 }