feat: add analytics tracking to key components

- Track tab creation and closure events in TabManager
- Add session tracking (created, resumed, completed) in ClaudeCodeSession
- Track model selection changes in ClaudeCodeSession
- Monitor agent execution events (success/failure) in AgentExecution
- Include execution duration metrics for agents
- Use useTrackEvent hook for consistent event tracking
This commit is contained in:
Vivek R
2025-07-30 19:45:00 +05:30
parent 77e0ef0e73
commit f7e932ed79
3 changed files with 40 additions and 0 deletions

View File

@@ -33,6 +33,7 @@ import { SplitPane } from "@/components/ui/split-pane";
import { WebviewPreview } from "./WebviewPreview";
import type { ClaudeStreamMessage } from "./AgentExecution";
import { useVirtualizer } from "@tanstack/react-virtual";
import { useTrackEvent, useComponentMetrics } from "@/hooks";
interface ClaudeCodeSessionProps {
/**
@@ -114,6 +115,10 @@ export const ClaudeCodeSession: React.FC<ClaudeCodeSessionProps> = ({
const isMountedRef = useRef(true);
const isListeningRef = useRef(false);
// Analytics tracking
const trackEvent = useTrackEvent();
useComponentMetrics('ClaudeCodeSession');
// Keep ref in sync with state
useEffect(() => {
queuedPromptsRef.current = queuedPrompts;
@@ -595,10 +600,14 @@ export const ClaudeCodeSession: React.FC<ClaudeCodeSessionProps> = ({
// Execute the appropriate command
if (effectiveSession && !isFirstPrompt) {
console.log('[ClaudeCodeSession] Resuming session:', effectiveSession.id);
trackEvent.sessionResumed(effectiveSession.id);
trackEvent.modelSelected(model);
await api.resumeClaudeCode(projectPath, effectiveSession.id, prompt, model);
} else {
console.log('[ClaudeCodeSession] Starting new session');
setIsFirstPrompt(false);
trackEvent.sessionCreated(model, 'prompt_input');
trackEvent.modelSelected(model);
await api.executeClaudeCode(projectPath, prompt, model);
}
}
@@ -821,6 +830,11 @@ export const ClaudeCodeSession: React.FC<ClaudeCodeSessionProps> = ({
isMountedRef.current = false;
isListeningRef.current = false;
// Track session completion
if (effectiveSession) {
trackEvent.sessionCompleted();
}
// Clean up listeners
unlistenRefs.current.forEach(unlisten => unlisten());
unlistenRefs.current = [];