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

Function trackEvent

cli/src/utils/analytics.ts:179–232  ·  view source on GitHub ↗
(
  event: AnalyticsEvent,
  properties?: Record<string, any>,
)

Source from the content-addressed store, hash-verified

177}
178
179export function trackEvent(
180 event: AnalyticsEvent,
181 properties?: Record<string, any>,
182) {
183 const { isProd } = resolveDeps()
184 const distinctId = getDistinctId()
185
186 if (!client) {
187 if (isProd) {
188 const error = new Error('Analytics client not initialized')
189 logAnalyticsError(error, {
190 stage: AnalyticsErrorStage.Track,
191 event,
192 properties,
193 })
194 throw error
195 }
196 return
197 }
198
199 if (!distinctId) {
200 // This shouldn't happen if initAnalytics was called, but handle gracefully
201 return
202 }
203
204 if (!isProd) {
205 if (DEBUG_ANALYTICS) {
206 logAnalyticsDebug(`[analytics] ${event}`, {
207 event,
208 properties,
209 distinctId,
210 })
211 }
212 return
213 }
214
215 if (!shouldTrackAnalyticsEvent({ event, distinctId, properties })) {
216 return
217 }
218
219 try {
220 client.capture({
221 distinctId,
222 event,
223 properties,
224 })
225 } catch (error) {
226 logAnalyticsError(error, {
227 stage: AnalyticsErrorStage.Track,
228 event,
229 properties,
230 })
231 }
232}
233
234export function identifyUser(userId: string, properties?: Record<string, any>) {
235 if (!client) {

Callers 11

ChatFunction · 0.90
handleFollowupClickFunction · 0.90
mainFunction · 0.90
AppWithAsyncAuthFunction · 0.90
calculateFingerprintFunction · 0.90
sendAnalyticsAndLogFunction · 0.90
runBashCommandFunction · 0.90
routeUserPromptFunction · 0.90
useAuthStateFunction · 0.90

Calls 6

resolveDepsFunction · 0.85
getDistinctIdFunction · 0.85
logAnalyticsErrorFunction · 0.85
logAnalyticsDebugFunction · 0.85
captureMethod · 0.80

Tested by

no test coverage detected