From b85990bede31a57f22c0f2a92170e34e3098e36c Mon Sep 17 00:00:00 2001 From: Vishakh Date: Thu, 21 May 2026 16:33:47 -0400 Subject: [PATCH] Added more precise instrumentation for DNA Chat. --- app/components/LLMChatInline.tsx | 6 +++++- app/dna-chat/page.tsx | 4 +++- lib/analytics.ts | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/components/LLMChatInline.tsx b/app/components/LLMChatInline.tsx index 77846d1..9e53e67 100644 --- a/app/components/LLMChatInline.tsx +++ b/app/components/LLMChatInline.tsx @@ -8,7 +8,7 @@ import { useCustomization } from "./CustomizationContext"; import ReactMarkdown from 'react-markdown'; import remarkGfm from 'remark-gfm'; import { callLLM, callLLMStream, getLLMDescription, MessageContentPart } from "@/lib/llm-client"; -import { trackLLMQuestionAsked } from "@/lib/analytics"; +import { trackLLMQuestionAsked, trackAIConsentGiven, trackAIConsentDeclined, trackAIConsentModalShown, trackExampleQuestionClicked } from "@/lib/analytics"; type AttachmentType = 'text' | 'pdf' | 'csv' | 'tsv' | 'image'; @@ -105,18 +105,21 @@ export default function AIChatInline() { localStorage.setItem(CONSENT_STORAGE_KEY, "true"); setHasConsent(true); setShowConsentModal(false); + trackAIConsentGiven(); void handleSendMessage(true); } }; const handleConsentDecline = () => { setShowConsentModal(false); + trackAIConsentDeclined(); }; const handleExampleClick = (question: string) => { setInputValue(question); inputRef.current?.focus(); + trackExampleQuestionClicked(); }; const handleCopyMessage = async (content: string) => { @@ -304,6 +307,7 @@ export default function AIChatInline() { // Check consent before sending first message if (!skipConsentCheck && !hasConsent) { setShowConsentModal(true); + trackAIConsentModalShown(); return; } diff --git a/app/dna-chat/page.tsx b/app/dna-chat/page.tsx index d773f2c..ca0c80f 100644 --- a/app/dna-chat/page.tsx +++ b/app/dna-chat/page.tsx @@ -8,7 +8,7 @@ import GuidedTour from "../components/GuidedTour"; import { dnaChatTour } from "../components/tours/tourContent"; import { useResults } from "../components/ResultsContext"; import { ResultsManager } from "@/lib/results-manager"; -import { trackDNAChatViewed } from "@/lib/analytics"; +import { trackDNAChatViewed, trackDNAChatSampleDataLoaded, trackDNAChatSampleDataFailed } from "@/lib/analytics"; const SAMPLE_RESULTS_FILE_NAME = "monadic_dna_explorer_results_2026-05-19.tsv"; @@ -123,6 +123,7 @@ export default function DNAChatPage() { await clearResults(); await addResultsBatch(session.results); localStorage.setItem("dna_chat_sample_results_loaded", "true"); + trackDNAChatSampleDataLoaded(session.results.length); setSampleLoad({ status: "loaded", @@ -133,6 +134,7 @@ export default function DNAChatPage() { }); } catch (error) { console.error("[DNA Chat] Sample results load failed:", error); + trackDNAChatSampleDataFailed(error instanceof Error ? error.message : undefined); setSampleLoad({ status: "error", downloadedBytes: 0, diff --git a/lib/analytics.ts b/lib/analytics.ts index f21cbc6..5628870 100644 --- a/lib/analytics.ts +++ b/lib/analytics.ts @@ -470,6 +470,22 @@ export function trackDNAChatViewed() { trackEvent('dna_chat_viewed'); } +export function trackDNAChatSampleDataLoaded(resultCount: number) { + trackEvent('dna_chat_sample_data_loaded', { result_count: resultCount }); +} + +export function trackDNAChatSampleDataFailed(reason?: string) { + trackEvent('dna_chat_sample_data_failed', { reason: sanitizeErrorReason(reason) }); +} + +export function trackExampleQuestionClicked() { + trackEvent('example_question_clicked'); +} + +export function trackAIConsentModalShown() { + trackEvent('ai_consent_modal_shown'); +} + export function trackOverviewReportViewed() { trackEvent('overview_report_viewed'); }