MCPcopy Index your code
hub / github.com/winfunc/opcode / useWorkflowTracking

Function useWorkflowTracking

src/hooks/useAnalytics.ts:510–577  ·  view source on GitHub ↗
(workflowType: string)

Source from the content-addressed store, hash-verified

508
509// Hook for tracking workflow completion
510export function useWorkflowTracking(workflowType: string) {
511 const startTime = useRef<number | null>(null);
512 const stepsCompleted = useRef<number>(0);
513 const toolsUsed = useRef<Set<string>>(new Set());
514 const interruptions = useRef<number>(0);
515 const trackEvent = useTrackEvent();
516
517 const startWorkflow = useCallback((totalSteps: number) => {
518 startTime.current = Date.now();
519 stepsCompleted.current = 0;
520 toolsUsed.current.clear();
521 interruptions.current = 0;
522
523 trackEvent.workflowStarted({
524 workflow_type: workflowType,
525 steps_completed: 0,
526 total_steps: totalSteps,
527 duration_ms: 0,
528 interruptions: 0,
529 completion_rate: 0,
530 tools_used: [],
531 });
532 }, [workflowType, trackEvent]);
533
534 const trackStep = useCallback((toolName?: string) => {
535 stepsCompleted.current += 1;
536 if (toolName) {
537 toolsUsed.current.add(toolName);
538 }
539 }, []);
540
541 const trackInterruption = useCallback(() => {
542 interruptions.current += 1;
543 }, []);
544
545 const completeWorkflow = useCallback((totalSteps: number, success: boolean = true) => {
546 if (!startTime.current) return;
547
548 const duration = Date.now() - startTime.current;
549 const completionRate = stepsCompleted.current / totalSteps;
550
551 const eventData = {
552 workflow_type: workflowType,
553 steps_completed: stepsCompleted.current,
554 total_steps: totalSteps,
555 duration_ms: duration,
556 interruptions: interruptions.current,
557 completion_rate: completionRate,
558 tools_used: Array.from(toolsUsed.current),
559 };
560
561 if (success) {
562 trackEvent.workflowCompleted(eventData);
563 } else {
564 trackEvent.workflowAbandoned(eventData);
565 }
566
567 // Reset

Callers 1

ClaudeCodeSessionFunction · 0.90

Calls 2

useTrackEventFunction · 0.85
clearMethod · 0.80

Tested by

no test coverage detected