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

@@ -36,6 +36,7 @@ import { ErrorBoundary } from "./ErrorBoundary";
import { useVirtualizer } from "@tanstack/react-virtual";
import { AGENT_ICONS } from "./CCAgents";
import { HooksEditor } from "./HooksEditor";
import { useTrackEvent, useComponentMetrics } from "@/hooks";
interface AgentExecutionProps {
/**
@@ -89,6 +90,10 @@ export const AgentExecution: React.FC<AgentExecutionProps> = ({
const [error, setError] = useState<string | null>(null);
const [copyPopoverOpen, setCopyPopoverOpen] = useState(false);
// Analytics tracking
const trackEvent = useTrackEvent();
useComponentMetrics('AgentExecution');
// Hooks configuration state
const [isHooksDialogOpen, setIsHooksDialogOpen] = useState(false);
const [activeHooksTab, setActiveHooksTab] = useState("project");
@@ -302,6 +307,9 @@ export const AgentExecution: React.FC<AgentExecutionProps> = ({
console.log("Agent execution started with run ID:", executionRunId);
setRunId(executionRunId);
// Track agent execution start
trackEvent.agentExecuted(agent.name || 'custom', true, agent.name, undefined);
// Set up event listeners with run ID isolation
const outputUnlisten = await listen<string>(`agent-output:${executionRunId}`, (event) => {
try {
@@ -323,9 +331,13 @@ export const AgentExecution: React.FC<AgentExecutionProps> = ({
const completeUnlisten = await listen<boolean>(`agent-complete:${executionRunId}`, (event) => {
setIsRunning(false);
const duration = executionStartTime ? Date.now() - executionStartTime : undefined;
setExecutionStartTime(null);
if (!event.payload) {
setError("Agent execution failed");
trackEvent.agentExecuted(agent.name || 'custom', false, agent.name, duration);
} else {
trackEvent.agentExecuted(agent.name || 'custom', true, agent.name, duration);
}
});