MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / initAnalytics

Function initAnalytics

cli/src/utils/analytics.ts:136–164  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

134}
135
136export function initAnalytics() {
137 const { env, isProd, createClient, generateAnonymousId } = resolveDeps()
138
139 if (!env.NEXT_PUBLIC_POSTHOG_API_KEY || !env.NEXT_PUBLIC_POSTHOG_HOST_URL) {
140 const error = new Error(
141 'NEXT_PUBLIC_POSTHOG_API_KEY or NEXT_PUBLIC_POSTHOG_HOST_URL is not set',
142 )
143 logAnalyticsError(error, {
144 stage: AnalyticsErrorStage.Init,
145 missingEnv: true,
146 })
147 throw error
148 }
149
150 // Generate anonymous ID for pre-login tracking
151 // PostHog will merge this with the real user ID via alias() when user logs in
152 anonymousId = generateAnonymousId()
153 identified = false
154
155 try {
156 client = createClient(env.NEXT_PUBLIC_POSTHOG_API_KEY, {
157 host: env.NEXT_PUBLIC_POSTHOG_HOST_URL,
158 enableExceptionAutocapture: isProd,
159 })
160 } catch (error) {
161 logAnalyticsError(error, { stage: AnalyticsErrorStage.Init })
162 throw error
163 }
164}
165
166export async function flushAnalytics() {
167 if (!client) {

Callers 2

initializeAppFunction · 0.90

Calls 3

generateAnonymousIdFunction · 0.90
resolveDepsFunction · 0.85
logAnalyticsErrorFunction · 0.85

Tested by

no test coverage detected