🪢 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
feat(web): instrument dashboard and widget usage in PostHog (#16626)
Trang Nguyena8a0a3b0df92
diff --git a/web/src/features/dashboard/components/CloneFirstDialog.tsx b/web/src/features/dashboard/components/CloneFirstDialog.tsxindex 87e982184e..13f49ada29 100644--- a/web/src/features/dashboard/components/CloneFirstDialog.tsx+++ b/web/src/features/dashboard/components/CloneFirstDialog.tsx@@ -76,6 +76,9 @@ export function CloneFirstDialog({source: "clone_first_dialog",set_as_home: setAsHome,had_pending_change: Boolean(pendingDefinition),+ dashboardId,+ // The clone-first flow only exists for locked Langfuse-owned dashboards.+ owner: "LANGFUSE",});showSuccessToast({title: "Editable copy created",diff --git a/web/src/features/dashboard/components/DashboardTable.tsx b/web/src/features/dashboard/components/DashboardTable.tsxindex 006981d8ce..8bae44b200 100644--- a/web/src/features/dashboard/components/DashboardTable.tsx+++ b/web/src/features/dashboard/components/DashboardTable.tsx@@ -40,9 +40,11 @@ type DashboardTableRow = {function CloneDashboardButton({dashboardId,projectId,+ owner,}: {dashboardId: string;projectId: string;+ owner: DashboardTableRow["owner"];}) {const utils = api.useUtils();const hasAccess = useHasProjectAccess({ projectId, scope: "dashboards:CUD" });@@ -51,7 +53,11 @@ function CloneDashboardButton({const mutCloneDashboard = api.dashboard.cloneDashboard.useMutation({onSuccess: () => {utils.dashboard.invalidate();- capture("dashboard:clone_dashboard", { source: "list_clone_button" });+ capture("dashboard:clone_dashboard", {+ source: "list_clone_button",+ dashboardId,+ owner,+ });showSuccessToast({title: "Dashboard cloned",description: "The dashboard has been cloned successfully",@@ -306,6 +312,7 @@ export function DashboardTable() {<CloneDashboardButtondashboardId={id}projectId={projectId}+ owner={owner}/></DropdownMenuItem>{owner === "PROJECT" && (diff --git a/web/src/features/posthog-analytics/usePostHogClientCapture.ts b/web/src/features/posthog-analytics/usePostHogClientCapture.tsindex 05c5819a4d..4d5bdc5d92 100644--- a/web/src/features/posthog-analytics/usePostHogClientCapture.ts+++ b/web/src/features/posthog-analytics/usePostHogClientCapture.ts@@ -212,6 +212,8 @@ export const events = {"save_to_prompt_version_button_click",],dashboard: [+ "view",+ "widget_saved","clone_dashboard","home_dashboard_viewed","home_dashboard_peeked",diff --git a/web/src/features/widgets/components/SelectWidgetDialog.tsx b/web/src/features/widgets/components/SelectWidgetDialog.tsxindex 2e1b5aace5..26cd2f6c3b 100644--- a/web/src/features/widgets/components/SelectWidgetDialog.tsx+++ b/web/src/features/widgets/components/SelectWidgetDialog.tsx@@ -261,6 +261,11 @@ export function SelectWidgetDialog({key={presetId}type="button"onClick={() => {+ capture("dashboard:widget_added", {+ kind: "home_preset",+ preset_id: presetId,+ dashboard_id: dashboardId,+ });onSelectPreset(presetId);onOpenChange(false);}}diff --git a/web/src/pages/project/[projectId]/dashboards/[dashboardId]/index.tsx b/web/src/pages/project/[projectId]/dashboards/[dashboardId]/index.tsxindex 5540804744..ddeb7308a3 100644--- a/web/src/pages/project/[projectId]/dashboards/[dashboardId]/index.tsx+++ b/web/src/pages/project/[projectId]/dashboards/[dashboardId]/index.tsx@@ -129,6 +129,19 @@ export default function DashboardDetail() {// route through the clone-first flow instead of mutating.const isLockedEditable = hasRbacCUDAccess && isLockedDashboard;+ // PostHog is the external system: report one view per dashboard once the+ // owner is known ("do the Langfuse-maintained templates get used?"). The+ // id ref dedupes Strict Mode double-mounts while still re-reporting on+ // client-side navigation between dashboards (same pattern as+ // dashboard:home_dashboard_viewed).+ const dashboardOwner = dashboard.data?.owner;+ const viewedDashboardRef = useRef<string | null>(null);+ useEffect(() => {+ if (!dashboardOwner || viewedDashboardRef.current === dashboardId) return;+ viewedDashboardRef.current = dashboardId;+ capture("dashboard:view", { dashboardId, owner: dashboardOwner });+ }, [capture, dashboardId, dashboardOwner]);+// Access for cloning (independent of dashboard owner)const hasCloneAccess = hasRbacCUDAccess && isLockedDashboard;diff --git a/web/src/pages/project/[projectId]/widgets/[widgetId]/index.tsx b/web/src/pages/project/[projectId]/widgets/[widgetId]/index.tsxindex c6f443775e..9375b89cab 100644--- a/web/src/pages/project/[projectId]/widgets/[widgetId]/index.tsx+++ b/web/src/pages/project/[projectId]/widgets/[widgetId]/index.tsx@@ -7,6 +7,7 @@ import { showErrorToast } from "@/src/features/notifications/showErrorToast";import { showSuccessToast } from "@/src/features/notifications/showSuccessToast";import { type metricAggregations, type views } from "@langfuse/shared/query";import { type z } from "zod";+import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";export default function EditWidget() {const router = useRouter();@@ -18,6 +19,7 @@ export default function EditWidget() {// Fetch the widget detailsconst utils = api.useUtils();+ const capture = usePostHogClientCapture();const { data: widgetData, isLoading: isWidgetLoading } =api.dashboardWidgets.get.useQuery({@@ -34,7 +36,16 @@ export default function EditWidget() {onSettled: () => {utils.dashboardWidgets.invalidate();},- onSuccess: () => {+ onSuccess: (data, variables) => {+ // Which measure/aggregation/chart shapes do users actually save?+ capture("dashboard:widget_saved", {+ isNew: false,+ view: variables.view,+ chartType: variables.chartType,+ measures: variables.metrics.map((m) => `${m.agg}:${m.measure}`),+ dimensionCount: variables.dimensions.length,+ filterCount: variables.filters.length,+ });showSuccessToast({title: "Widget updated successfully",description: "Your widget has been updated.",diff --git a/web/src/pages/project/[projectId]/widgets/new.tsx b/web/src/pages/project/[projectId]/widgets/new.tsxindex fbdcac3e11..dc25e38bf5 100644--- a/web/src/pages/project/[projectId]/widgets/new.tsx+++ b/web/src/pages/project/[projectId]/widgets/new.tsx@@ -11,6 +11,7 @@ import { SelectDashboardDialog } from "@/src/features/dashboard/components/Selecimport { useState } from "react";import { useV4Beta } from "@/src/features/events/hooks/useV4Beta";import { getDefaultView } from "@/src/features/widgets/utils";+import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";export default function NewWidget() {const router = useRouter();@@ -19,9 +20,19 @@ export default function NewWidget() {dashboardId?: string;};const { isBetaEnabled } = useV4Beta();+ const capture = usePostHogClientCapture();const createWidgetMutation = api.dashboardWidgets.create.useMutation({- onSuccess: (data) => {+ onSuccess: (data, variables) => {+ // Which measure/aggregation/chart shapes do users actually save?+ capture("dashboard:widget_saved", {+ isNew: true,+ view: variables.view,+ chartType: variables.chartType,+ measures: variables.metrics.map((m) => `${m.agg}:${m.measure}`),+ dimensionCount: variables.dimensions.length,+ filterCount: variables.filters.length,+ });showSuccessToast({title: "Widget created successfully",description: "Your widget has been created.",