Skip to content

Commit cd09f7d

Browse files
committed
track analytics for sse endpoint
1 parent 059f44a commit cd09f7d

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

common/src/constants/analytics-events.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export enum AnalyticsEvent {
3636

3737
// Web
3838
SIGNUP = 'web.signup',
39+
SSE_ENDPOINT_REQUEST = 'web.sse_endpoint_request',
3940

4041
// Web - Authentication
4142
AUTH_LOGIN_STARTED = 'auth.login_started',

web/src/app/api/v1/chat/completions/route.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { getUserUsageData } from '@codebuff/billing/usage-service'
2+
import { trackEvent } from '@codebuff/common/analytics'
3+
import { AnalyticsEvent } from '@codebuff/common/constants/analytics-events'
24
import { getErrorObject } from '@codebuff/common/util/error'
35
import { NextResponse } from 'next/server'
46

@@ -29,6 +31,16 @@ export async function POST(req: NextRequest) {
2931
}
3032

3133
const userId = userInfo.id
34+
35+
trackEvent({
36+
event: AnalyticsEvent.SSE_ENDPOINT_REQUEST,
37+
properties: {
38+
body,
39+
},
40+
userId,
41+
logger,
42+
})
43+
3244
const {
3345
balance: { totalRemaining },
3446
nextQuotaReset,

0 commit comments

Comments
 (0)