Skip to content

Commit 07b9006

Browse files
committed
feat(events): add EventTypeGrantPoint and include timestamp in PostHog event captures
1 parent a48d523 commit 07b9006

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

internal/events/constants.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ const (
99
EventTypeLogoutAll EventType = "logout_all"
1010

1111
EventTypeSubmitAnswer EventType = "submit_answer"
12+
13+
// Internal usage
14+
EventTypeGrantPoint EventType = "grant_point"
1215
)

internal/events/events.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func (s *EventService) TriggerEvent(ctx context.Context, event Event) {
5353
s.posthogClient.Enqueue(posthog.Capture{
5454
DistinctId: strconv.Itoa(event.UserID),
5555
Event: string(event.Type),
56+
Timestamp: time.Now(),
5657
Properties: event.Payload,
5758
})
5859
}

internal/events/points.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ type PointsGranter struct {
5151
posthogClient posthog.Client
5252
}
5353

54-
const GRANT_POINT_EVENT = "grant_point"
55-
5654
// NewPointsGranter creates a new PointsGranter.
5755
func NewPointsGranter(entClient *ent.Client, posthogClient posthog.Client) *PointsGranter {
5856
return &PointsGranter{
@@ -418,11 +416,11 @@ func (d *PointsGranter) grantPoint(ctx context.Context, userID int, questionID i
418416
properties.Set("questionID", strconv.Itoa(questionID))
419417
}
420418

421-
slog.Debug("sending event to PostHog", "event_type", GRANT_POINT_EVENT, "user_id", userID)
419+
slog.Debug("sending event to PostHog", "event_type", EventTypeGrantPoint, "user_id", userID)
422420

423421
d.posthogClient.Enqueue(posthog.Capture{
424422
DistinctId: strconv.Itoa(userID),
425-
Event: GRANT_POINT_EVENT,
423+
Event: string(EventTypeGrantPoint),
426424
Timestamp: time.Now(),
427425
Properties: properties,
428426
})

0 commit comments

Comments
 (0)