Skip to content

Commit d9fe5a0

Browse files
committed
init analytics earlier
1 parent bbe89f6 commit d9fe5a0

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

cli/src/index.tsx

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,26 @@ async function main(): Promise<void> {
197197
const startCwd = process.cwd()
198198
const showProjectPicker = shouldShowProjectPicker(startCwd, homeDir)
199199

200+
// Initialize analytics early, before anything that might use the logger
201+
// (the logger calls trackEvent, which throws if analytics isn't initialized)
202+
try {
203+
initAnalytics()
204+
205+
// Track app launch event
206+
trackEvent(AnalyticsEvent.APP_LAUNCHED, {
207+
version: loadPackageVersion(),
208+
platform: process.platform,
209+
arch: process.arch,
210+
hasInitialPrompt: Boolean(initialPrompt),
211+
hasAgentOverride: hasAgentOverride,
212+
continueChat,
213+
initialMode: initialMode ?? 'DEFAULT',
214+
})
215+
} catch (error) {
216+
// Analytics initialization is optional - don't fail the app if it errors
217+
logger.debug(error, 'Failed to initialize analytics')
218+
}
219+
200220
// Initialize agent registry (loads user agents via SDK).
201221
// When --agent is provided, skip local .agents to avoid overrides.
202222
if (isPublishCommand || !hasAgentOverride) {
@@ -231,25 +251,6 @@ async function main(): Promise<void> {
231251
}
232252
}
233253

234-
// Initialize analytics
235-
try {
236-
initAnalytics()
237-
238-
// Track app launch event
239-
trackEvent(AnalyticsEvent.APP_LAUNCHED, {
240-
version: loadPackageVersion(),
241-
platform: process.platform,
242-
arch: process.arch,
243-
hasInitialPrompt: Boolean(initialPrompt),
244-
hasAgentOverride: hasAgentOverride,
245-
continueChat,
246-
initialMode: initialMode ?? 'DEFAULT',
247-
})
248-
} catch (error) {
249-
// Analytics initialization is optional - don't fail the app if it errors
250-
logger.debug(error, 'Failed to initialize analytics')
251-
}
252-
253254
if (clearLogs) {
254255
clearLogFile()
255256
}

0 commit comments

Comments
 (0)