MCPcopy
hub / github.com/CodebuffAI/codebuff / trackEvent

Function trackEvent

common/src/analytics.ts:48–93  ·  view source on GitHub ↗
({
  event,
  userId,
  properties,
  logger,
}: {
  event: AnalyticsEvent
  userId: string
  properties?: Record<string, any>
  logger: Logger
})

Source from the content-addressed store, hash-verified

46}
47
48export function trackEvent({
49 event,
50 userId,
51 properties,
52 logger,
53}: {
54 event: AnalyticsEvent
55 userId: string
56 properties?: Record<string, any>
57 logger: Logger
58}) {
59 // Don't track events in non-production environments
60 if (env.NEXT_PUBLIC_CB_ENVIRONMENT !== 'prod') {
61 if (DEBUG_ANALYTICS) {
62 logger.debug({ event, userId, properties }, `[analytics] ${event}`)
63 }
64 return
65 }
66
67 if (!client) {
68 try {
69 client = createPostHogClient(env.NEXT_PUBLIC_POSTHOG_API_KEY, {
70 host: env.NEXT_PUBLIC_POSTHOG_HOST_URL,
71 flushAt: 1,
72 flushInterval: 0,
73 })
74 } catch (error) {
75 logger.warn({ error }, 'Failed to initialize analytics client')
76 return
77 }
78 logger.info(
79 { envName: env.NEXT_PUBLIC_CB_ENVIRONMENT },
80 'Analytics client initialized',
81 )
82 }
83
84 try {
85 client.capture({
86 distinctId: userId,
87 event,
88 properties,
89 })
90 } catch (error) {
91 logger.error({ error }, 'Failed to track event')
92 }
93}

Callers 15

mainPromptFunction · 0.90
sendOrganizationAlertFunction · 0.90
consumeCreditsFunction · 0.90
handleSubscribeFunction · 0.90

Calls 2

createPostHogClientFunction · 0.90
captureMethod · 0.80

Tested by

no test coverage detected