🪢 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(ai-gateway): product analytics for setup, credentials, invites, keys and model access (#19379)
Tobias Wochinger41510b2cb0e4
diff --git a/web/src/__tests__/server/ai-gateway-control-plane.servertest.ts b/web/src/__tests__/server/ai-gateway-control-plane.servertest.tsindex a2b7ce42ed..ee0916fce8 100644--- a/web/src/__tests__/server/ai-gateway-control-plane.servertest.ts+++ b/web/src/__tests__/server/ai-gateway-control-plane.servertest.ts@@ -491,7 +491,12 @@ describe("AI gateway control plane", () => {emails: [inviteeEmail],notifyMembers: true,});- expect(result).toEqual({ invitedCount: 1, failed: [], notifiedCount: 1 });+ expect(result).toEqual({+ invitedCount: 1,+ existingMemberCount: 0,+ failed: [],+ notifiedCount: 1,+ });expect(queuedNotifications()).toEqual(expect.arrayContaining([@@ -540,6 +545,7 @@ describe("AI gateway control plane", () => {expect(result).toEqual({invitedCount: 0,+ existingMemberCount: 1,failed: [],notifiedCount: 1,});@@ -607,6 +613,7 @@ describe("AI gateway control plane", () => {expect(result).toEqual({invitedCount: 0,+ existingMemberCount: 1,failed: [{email: viewerEmail,diff --git a/web/src/components/design-system/CodeSection/CodeSection.tsx b/web/src/components/design-system/CodeSection/CodeSection.tsxindex cae300d1d2..4d2f32f666 100644--- a/web/src/components/design-system/CodeSection/CodeSection.tsx+++ b/web/src/components/design-system/CodeSection/CodeSection.tsx@@ -86,6 +86,8 @@ type CodeSectionProps = {actions?: CodeSectionAction[];/** Shown next to the check icon after copying. */copiedMessage?: string;+ /** Called after the built-in copy button wrote `content` to the clipboard. */+ onAfterCopy?: () => void;/** Clamps the body to six lines and adds an expand/collapse control. */isCollapsible?: boolean;defaultCollapsed?: boolean;@@ -100,6 +102,7 @@ export function CodeSection({variant = "filled",actions = [],copiedMessage,+ onAfterCopy,isCollapsible = false,defaultCollapsed = false,shouldWrapLines = true,@@ -114,6 +117,7 @@ export function CodeSection({const handleCopy = async () => {try {await copy(content);+ onAfterCopy?.();} catch {// Clipboard writes can be rejected when the browser denies permission.}diff --git a/web/src/components/design-system/ExpandableContentPeek/ExpandableContentPeek.tsx b/web/src/components/design-system/ExpandableContentPeek/ExpandableContentPeek.tsxindex 9cc3a0bf91..e832e67a56 100644--- a/web/src/components/design-system/ExpandableContentPeek/ExpandableContentPeek.tsx+++ b/web/src/components/design-system/ExpandableContentPeek/ExpandableContentPeek.tsx@@ -27,6 +27,8 @@ type ExpandableContentPeekProps = PropsWithChildren<{/** Label of the button that reveals the rest, e.g. "Show all steps". */expandLabel: string;collapsedHeight?: "sm" | "md" | "lg";+ /** Called once when the clamped content is revealed. */+ onAfterExpand?: () => void;}>;function useIsOverflowing(@@ -65,6 +67,7 @@ export function ExpandableContentPeek({children,expandLabel,collapsedHeight = "md",+ onAfterExpand,}: ExpandableContentPeekProps) {const [isExpanded, setIsExpanded] = useState(false);const containerRef = useRef<HTMLDivElement>(null);@@ -72,7 +75,10 @@ export function ExpandableContentPeek({const isOverflowing = useIsOverflowing(containerRef, contentRef, !isExpanded);const isClamped = !isExpanded && isOverflowing;- const expand = () => setIsExpanded(true);+ const expand = () => {+ setIsExpanded(true);+ onAfterExpand?.();+ };return (<div className="relative">diff --git a/web/src/components/design-system/table/columns/createTextTableColumn.tsx b/web/src/components/design-system/table/columns/createTextTableColumn.tsxindex e4282599ad..44f7fdb0a0 100644--- a/web/src/components/design-system/table/columns/createTextTableColumn.tsx+++ b/web/src/components/design-system/table/columns/createTextTableColumn.tsx@@ -28,6 +28,10 @@ type TextTableColumnOptions<TData extends RowData, TValue> = TableColumnOptions<type TextTableColumnTrailingAction<TData extends RowData, TValue> =| {type: "copy-to-clipboard";+ /** Called after the value was written to the clipboard. */+ onAfterCopy?: (+ context: CellContext<TData, TValue | null | undefined>,+ ) => void;}| {type: "custom";@@ -68,7 +72,12 @@ export function createTextTableColumn<TData extends RowData, TValue = string>({if (!trailingAction)return nullValue ? <Text value={nullValue} /> : null;if (trailingAction.type === "copy-to-clipboard") {- return nullValue ? <CopyableText value={nullValue} /> : null;+ return nullValue ? (+ <CopyableText+ value={nullValue}+ onAfterCopy={() => trailingAction.onAfterCopy?.(context)}+ />+ ) : null;}return (@@ -107,7 +116,12 @@ export function createTextTableColumn<TData extends RowData, TValue = string>({}if (trailingAction?.type === "copy-to-clipboard") {- return <CopyableText value={text} />;+ return (+ <CopyableText+ value={text}+ onAfterCopy={() => trailingAction.onAfterCopy?.(context)}+ />+ );}if (trailingAction?.type === "custom") {return (@@ -180,7 +194,13 @@ function Text({ value }: { value: string }) {);}-function CopyableText({ value }: { value: string }) {+function CopyableText({+ value,+ onAfterCopy,+}: {+ value: string;+ onAfterCopy: () => void;+}) {const { copy, isCopied } = useCopyToClipboard();return (@@ -197,6 +217,7 @@ function CopyableText({ value }: { value: string }) {const button = event.currentTarget;try {await copy(value);+ onAfterCopy();} catch {// Clipboard failures are intentionally silent.} finally {diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/CreateGatewayApiKeyDialogController/CreateGatewayApiKeyDialogController.tsx b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/CreateGatewayApiKeyDialogController/CreateGatewayApiKeyDialogController.tsxindex af15397d63..b218bc20dd 100644--- a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/CreateGatewayApiKeyDialogController/CreateGatewayApiKeyDialogController.tsx+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/CreateGatewayApiKeyDialogController/CreateGatewayApiKeyDialogController.tsx@@ -1,4 +1,5 @@import { useState, type ReactNode } from "react";+import { useSession } from "next-auth/react";import { ChevronRight, Plus, X } from "@langfuse/icons";import { Alert } from "@/src/components/design-system/Alert/Alert";@@ -20,6 +21,7 @@ import {resolveApiKeyExpiration,} from "@/src/features/apiKey";import { GeneratedKeyContent } from "@/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/GeneratedKeyContent";+import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";import { useHasOrganizationAccess } from "@/src/features/rbac";import {api,@@ -65,6 +67,8 @@ export function CreateGatewayApiKeyDialogController({null,);const utils = api.useUtils();+ const capture = usePostHogClientCapture();+ const session = useSession();const create = api.aiGateway.createApiKey.useMutation({onError: (error) =>reportTrpcErrorWithoutToast(error, "ai-gateway-api-keys"),@@ -91,13 +95,26 @@ export function CreateGatewayApiKeyDialogController({.filter((field) => field.key.trim()).map((field) => [field.key.trim(), field.value]),);+ const effectiveIssuedAs = canIssueServiceAccountKeys ? issuedAs : "user";try {const created = await create.mutateAsync({orgId: organizationId,name: name.trim() || undefined,metadata: metadataObject,expiresAt,- issuedAs: canIssueServiceAccountKeys ? issuedAs : "user",+ issuedAs: effectiveIssuedAs,+ });+ capture("ai_gateway:api_key_created", {+ orgId: organizationId,+ creatorRole:+ session.data?.user?.organizations.find(+ (organization) => organization.id === organizationId,+ )?.role ?? null,+ isServiceAccount: effectiveIssuedAs === "serviceAccount",+ hasMetadata: metadataCount > 0,+ metadataCount,+ hasDescription: name.trim().length > 0,+ expiryPreset,});setGeneratedSecretKey(created.secretKey);await utils.aiGateway.listApiKeys.invalidate({diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GatewayApiKeysTable/ConnectedGatewayApiKeysTable.tsx b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GatewayApiKeysTable/ConnectedGatewayApiKeysTable.tsxindex 57536e2960..5c5133f6a6 100644--- a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GatewayApiKeysTable/ConnectedGatewayApiKeysTable.tsx+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GatewayApiKeysTable/ConnectedGatewayApiKeysTable.tsx@@ -6,6 +6,7 @@ import { Button } from "@/src/components/ui/button";import { CreateGatewayApiKeyDialogController } from "@/src/features/ai-gateway/components/GatewayApiKeysPage/components/CreateGatewayApiKeyDialogController/CreateGatewayApiKeyDialogController";import { TeamInviteDialogController } from "@/src/features/ai-gateway/components/GatewayApiKeysPage/components/TeamInviteDialogController/TeamInviteDialogController";import { ConfirmationDialogController } from "@/src/components/design-system/ConfirmationDialogController/ConfirmationDialogController";+import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";import { usePaginationState } from "@/src/hooks/usePaginationState";import { api } from "@/src/utils/api";import { GatewayApiKeysTable } from "./GatewayApiKeysTable";@@ -33,6 +34,7 @@ export function ConnectedGatewayApiKeysTable({{ placeholderData: keepPreviousData },);const utils = api.useUtils();+ const capture = usePostHogClientCapture();const revoke = api.aiGateway.revokeApiKey.useMutation();const handleSearchChange = (value: string) => {@@ -71,6 +73,7 @@ export function ConnectedGatewayApiKeysTable({onAfterDismiss={revoke.reset}onConfirm={async (apiKeyId) => {await revoke.mutateAsync({ orgId: organizationId, id: apiKeyId });+ capture("ai_gateway:api_key_revoked", { orgId: organizationId });const remainingCount = (apiKeysQuery.data?.totalCount ?? 1) - 1;const lastPageIndex = Math.max(0,diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/GeneratedKeyContent.tsx b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/GeneratedKeyContent.tsxindex 8a373b345f..f62fa2a9f3 100644--- a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/GeneratedKeyContent.tsx+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/GeneratedKeyContent.tsx@@ -2,6 +2,7 @@ import { Alert } from "@/src/components/design-system/Alert/Alert";import { Dialog } from "@/src/components/design-system/Dialog/Dialog";import { Skeleton } from "@/src/components/ui/skeleton";import { SetupInstructionsTabs } from "@/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/SetupInstructionsTabs/SetupInstructionsTabs";+import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";import { MaskedGatewayKey } from "./components/MaskedGatewayKey";import { useAgentSetupInstructions } from "./hooks/useAgentSetupInstructions";@@ -27,7 +28,12 @@ function SetupInstructions({ organizationId }: SetupInstructionsProps) {);}- return <SetupInstructionsTabs instructions={instructions} />;+ return (+ <SetupInstructionsTabs+ organizationId={organizationId}+ instructions={instructions}+ />+ );}type GeneratedKeyContentProps = {@@ -39,12 +45,24 @@ export function GeneratedKeyContent({organizationId,secretKey,}: GeneratedKeyContentProps) {+ const capture = usePostHogClientCapture();+return (<Dialog.Body><p className="text-muted-foreground">Copy the key now. It is shown only once.</p>- <MaskedGatewayKey secretKey={secretKey} />+ <MaskedGatewayKey+ secretKey={secretKey}+ onAfterCopy={() =>+ capture("ai_gateway:api_key_secret_copied", { orgId: organizationId })+ }+ onAfterReveal={() =>+ capture("ai_gateway:api_key_secret_revealed", {+ orgId: organizationId,+ })+ }+ /><hr className="-mx-4" /><SetupInstructions organizationId={organizationId} /></Dialog.Body>diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/AgentInstructionsPanel.tsx b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/AgentInstructionsPanel.tsxindex 6ba445620e..b1093e81ee 100644--- a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/AgentInstructionsPanel.tsx+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/AgentInstructionsPanel.tsx@@ -1,22 +1,53 @@import { ExpandableContentPeek } from "@/src/components/design-system/ExpandableContentPeek/ExpandableContentPeek";import type { AgentSetupInstructions } from "@/src/features/ai-gateway/types/agentSetupInstructions";+import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";import { AgentSetupSteps } from "./AgentSetupSteps";import { CopyForAgentButton } from "./CopyForAgentButton";type AgentInstructionsPanelProps = {+ organizationId: string;instructions: AgentSetupInstructions;};export function AgentInstructionsPanel({+ organizationId,instructions,}: AgentInstructionsPanelProps) {+ const capture = usePostHogClientCapture();+ const agent = { orgId: organizationId, agentId: instructions.id };+return (<div className="flex flex-col items-start gap-3">- <CopyForAgentButton instructions={instructions} />+ <CopyForAgentButton+ instructions={instructions}+ onAfterCopy={() =>+ capture("ai_gateway:agent_setup_instructions_copied", {+ ...agent,+ source: "copy_for_agent",+ })+ }+ />{/* Inactive tabs unmount, so switching tabs collapses the peek again. */}<div className="w-full">- <ExpandableContentPeek expandLabel="Show all steps">- <AgentSetupSteps instructions={instructions} />+ <ExpandableContentPeek+ expandLabel="Show all steps"+ onAfterExpand={() =>+ capture("ai_gateway:agent_setup_instructions_viewed", {+ ...agent,+ hasProviderWarning: instructions.warning !== undefined,+ })+ }+ >+ <AgentSetupSteps+ instructions={instructions}+ onAfterStepCopy={(stepNumber) =>+ capture("ai_gateway:agent_setup_instructions_copied", {+ ...agent,+ source: "step_code",+ stepNumber,+ })+ }+ /></ExpandableContentPeek></div></div>diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/AgentSetupSteps.tsx b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/AgentSetupSteps.tsxindex b3e1ed0d5d..ef63b26168 100644--- a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/AgentSetupSteps.tsx+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/AgentSetupSteps.tsx@@ -6,9 +6,13 @@ import type { AgentSetupInstructions } from "@/src/features/ai-gateway/types/agetype AgentSetupStepsProps = {instructions: AgentSetupInstructions;+ onAfterStepCopy?: (stepNumber: number) => void;};-export function AgentSetupSteps({ instructions }: AgentSetupStepsProps) {+export function AgentSetupSteps({+ instructions,+ onAfterStepCopy,+}: AgentSetupStepsProps) {return (<div className="flex flex-col gap-3">{instructions.warning ? (@@ -47,6 +51,7 @@ export function AgentSetupSteps({ instructions }: AgentSetupStepsProps) {content={step.code}language={step.language}shouldWrapLines={false}+ onAfterCopy={() => onAfterStepCopy?.(index + 1)}/>)}</Stepper>diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/ClaudeSetupTabs.tsx b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/ClaudeSetupTabs.tsxindex 0efa16ce42..200bcb2424 100644--- a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/ClaudeSetupTabs.tsx+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/ClaudeSetupTabs.tsx@@ -12,6 +12,7 @@ function isClaudeAgentId(value: string): value is ClaudeAgentId {}type ClaudeSetupTabsProps = {+ organizationId: string;instructions: AgentSetupInstructions[];value: ClaudeAgentId;onValueChange: (value: ClaudeAgentId) => void;@@ -19,6 +20,7 @@ type ClaudeSetupTabsProps = {/** Claude Code and Claude Desktop share one tab, with a switch between them. */export function ClaudeSetupTabs({+ organizationId,instructions,value,onValueChange,@@ -43,7 +45,10 @@ export function ClaudeSetupTabs({return entry ? (<Tabs.Content key={variant.id} value={variant.id}><div className="pt-3">- <AgentInstructionsPanel instructions={entry} />+ <AgentInstructionsPanel+ organizationId={organizationId}+ instructions={entry}+ /></div></Tabs.Content>) : null;diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/CopyForAgentButton.tsx b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/CopyForAgentButton.tsxindex 244a6a02ac..8fd2654c00 100644--- a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/CopyForAgentButton.tsx+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/CopyForAgentButton.tsx@@ -7,14 +7,19 @@ import { useCopyToClipboard } from "@/src/hooks/useCopyToClipboard";type CopyForAgentButtonProps = {instructions: AgentSetupInstructions;+ onAfterCopy?: () => void;};-export function CopyForAgentButton({ instructions }: CopyForAgentButtonProps) {+export function CopyForAgentButton({+ instructions,+ onAfterCopy,+}: CopyForAgentButtonProps) {const { copy, isCopied } = useCopyToClipboard({ successDuration: 2_000 });const handleCopy = async () => {try {await copy(formatAgentSetupMarkdown(instructions));+ onAfterCopy?.();} catch {// Clipboard writes can be rejected when the browser denies permission.}diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/MaskedGatewayKey.tsx b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/MaskedGatewayKey.tsxindex 1c19ff1dd8..9c1a037cdd 100644--- a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/MaskedGatewayKey.tsx+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/MaskedGatewayKey.tsx@@ -21,18 +21,28 @@ function maskSecretKey(secretKey: string) {type MaskedGatewayKeyProps = {secretKey: string;+ onAfterCopy?: () => void;+ onAfterReveal?: () => void;};-export function MaskedGatewayKey({ secretKey }: MaskedGatewayKeyProps) {+export function MaskedGatewayKey({+ secretKey,+ onAfterCopy,+ onAfterReveal,+}: MaskedGatewayKeyProps) {const [isRevealed, setIsRevealed] = useState(false);const { copy, isCopied } = useCopyToClipboard();const revealLabel = isRevealed ? "Hide key" : "Show key";const copyLabel = isCopied ? "Copied" : "Copy key";- const toggleReveal = () => setIsRevealed((current) => !current);+ const toggleReveal = () => {+ if (!isRevealed) onAfterReveal?.();+ setIsRevealed(!isRevealed);+ };const handleCopy = async () => {try {await copy(secretKey);+ onAfterCopy?.();} catch {// The key is shown only once, so a denied clipboard write must leave// it selectable by hand.diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/SetupInstructionsTabs/SetupInstructionsTabs.stories.tsx b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/SetupInstructionsTabs/SetupInstructionsTabs.stories.tsxindex fee5dc5c48..b0df5fcb2a 100644--- a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/SetupInstructionsTabs/SetupInstructionsTabs.stories.tsx+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/SetupInstructionsTabs/SetupInstructionsTabs.stories.tsx@@ -13,6 +13,7 @@ const meta = preview.meta({ component: SetupInstructionsTabs });export const Default = meta.story({args: {+ organizationId: "seed-org-id",instructions: buildAgentSetupInstructions({...context,providers: ["ANTHROPIC", "OPENAI"],@@ -37,6 +38,7 @@ export const TestClaudeSwitch = meta.story({export const TestWarnsWithoutAnthropic = meta.story({name: "(Test) Claude tab warns without an Anthropic connection",args: {+ organizationId: "seed-org-id",instructions: buildAgentSetupInstructions({...context,providers: ["OPENAI"],diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/SetupInstructionsTabs/SetupInstructionsTabs.tsx b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/SetupInstructionsTabs/SetupInstructionsTabs.tsxindex 8160b44f8a..4de312bd13 100644--- a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/SetupInstructionsTabs/SetupInstructionsTabs.tsx+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/SetupInstructionsTabs/SetupInstructionsTabs.tsx@@ -23,10 +23,12 @@ const TABS: { id: TabId; label: string; icon: IconComponent }[] = [];type SetupInstructionsTabsProps = {+ organizationId: string;instructions: AgentSetupInstructions[];};export function SetupInstructionsTabs({+ organizationId,instructions,}: SetupInstructionsTabsProps) {const [activeTab, setActiveTab] = useState<string>(DEFAULT_TAB);@@ -82,6 +84,7 @@ export function SetupInstructionsTabs({<Tabs.Content key={tab.id} value={tab.id}><div className="pt-4"><ClaudeSetupTabs+ organizationId={organizationId}instructions={instructions}value={claudeVariant}onValueChange={setClaudeVariant}@@ -94,7 +97,10 @@ export function SetupInstructionsTabs({return entry ? (<Tabs.Content key={tab.id} value={tab.id}><div className="pt-4">- <AgentInstructionsPanel instructions={entry} />+ <AgentInstructionsPanel+ organizationId={organizationId}+ instructions={entry}+ /></div></Tabs.Content>) : null;diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/TeamInviteDialogController/TeamInviteDialogController.tsx b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/TeamInviteDialogController/TeamInviteDialogController.tsxindex 0c36455b88..b223286844 100644--- a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/TeamInviteDialogController/TeamInviteDialogController.tsx+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/TeamInviteDialogController/TeamInviteDialogController.tsx@@ -8,6 +8,8 @@ import {} from "@/src/utils/api";import { TeamInviteDialog } from "@/src/features/ai-gateway/components/GatewayApiKeysPage/components/TeamInviteDialogController/components/TeamInviteDialog";import { showInviteOutcome } from "@/src/features/ai-gateway/components/GatewayApiKeysPage/components/TeamInviteDialogController/fns/showInviteOutcome";+import { toTeamInviteSentEvent } from "@/src/features/ai-gateway/fns/toTeamInviteSentEvent";+import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";export function TeamInviteDialogController({organizationId,@@ -16,6 +18,7 @@ export function TeamInviteDialogController({organizationId: string;children: (control: { openDialog: () => void }) => ReactNode;}) {+ const capture = usePostHogClientCapture();const invite = api.aiGateway.inviteTeam.useMutation({onError: (error) =>reportTrpcErrorWithoutToast(error, "ai-gateway-team-invite"),@@ -28,6 +31,16 @@ export function TeamInviteDialogController({emails,notifyMembers: false,});+ capture(+ "ai_gateway:team_invite_sent",+ toTeamInviteSentEvent({+ orgId: organizationId,+ surface: "api_keys_page",+ emails,+ notifyMembers: false,+ result,+ }),+ );if (result.failed.length === 0) showInviteOutcome(result);return result.failed;} catch (error) {diff --git a/web/src/features/ai-gateway/components/GatewayConnectionModelsPage/GatewayConnectionModelsPage.tsx b/web/src/features/ai-gateway/components/GatewayConnectionModelsPage/GatewayConnectionModelsPage.tsxindex d515158d6a..77555b34a7 100644--- a/web/src/features/ai-gateway/components/GatewayConnectionModelsPage/GatewayConnectionModelsPage.tsx+++ b/web/src/features/ai-gateway/components/GatewayConnectionModelsPage/GatewayConnectionModelsPage.tsx@@ -6,10 +6,16 @@ import { TextLink } from "@/src/components/design-system/TextLink/TextLink";import { ConnectionModelsLoadError } from "@/src/features/ai-gateway/components/GatewayConnectionModelsPage/components/ConnectionModelsLoadError";import { ConnectionModelsSkeleton } from "@/src/features/ai-gateway/components/GatewayConnectionModelsPage/components/ConnectionModelsSkeleton/ConnectionModelsSkeleton";import { ConnectionSummary } from "@/src/features/ai-gateway/components/GatewayConnectionModelsPage/components/ConnectionSummary/ConnectionSummary";-import { GatewayConnectionModelsTable } from "@/src/features/ai-gateway/components/GatewayConnectionModelsPage/components/GatewayConnectionModelsTable/GatewayConnectionModelsTable";+import {+ GatewayConnectionModelsTable,+ type GatewayConnectionModelsTableProps,+} from "@/src/features/ai-gateway/components/GatewayConnectionModelsPage/components/GatewayConnectionModelsTable/GatewayConnectionModelsTable";import { useGatewayConnectionModels } from "@/src/features/ai-gateway/components/GatewayConnectionModelsPage/hooks/useGatewayConnectionModels";+import { isGatewayModelAllowed } from "@/src/features/ai-gateway/fns/isGatewayModelAllowed";+import { toGatewayAllowedModelsSet } from "@/src/features/ai-gateway/fns/toGatewayAllowedModelsSet";import { updateGatewayAllowedModels } from "@/src/features/ai-gateway/fns/updateGatewayAllowedModels";import type { GatewayConnection } from "@/src/features/ai-gateway/types/gatewayProvider";+import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";export type GatewayConnectionModelsPageProps = {organizationId: string;@@ -52,6 +58,7 @@ export function GatewayConnectionModelsPage({/>{connection || !connectionQuery.isError ? (<ConnectionModelsBody+ organizationId={organizationId}connection={connection}isSaving={isSaving}modelsQuery={modelsQuery}@@ -78,6 +85,7 @@ function ProviderCredentialsLink({}type ConnectionModelsBodyProps = {+ organizationId: string;connection: GatewayConnection | undefined;isSaving: boolean;modelsQuery: ReturnType<typeof useGatewayConnectionModels>["modelsQuery"];@@ -89,12 +97,14 @@ type ConnectionModelsBodyProps = {};function ConnectionModelsBody({+ organizationId,connection,isSaving,modelsQuery,onRetry,saveAllowedModels,}: ConnectionModelsBodyProps) {+ const capture = usePostHogClientCapture();if (!connection || modelsQuery.isPending) {return (<div className="flex min-h-0 flex-1 flex-col">@@ -121,31 +131,56 @@ function ConnectionModelsBody({}const models = modelsQuery.data.models;- const enableAll = () => saveAllowedModels(null);- const disableAll = () => saveAllowedModels([]);- const setModelsEnabled = (- targetModels: string[],- enabled: boolean,- onSuccess?: () => void,- ) => {- saveAllowedModels(- updateGatewayAllowedModels({+ const setModelsEnabled = ({+ models: targetModels,+ enabled,+ scope,+ onSuccess,+ }: Omit<+ Parameters<GatewayConnectionModelsTableProps["onSetEnabled"]>[0],+ "scope"+ > & { scope: "single" | "selection" | "all" }) => {+ let nextAllowedModels: string[] | null = enabled ? null : [];+ if (scope !== "all") {+ nextAllowedModels = updateGatewayAllowedModels({allowedModels: connection.allowedModels,availableModels: models,targetModels,enabled,- }),- onSuccess,- );+ });+ }+ const changedModelCount = targetModels.filter(+ (model) =>+ isGatewayModelAllowed(connection.allowedModels, model) !== enabled,+ ).length;+ const nextAllowedModelsSet = toGatewayAllowedModelsSet(nextAllowedModels);+ saveAllowedModels(nextAllowedModels, () => {+ capture("ai_gateway:model_access_changed", {+ orgId: organizationId,+ provider: connection.provider,+ action: enabled ? "enable" : "disable",+ scope,+ modelCount: targetModels.length,+ changedModelCount,+ enabledModelCount: models.filter((model) =>+ isGatewayModelAllowed(nextAllowedModelsSet, model),+ ).length,+ totalModelCount: models.length,+ });+ onSuccess?.();+ });};-return (<GatewayConnectionModelsTablemodels={models}allowedModels={connection.allowedModels}isSaving={isSaving}- onEnableAll={enableAll}- onDisableAll={disableAll}+ onEnableAll={() =>+ setModelsEnabled({ models, enabled: true, scope: "all" })+ }+ onDisableAll={() =>+ setModelsEnabled({ models, enabled: false, scope: "all" })+ }onSetEnabled={setModelsEnabled}/>);diff --git a/web/src/features/ai-gateway/components/GatewayConnectionModelsPage/components/GatewayConnectionModelsTable/GatewayConnectionModelsTable.tsx b/web/src/features/ai-gateway/components/GatewayConnectionModelsPage/components/GatewayConnectionModelsTable/GatewayConnectionModelsTable.tsxindex 6eb92f3259..ca876c2177 100644--- a/web/src/features/ai-gateway/components/GatewayConnectionModelsPage/components/GatewayConnectionModelsTable/GatewayConnectionModelsTable.tsx+++ b/web/src/features/ai-gateway/components/GatewayConnectionModelsPage/components/GatewayConnectionModelsTable/GatewayConnectionModelsTable.tsx@@ -10,11 +10,13 @@ import type { LangfuseColumnDef } from "@/src/components/table/types";import { TableSelectionManager } from "@/src/features/table";import { isGatewayModelAllowed } from "@/src/features/ai-gateway/fns/isGatewayModelAllowed";import { toGatewayAllowedModelsSet } from "@/src/features/ai-gateway/fns/toGatewayAllowedModelsSet";-import { GatewayConnectionModelsSelectionBar } from "./components/GatewayConnectionModelsSelectionBar";+import {+ GatewayConnectionModelsSelectionBar,+ type GatewayConnectionModelsSelectionBarProps,+} from "./components/GatewayConnectionModelsSelectionBar";import { GatewayConnectionModelsToolbar } from "./components/GatewayConnectionModelsToolbar";import { ModelEnabledSwitch } from "./components/ModelEnabledSwitch";import type { GatewayConnectionModelRow } from "./types/gatewayConnectionModelRow";-const PAGE_SIZE_OPTIONS = [10, 20, 30, 40, 50];const DEFAULT_PAGE_SIZE = 50;const ROW_HEIGHTS = {@@ -29,11 +31,7 @@ export type GatewayConnectionModelsTableProps = {isSaving: boolean;onEnableAll: () => void;onDisableAll: () => void;- onSetEnabled: (- models: string[],- enabled: boolean,- onSuccess?: () => void,- ) => void;+ onSetEnabled: GatewayConnectionModelsSelectionBarProps["onSetEnabled"];};export function GatewayConnectionModelsTable({@@ -63,7 +61,8 @@ export function GatewayConnectionModelsTable({selectionStore,});const toggleModel = useCallback(- (model: string, enabled: boolean) => onSetEnabled([model], enabled),+ (model: string, enabled: boolean) =>+ onSetEnabled({ models: [model], enabled, scope: "single" }),[onSetEnabled],);const columns = useMemo<LangfuseColumnDef<GatewayConnectionModelRow>[]>(diff --git a/web/src/features/ai-gateway/components/GatewayConnectionModelsPage/components/GatewayConnectionModelsTable/components/GatewayConnectionModelsSelectionBar.tsx b/web/src/features/ai-gateway/components/GatewayConnectionModelsPage/components/GatewayConnectionModelsTable/components/GatewayConnectionModelsSelectionBar.tsxindex 1777eddf2e..9f88fb2beb 100644--- a/web/src/features/ai-gateway/components/GatewayConnectionModelsPage/components/GatewayConnectionModelsTable/components/GatewayConnectionModelsSelectionBar.tsx+++ b/web/src/features/ai-gateway/components/GatewayConnectionModelsPage/components/GatewayConnectionModelsTable/components/GatewayConnectionModelsSelectionBar.tsx@@ -4,16 +4,16 @@ import { useStore } from "zustand";import { OverviewSelectionBar } from "@/src/components/table/OverviewSelectionBar/OverviewSelectionBar";import type { TableSelectionStore } from "@/src/components/table/table-selection-store";import { Button } from "@/src/components/ui/button";-export type GatewayConnectionModelsSelectionBarProps = {filteredModelIds: string[];isSaving: boolean;selectionStore: TableSelectionStore;- onSetEnabled: (- models: string[],- enabled: boolean,- onSuccess?: () => void,- ) => void;+ onSetEnabled: (params: {+ models: string[];+ enabled: boolean;+ scope: "single" | "selection";+ onSuccess?: () => void;+ }) => void;};export function GatewayConnectionModelsSelectionBar({@@ -30,10 +30,13 @@ export function GatewayConnectionModelsSelectionBar({);const selectedModels = selectAll ? filteredModelIds : selectedIds;- const enableSelected = () =>- onSetEnabled(selectedModels, true, selectionActions.clearSelection);- const disableSelected = () =>- onSetEnabled(selectedModels, false, selectionActions.clearSelection);+ const setSelectedEnabled = (enabled: boolean) =>+ onSetEnabled({+ models: selectedModels,+ enabled,+ scope: "selection",+ onSuccess: selectionActions.clearSelection,+ });return (<OverviewSelectionBar@@ -45,7 +48,7 @@ export function GatewayConnectionModelsSelectionBar({variant="outline"size="sm"disabled={isSaving}- onClick={enableSelected}+ onClick={() => setSelectedEnabled(true)}><Play size="base" color="default" __rawClassName="mr-2" />Enable@@ -55,7 +58,7 @@ export function GatewayConnectionModelsSelectionBar({variant="outline"size="sm"disabled={isSaving}- onClick={disableSelected}+ onClick={() => setSelectedEnabled(false)}><Pause size="base" color="default" __rawClassName="mr-2" />Disablediff --git a/web/src/features/ai-gateway/components/GatewayModelsPage/components/ConnectedGatewayModelsTable/ConnectedGatewayModelsTable.tsx b/web/src/features/ai-gateway/components/GatewayModelsPage/components/ConnectedGatewayModelsTable/ConnectedGatewayModelsTable.tsxindex 03f7ba4b23..939b62fd5d 100644--- a/web/src/features/ai-gateway/components/GatewayModelsPage/components/ConnectedGatewayModelsTable/ConnectedGatewayModelsTable.tsx+++ b/web/src/features/ai-gateway/components/GatewayModelsPage/components/ConnectedGatewayModelsTable/ConnectedGatewayModelsTable.tsx@@ -1,5 +1,5 @@/* eslint-disable @typescript-eslint/no-use-before-define */-import { useMemo, useState } from "react";+import { useCallback, useMemo, useState } from "react";import Header from "@/src/components/layouts/header";import { Alert } from "@/src/components/design-system/Alert/Alert";import { Button } from "@/src/components/design-system/Button/Button";@@ -9,6 +9,7 @@ import { SelectInput } from "@/src/components/design-system/SelectInput/SelectInimport { GATEWAY_MODELS_DOCS_URL } from "@/src/features/ai-gateway/constants/gatewayDocsUrls";import { providerLabels } from "@/src/features/ai-gateway/constants/providerLabels";import type { GatewayProvider } from "@/src/features/ai-gateway/types/gatewayProvider";+import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";import {filterGatewayModels,type GatewayModelRow,@@ -38,6 +39,15 @@ export function ConnectedGatewayModelsTable({isLoading: boolean;syncError: boolean;}) {+ const capture = usePostHogClientCapture();+ const handleModelCopied = useCallback(+ (model: GatewayModelRow) =>+ capture("ai_gateway:model_name_copied", {+ orgId: organizationId,+ provider: model.provider,+ }),+ [capture, organizationId],+ );const [searchQuery, setSearchQuery] = useState("");const [provider, setProvider] = useState<GatewayProvider | "all">(ALL_PROVIDERS,@@ -152,6 +162,7 @@ export function ConnectedGatewayModelsTable({<GatewayModelsTableorganizationId={organizationId}canManageGateway={canManageGateway}+ onAfterModelCopy={handleModelCopied}data={isLoading? { status: "loading" }diff --git a/web/src/features/ai-gateway/components/GatewayModelsPage/components/ConnectedGatewayModelsTable/components/GatewayModelsTable/GatewayModelsTable.tsx b/web/src/features/ai-gateway/components/GatewayModelsPage/components/ConnectedGatewayModelsTable/components/GatewayModelsTable/GatewayModelsTable.tsxindex f096a19e5a..3e813beb77 100644--- a/web/src/features/ai-gateway/components/GatewayModelsPage/components/ConnectedGatewayModelsTable/components/GatewayModelsTable/GatewayModelsTable.tsx+++ b/web/src/features/ai-gateway/components/GatewayModelsPage/components/ConnectedGatewayModelsTable/components/GatewayModelsTable/GatewayModelsTable.tsx@@ -27,16 +27,23 @@ export function GatewayModelsTable({data,noResultsMessage,pagination,+ onAfterModelCopy,}: {organizationId: string;canManageGateway: boolean;data: TableProps<GatewayModelRow>["data"];noResultsMessage: string;pagination: PaginationBarProps;+ onAfterModelCopy?: (model: GatewayModelRow) => void;}) {const columns = useMemo(- () => createGatewayModelsColumns({ organizationId, canManageGateway }),- [canManageGateway, organizationId],+ () =>+ createGatewayModelsColumns({+ organizationId,+ canManageGateway,+ onAfterModelCopy,+ }),+ [canManageGateway, onAfterModelCopy, organizationId],);return (@@ -55,16 +62,20 @@ export function GatewayModelsTable({function createGatewayModelsColumns({organizationId,canManageGateway,-}: {- organizationId: string;- canManageGateway: boolean;-}): LangfuseColumnDef<GatewayModelRow>[] {+ onAfterModelCopy,+}: Pick<+ Parameters<typeof GatewayModelsTable>[0],+ "organizationId" | "canManageGateway" | "onAfterModelCopy"+>): LangfuseColumnDef<GatewayModelRow>[] {return [createTextTableColumn<GatewayModelRow>({accessorKey: "id",header: "Model",size: 360,- trailingAction: { type: "copy-to-clipboard" },+ trailingAction: {+ type: "copy-to-clipboard",+ onAfterCopy: ({ row }) => onAfterModelCopy?.(row.original),+ },}),{accessorKey: "connectionName",diff --git a/web/src/features/ai-gateway/components/GatewaySetupPage/components/ConnectedGatewaySetupGuide.tsx b/web/src/features/ai-gateway/components/GatewaySetupPage/components/ConnectedGatewaySetupGuide.tsxindex 9f7ab1c1dd..298af9436e 100644--- a/web/src/features/ai-gateway/components/GatewaySetupPage/components/ConnectedGatewaySetupGuide.tsx+++ b/web/src/features/ai-gateway/components/GatewaySetupPage/components/ConnectedGatewaySetupGuide.tsx@@ -1,3 +1,5 @@+import { useEffect, useRef } from "react";+import { Skeleton } from "@/src/components/ui/skeleton";import { GatewaySetupGuide } from "@/src/features/ai-gateway/components/GatewaySetupPage/components/GatewaySetupGuide/GatewaySetupGuide";import { ProviderDialogController } from "@/src/features/ai-gateway/components/GatewaySetupPage/components/ProviderDialogController/ProviderDialogController";@@ -8,6 +10,7 @@ import type {GatewayConfig,GatewayProject,} from "@/src/features/ai-gateway/components/GatewaySetupPage/types/gatewaySetup";+import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";export type ConnectedGatewaySetupGuideProps = {organizationId: string;@@ -22,20 +25,43 @@ export function ConnectedGatewaySetupGuide({projects,onFinish,}: ConnectedGatewaySetupGuideProps) {+ const capture = usePostHogClientCapture();const { activeStep, firstConnection, isPending } = useGatewaySetupProgress({organizationId,config,});- const { saveIngestion, isSaving } = useSaveGatewayIngestion(organizationId);+ const { saveIngestion, isSaving } = useSaveGatewayIngestion(+ organizationId,+ "setup_guide",+ );const { notifiableMembers, inviteTeam, isInviting } =useGatewayTeamInvite(organizationId);+ // Funnel entry for the setup steps; the ref keeps it to one event per visit.+ const hasCapturedViewRef = useRef(false);+ useEffect(() => {+ if (hasCapturedViewRef.current) return;+ hasCapturedViewRef.current = true;+ capture("ai_gateway:setup_guide_viewed", { orgId: organizationId });+ }, [capture, organizationId]);+if (isPending) {return <Skeleton className="h-64 w-full max-w-3xl" />;}return (- <ProviderDialogController organizationId={organizationId}>+ <ProviderDialogController+ organizationId={organizationId}+ surface="setup_guide"+ onAfterCreate={({ provider }) =>+ capture("ai_gateway:setup_step_completed", {+ orgId: organizationId,+ step: "credential",+ stepNumber: 2,+ provider,+ })+ }+ >{({ openAddDialog }) => (<GatewaySetupGuideactiveStep={activeStep}@@ -43,12 +69,31 @@ export function ConnectedGatewaySetupGuide({projects={projects}firstConnection={firstConnection}isSavingIngestion={isSaving}- onSaveIngestion={saveIngestion}+ onSaveIngestion={async (settings) => {+ const isSaved = await saveIngestion(settings);+ if (isSaved) {+ capture("ai_gateway:setup_step_completed", {+ orgId: organizationId,+ step: "ingestion",+ stepNumber: 1,+ ingestionMode: settings.ingestionMode,+ });+ }+ return isSaved;+ }}onAddCredential={openAddDialog}notifiableMembers={notifiableMembers}isInviting={isInviting}onInvite={inviteTeam}- onFinish={onFinish}+ onFinish={({ isSkipped }) => {+ capture("ai_gateway:setup_step_completed", {+ orgId: organizationId,+ step: "team_invite",+ stepNumber: 3,+ isSkipped,+ });+ onFinish();+ }}/>)}</ProviderDialogController>diff --git a/web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewayCredentialsOverview/GatewayCredentialsOverview.tsx b/web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewayCredentialsOverview/GatewayCredentialsOverview.tsxindex 5e3e7f5f31..d8ef744bbb 100644--- a/web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewayCredentialsOverview/GatewayCredentialsOverview.tsx+++ b/web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewayCredentialsOverview/GatewayCredentialsOverview.tsx@@ -22,6 +22,7 @@ import type {import { GATEWAY_SETUP } from "@/src/features/ai-gateway/components/GatewaySetupPage/constants/gatewaySetup";import { GATEWAY_INGESTION_MODES } from "@/src/features/ai-gateway/constants/gatewayIngestionModes";import type { GatewayConnection } from "@/src/features/ai-gateway/types/gatewayProvider";+import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";import { api, reportNonTrpcError } from "@/src/utils/api";export type GatewayCredentialsOverviewProps = {@@ -50,6 +51,7 @@ export function GatewayCredentialsOverview({{ enabled: !connectionId && connectionsQuery.isSuccess },);const utils = api.useUtils();+ const capture = usePostHogClientCapture();const retry = api.aiGateway.retryConnection.useMutation();const remove = api.aiGateway.deleteConnection.useMutation();@@ -78,6 +80,10 @@ export function GatewayCredentialsOverview({orgId: organizationId,id: connection.id,});+ capture("ai_gateway:provider_credential_deleted", {+ orgId: organizationId,+ provider: connection.provider,+ });await Promise.all([utils.aiGateway.listConnections.invalidate({orgId: organizationId,@@ -201,7 +207,10 @@ export function GatewayCredentialsOverview({</Button>)}</IngestionDialogController>- <ProviderDialogController organizationId={organizationId}>+ <ProviderDialogController+ organizationId={organizationId}+ surface="overview"+ >{({ openAddDialog }) => (<Button onClick={openAddDialog}><Plus size="base" __rawClassName="mr-1.5" />@@ -229,7 +238,10 @@ export function GatewayCredentialsOverview({onConfirm={deleteConnection}>{({ openDialog: openDeleteDialog }) => (- <ProviderDialogController organizationId={organizationId}>+ <ProviderDialogController+ organizationId={organizationId}+ surface="overview"+ >{({ openEditDialog }) => (<div className="flex min-h-0 flex-1 flex-col overflow-hidden"><GatewayProvidersTablediff --git a/web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewayCredentialsOverview/components/IngestionDialogController/IngestionDialogController.tsx b/web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewayCredentialsOverview/components/IngestionDialogController/IngestionDialogController.tsxindex 5693dd55c8..bfcafa272b 100644--- a/web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewayCredentialsOverview/components/IngestionDialogController/IngestionDialogController.tsx+++ b/web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewayCredentialsOverview/components/IngestionDialogController/IngestionDialogController.tsx@@ -23,7 +23,10 @@ export function IngestionDialogController({projects,children,}: IngestionDialogControllerProps) {- const { saveIngestion, isSaving } = useSaveGatewayIngestion(organizationId);+ const { saveIngestion, isSaving } = useSaveGatewayIngestion(+ organizationId,+ "overview",+ );async function handleSave(settings: GatewayIngestionSettings) {const isSaved = await saveIngestion(settings);diff --git a/web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewaySetupGuide/GatewaySetupGuide.stories.tsx b/web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewaySetupGuide/GatewaySetupGuide.stories.tsxindex 6f35356335..22f999902e 100644--- a/web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewaySetupGuide/GatewaySetupGuide.stories.tsx+++ b/web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewaySetupGuide/GatewaySetupGuide.stories.tsx@@ -94,6 +94,7 @@ export const TestRetryDoesNotNotifyAgain = meta.story({...InvitingTeam.input.args,onInvite: fn(async () => ({invitedCount: 0,+ existingMemberCount: 1,failed: [{ email: "[email protected]", message: "Already a member" }],notifiedCount: 12,})),diff --git a/web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewaySetupGuide/components/TeamInviteStep/components/TeamInviteForm/TeamInviteForm.tsx b/web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewaySetupGuide/components/TeamInviteStep/components/TeamInviteForm/TeamInviteForm.tsxindex e190c14246..811a88beea 100644--- a/web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewaySetupGuide/components/TeamInviteStep/components/TeamInviteForm/TeamInviteForm.tsx+++ b/web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewaySetupGuide/components/TeamInviteStep/components/TeamInviteForm/TeamInviteForm.tsx@@ -18,7 +18,7 @@ export type TeamInviteFormProps = {emails: string[];notifyMembers: boolean;}) => Promise<GatewayTeamInviteResult | null>;- onFinish: () => void;+ onFinish: (outcome: { isSkipped: boolean }) => void;};function getSendLabel(emailCount: number) {@@ -58,7 +58,7 @@ export function TeamInviteForm({invitees.keepFailed(result.failed);return;}- onFinish();+ onFinish({ isSkipped: false });}return (@@ -90,7 +90,11 @@ export function TeamInviteForm({}onClick={handleSend}/>- <Button text="Skip for now" variant="ghost" onClick={onFinish} />+ <Button+ text="Skip for now"+ variant="ghost"+ onClick={() => onFinish({ isSkipped: true })}+ /></div></div>);diff --git a/web/src/features/ai-gateway/components/GatewaySetupPage/components/ProviderDialogController/ProviderDialogController.tsx b/web/src/features/ai-gateway/components/GatewaySetupPage/components/ProviderDialogController/ProviderDialogController.tsxindex 9910e89223..6c792e4dcd 100644--- a/web/src/features/ai-gateway/components/GatewaySetupPage/components/ProviderDialogController/ProviderDialogController.tsx+++ b/web/src/features/ai-gateway/components/GatewaySetupPage/components/ProviderDialogController/ProviderDialogController.tsx@@ -27,16 +27,22 @@ import {reportNonTrpcError,reportTrpcErrorWithoutToast,} from "@/src/utils/api";+import type { GatewaySettingsSurface } from "@/src/features/ai-gateway/types/aiGatewayAnalytics";+import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";import { getLiveConnectionNameError } from "@/src/features/ai-gateway/components/GatewaySetupPage/components/ProviderDialogController/fns/getLiveConnectionNameError";import { useExistingConnectionNames } from "@/src/features/ai-gateway/components/GatewaySetupPage/components/ProviderDialogController/hooks/useExistingConnectionNames";export function ProviderDialogController({organizationId,connection,+ surface,+ onAfterCreate,children,}: {organizationId: string;connection?: GatewayConnection;+ surface: GatewaySettingsSurface;+ onAfterCreate?: (created: { provider: GatewayProvider }) => void;children: (control: {openAddDialog: () => void;openEditDialog: (connection: GatewayConnection) => void;@@ -51,6 +57,7 @@ export function ProviderDialogController({);const [credential, setCredential] = useState("");const utils = api.useUtils();+ const capture = usePostHogClientCapture();const existingNames = useExistingConnectionNames(organizationId);const name =nameDraft ?? suggestGatewayConnectionName(provider, existingNames);@@ -145,6 +152,12 @@ export function ProviderDialogController({name,...(credential ? { credential } : {}),});+ capture("ai_gateway:provider_credential_updated", {+ orgId: organizationId,+ provider: selectedConnection.provider,+ isRenamed: name.trim() !== selectedConnection.name,+ isCredentialReplaced: Boolean(credential),+ });} else {await create.mutateAsync({orgId: organizationId,@@ -152,6 +165,13 @@ export function ProviderDialogController({name,credential,});+ capture("ai_gateway:provider_credential_added", {+ orgId: organizationId,+ surface,+ provider,+ isFirstCredential: existingNames.length === 0,+ });+ onAfterCreate?.({ provider });}/** Pins the autofilled name so the refetched list cannot bump it to the next suffix. */diff --git a/web/src/features/ai-gateway/components/GatewaySetupPage/hooks/useGatewayTeamInvite.ts b/web/src/features/ai-gateway/components/GatewaySetupPage/hooks/useGatewayTeamInvite.tsindex 024c993308..66f69d1756 100644--- a/web/src/features/ai-gateway/components/GatewaySetupPage/hooks/useGatewayTeamInvite.ts+++ b/web/src/features/ai-gateway/components/GatewaySetupPage/hooks/useGatewayTeamInvite.ts@@ -1,7 +1,10 @@+import { toTeamInviteSentEvent } from "@/src/features/ai-gateway/fns/toTeamInviteSentEvent";+import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";import { api, reportNonTrpcError } from "@/src/utils/api";export function useGatewayTeamInvite(organizationId: string) {const utils = api.useUtils();+ const capture = usePostHogClientCapture();const notifiableMembersQuery = api.aiGateway.getNotifiableMembers.useQuery({orgId: organizationId,});@@ -16,6 +19,15 @@ export function useGatewayTeamInvite(organizationId: string) {orgId: organizationId,...params,});+ capture(+ "ai_gateway:team_invite_sent",+ toTeamInviteSentEvent({+ orgId: organizationId,+ surface: "setup_guide",+ ...params,+ result,+ }),+ );await utils.aiGateway.getNotifiableMembers.invalidate({orgId: organizationId,});diff --git a/web/src/features/ai-gateway/components/GatewaySetupPage/hooks/useSaveGatewayIngestion.ts b/web/src/features/ai-gateway/components/GatewaySetupPage/hooks/useSaveGatewayIngestion.tsindex 098bd0f738..3f35c5d8a0 100644--- a/web/src/features/ai-gateway/components/GatewaySetupPage/hooks/useSaveGatewayIngestion.ts+++ b/web/src/features/ai-gateway/components/GatewaySetupPage/hooks/useSaveGatewayIngestion.ts@@ -2,12 +2,18 @@ import { useRef, useState } from "react";import { useSession } from "next-auth/react";import type { GatewayIngestionSettings } from "@/src/features/ai-gateway/components/GatewaySetupPage/types/gatewaySetup";+import type { GatewaySettingsSurface } from "@/src/features/ai-gateway/types/aiGatewayAnalytics";+import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";import { api, reportNonTrpcError } from "@/src/utils/api";/** Saves ingestion settings, creating the ingestion project first when a new one is named. */-export function useSaveGatewayIngestion(organizationId: string) {+export function useSaveGatewayIngestion(+ organizationId: string,+ surface: GatewaySettingsSurface,+) {const session = useSession();const utils = api.useUtils();+ const capture = usePostHogClientCapture();const createProject = api.projects.create.useMutation();const updateConfig = api.aiGateway.updateConfig.useMutation();// Spans every request and the refetch, so callers stay busy until the saved config is shown.@@ -43,6 +49,12 @@ export function useSaveGatewayIngestion(organizationId: string) {defaultIngestionProjectId: await resolveProjectId(settings),ingestionMode: settings.ingestionMode,});+ capture("ai_gateway:ingestion_settings_saved", {+ orgId: organizationId,+ surface,+ ingestionMode: settings.ingestionMode,+ projectTarget: settings.projectTarget,+ });await Promise.all([utils.aiGateway.getConfig.invalidate({ orgId: organizationId }),utils.aiGateway.getSetupStatus.invalidate({ orgId: organizationId }),diff --git a/web/src/features/ai-gateway/fns/toTeamInviteSentEvent.ts b/web/src/features/ai-gateway/fns/toTeamInviteSentEvent.tsnew file mode 100644index 0000000000..d45ad55c7c--- /dev/null+++ b/web/src/features/ai-gateway/fns/toTeamInviteSentEvent.ts@@ -0,0 +1,28 @@+import type { AiGatewayEventMap } from "@/src/features/ai-gateway/types/aiGatewayAnalytics";+import type { RouterOutputs } from "@/src/utils/api";++export function toTeamInviteSentEvent({+ orgId,+ surface,+ emails,+ notifyMembers,+ result,+}: Pick<+ AiGatewayEventMap["ai_gateway:team_invite_sent"],+ "orgId" | "surface"+> & {+ emails: string[];+ notifyMembers: boolean;+ result: RouterOutputs["aiGateway"]["inviteTeam"];+}) {+ return {+ orgId,+ surface,+ emailCount: emails.length,+ invitedCount: result.invitedCount,+ existingMemberCount: result.existingMemberCount,+ notifiedMemberCount: result.notifiedCount,+ failedCount: result.failed.length,+ isNotifyMembersEnabled: notifyMembers,+ };+}diff --git a/web/src/features/ai-gateway/server/team/gatewayTeamService.ts b/web/src/features/ai-gateway/server/team/gatewayTeamService.tsindex 07cfa2b41e..1c63f5ec8d 100644--- a/web/src/features/ai-gateway/server/team/gatewayTeamService.ts+++ b/web/src/features/ai-gateway/server/team/gatewayTeamService.ts@@ -121,12 +121,14 @@ export class GatewayTeamService {const invited = new Set<string>();const notified = new Set<string>();const failed: Array<{ email: string; message: string }> = [];+ let existingMemberCount = 0;for (const email of emails) {const member = existingMembers.get(email);// Typing a member's address means "tell them", so they get the member// announcement rather than an "already a member" invitation error.if (member) {if (member.id === ctx.session.user.id) continue;+ existingMemberCount += 1;if (!member.hasScope) {failed.push({email,@@ -218,6 +220,8 @@ export class GatewayTeamService {return {invitedCount: invited.size,+ /** Typed addresses of members other than the sender, notified or not. */+ existingMemberCount,failed,notifiedCount: notified.size,};diff --git a/web/src/features/ai-gateway/types/aiGatewayAnalytics.ts b/web/src/features/ai-gateway/types/aiGatewayAnalytics.tsnew file mode 100644index 0000000000..17ae3d00a4--- /dev/null+++ b/web/src/features/ai-gateway/types/aiGatewayAnalytics.ts@@ -0,0 +1,100 @@+import type { GatewayIngestionMode, Role } from "@langfuse/shared";++import type { ApiKeyExpirationPreset } from "@/src/features/apiKey/constants/apiKeyExpirationOptions";+import type { GatewayIngestionSettings } from "@/src/features/ai-gateway/components/GatewaySetupPage/types/gatewaySetup";+import type { AgentSetupInstructions } from "@/src/features/ai-gateway/types/agentSetupInstructions";+import type { GatewayProvider } from "@/src/features/ai-gateway/types/gatewayProvider";++// Gateway adoption funnel: setup guide -> credentials -> team -> keys -> model+// access. Metadata only — enums, counts and booleans. Never email addresses,+// connection or key names, credentials, metadata keys/values or model ids+// (fine-tuned model ids can embed customer names).++type OrganizationContext = { orgId: string };++/** The setup guide shown to new organizations, or the settings overview afterwards. */+export type GatewaySettingsSurface = "setup_guide" | "overview";++export type AiGatewayEventMap = {+ "ai_gateway:setup_guide_viewed": OrganizationContext;+ "ai_gateway:setup_step_completed": OrganizationContext &+ (+ | {+ step: "ingestion";+ stepNumber: 1;+ ingestionMode: GatewayIngestionMode;+ }+ | { step: "credential"; stepNumber: 2; provider: GatewayProvider }+ | { step: "team_invite"; stepNumber: 3; isSkipped: boolean }+ );+ "ai_gateway:ingestion_settings_saved": OrganizationContext &+ Pick<GatewayIngestionSettings, "ingestionMode" | "projectTarget"> & {+ surface: GatewaySettingsSurface;+ };+ "ai_gateway:provider_credential_added": OrganizationContext & {+ surface: GatewaySettingsSurface;+ provider: GatewayProvider;+ isFirstCredential: boolean;+ };+ "ai_gateway:provider_credential_updated": OrganizationContext & {+ provider: GatewayProvider;+ isRenamed: boolean;+ isCredentialReplaced: boolean;+ };+ "ai_gateway:provider_credential_deleted": OrganizationContext & {+ provider: GatewayProvider;+ };+ "ai_gateway:team_invite_sent": OrganizationContext & {+ surface: "setup_guide" | "api_keys_page";+ /** Addresses typed into the form. */+ emailCount: number;+ /** Typed addresses that became new organization invitations. */+ invitedCount: number;+ /** Typed addresses that already belonged to organization members. */+ existingMemberCount: number;+ /** Members emailed the gateway announcement, typed or via "notify members". */+ notifiedMemberCount: number;+ failedCount: number;+ isNotifyMembersEnabled: boolean;+ };+ "ai_gateway:api_key_created": OrganizationContext & {+ /** Organization role of the creator; null when they are not a member (instance admins). */+ creatorRole: Role | null;+ isServiceAccount: boolean;+ hasMetadata: boolean;+ metadataCount: number;+ hasDescription: boolean;+ expiryPreset: ApiKeyExpirationPreset;+ };+ "ai_gateway:api_key_revoked": OrganizationContext;+ /** The one-time secret was copied; the key itself is never sent. */+ "ai_gateway:api_key_secret_copied": OrganizationContext;+ "ai_gateway:api_key_secret_revealed": OrganizationContext;+ "ai_gateway:model_access_changed": OrganizationContext & {+ provider: GatewayProvider;+ action: "enable" | "disable";+ /** Row switch, bulk selection, or the "Enable all" / "Disable all" buttons. */+ scope: "single" | "selection" | "all";+ /** Models the action targeted. */+ modelCount: number;+ /** Targeted models whose state actually flipped. */+ changedModelCount: number;+ enabledModelCount: number;+ totalModelCount: number;+ };+ // The copied slug embeds the connection name, so only the provider is sent.+ "ai_gateway:model_name_copied": OrganizationContext & {+ provider: GatewayProvider;+ };+ /** The user expanded a tool's setup steps ("Show all steps") after creating a key. */+ "ai_gateway:agent_setup_instructions_viewed": OrganizationContext & {+ agentId: AgentSetupInstructions["id"];+ hasProviderWarning: boolean;+ };+ "ai_gateway:agent_setup_instructions_copied": OrganizationContext & {+ agentId: AgentSetupInstructions["id"];+ } & (+ | { source: "copy_for_agent" }+ | { source: "step_code"; stepNumber: number }+ );+};diff --git a/web/src/features/posthog-analytics/usePostHogClientCapture.ts b/web/src/features/posthog-analytics/usePostHogClientCapture.tsindex 51094f5230..862e3cca5d 100644--- a/web/src/features/posthog-analytics/usePostHogClientCapture.ts+++ b/web/src/features/posthog-analytics/usePostHogClientCapture.ts@@ -3,6 +3,7 @@ import { usePostHog } from "posthog-js/react";import { useCallback } from "react";import type { AnnotationEventMap } from "@/src/features/scores/lib/annotationAnalytics";import type { EvalOnboardingEventMap } from "@/src/features/evals/v2/types/evalOnboardingAnalytics";+import type { AiGatewayEventMap } from "@/src/features/ai-gateway/types/aiGatewayAnalytics";import type {ToastInteractionEventProperties,ToastShownEventProperties,@@ -461,6 +462,26 @@ const events = {"quick_action_started","tool_approval_decided",],+ // AI Gateway setup and adoption. Props are typed in AiGatewayEventMap and+ // carry `orgId` on every event: metadata only, never emails, names,+ // credentials, key metadata or model ids.+ ai_gateway: [+ "setup_guide_viewed",+ "setup_step_completed",+ "ingestion_settings_saved",+ "provider_credential_added",+ "provider_credential_updated",+ "provider_credential_deleted",+ "team_invite_sent",+ "api_key_created",+ "api_key_revoked",+ "api_key_secret_copied",+ "api_key_secret_revealed",+ "model_access_changed",+ "model_name_copied",+ "agent_setup_instructions_viewed",+ "agent_setup_instructions_copied",+ ],cmd_k_menu: ["opened", "search_entered", "navigated"],spend_alert: ["created", "updated", "deleted"],sidebar: [@@ -529,6 +550,7 @@ type EventName = {type TypedEventMap = AnnotationEventMap &EvalOnboardingEventMap &+ AiGatewayEventMap &ToastEventMap;type EventProperties = TypedEventMap & {