🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(agent): Add custom PostHog events for in-app agent (#14470)
Ben Bachem24523754540a
diff --git a/web/src/ee/features/in-app-agent/components/InAppAiAgentProvider.tsx b/web/src/ee/features/in-app-agent/components/InAppAiAgentProvider.tsxindex 5bd3f28e2a..3fd83862ef 100644--- a/web/src/ee/features/in-app-agent/components/InAppAiAgentProvider.tsx+++ b/web/src/ee/features/in-app-agent/components/InAppAiAgentProvider.tsx@@ -30,6 +30,7 @@ import { useHasEntitlement } from "@/src/features/entitlements/hooks";import { showErrorToast } from "@/src/features/notifications/showErrorToast";import { api } from "@/src/utils/api";import { createInAppAgentScreenContext } from "@/src/ee/features/in-app-agent/context";+import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";const SELECTED_CONVERSATION_STORAGE_KEY_PREFIX ="langfuse:in-app-ai-agent-selected-conversation";@@ -172,6 +173,7 @@ function InAppAiAgentProviderInner({setOpen,}: InAppAiAgentProviderInnerProps) {const utils = api.useUtils();+ const capture = usePostHogClientCapture();const [selectedConversationId, setSelectedConversationId] = useSessionStorage<string | null>(`${SELECTED_CONVERSATION_STORAGE_KEY_PREFIX}:${projectId}`, null);@@ -528,6 +530,10 @@ function InAppAiAgentProviderInner({agent.addMessage(userMessage);setMessages(agent.messages.filter(isAgentConversationMessage));+ if (isNewConversation) {+ capture("in_app_agent:new_chat_started");+ }+ capture("in_app_agent:new_chat_turn");startedRun = true;runAgent(agent, conversationId);return true;@@ -544,6 +550,7 @@ function InAppAiAgentProviderInner({},[conversationQuery.data,+ capture,ensureSubscription,getOrCreateAgent,isSelectedConversationHydrating,diff --git a/web/src/features/posthog-analytics/usePostHogClientCapture.ts b/web/src/features/posthog-analytics/usePostHogClientCapture.tsindex 01f09f7f4b..b6b19e6074 100644--- a/web/src/features/posthog-analytics/usePostHogClientCapture.ts+++ b/web/src/features/posthog-analytics/usePostHogClientCapture.ts@@ -220,6 +220,7 @@ export const events = {"message_sent","community_hours_click",], // also used on landing page for consistency+ in_app_agent: ["new_chat_started", "new_chat_turn"],cmd_k_menu: ["opened", "search_entered", "navigated"],spend_alert: ["created", "updated", "deleted"],sidebar: ["book_a_call_clicked", "v4_beta_toggled"],