Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(mcp-analytics): show call counts in share tooltips and lab cards (#115601)

Georgis Andonis6dfabf3462f1
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 0eab3314a7b9..d384d486342d 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -12555,13 +12555,13 @@ snapshots:
scenes-app-mcp-analytics--dashboard--wide--light:
hash: v1.k794b7964.71306f5f516e8afadf50181f2181e50c9883b5aae53d247fbb03e3bf803c4c86.16C5ajh9Fsnr259tCPZBpPSTQUDQlI1tlI-9URo6-1s
scenes-app-mcp-analytics--dashboard-leaderboard-home--medium--dark:
- hash: v1.k794b7964.045f7a6a772739b957e1a93b26d71cf95cae47f82e4708d6ca640251e61e8edc.rwLxnkIEA2xdBQllbSsTaTd5HX38F9Da5YBzrY_CpxA
+ hash: v1.k794b7964.bebfe1219c184b4fc6d273e64c5f2891af7cf84735d4fee9138fea6304fc85d3.SSZ4rPhA1BOqACIXZM7PIGrePIImC-e5Z_xh6CfoH7g
scenes-app-mcp-analytics--dashboard-leaderboard-home--medium--light:
- hash: v1.k794b7964.4fe5cd9ca121d8c326634d4928ccc623a6c5a27660fa8c873c732911785250b0.T1eSepzKZMLui6j9QNAJVuQRZQt6B0qI3zu7TAw_pB8
+ hash: v1.k794b7964.c35a6809113bf5e2bbf25503f92d299b4a8e589add851dfe2bd2fd8dd1303d85.tJedepPMrmg7VsFbm0-TcV_7HNJrty2PSlm2A26RppQ
scenes-app-mcp-analytics--dashboard-leaderboard-home--wide--dark:
- hash: v1.k794b7964.b2c29f8a1cdc8e13284418d93da444b350f9d865aa49e8f09f83519fdbcf29fe.eaFsgTK_GgO5XZwbG7P3arCLS9yI5sHRxNyUO9uCS6w
+ hash: v1.k794b7964.16a1cd9a51d99d9bbc09015f72d576f20a00103453a072dfe97a8558d072b45d.5JAYJaO5bZYJeduJKlWX332QnzlmHSTRiBudFzyk1I4
scenes-app-mcp-analytics--dashboard-leaderboard-home--wide--light:
- hash: v1.k794b7964.63a81a9baea910859f4d5d50ee0012e2e2c1343a2fc4ba2012c83106bc769fab.5a5oc3YhihX0avvWrUq2epNhpufSikTLycZjHPPtAL0
+ hash: v1.k794b7964.40d3ae998f57c6f7708c951bbbae56e717b81357de0c3e8f9cdfd73571fe15d0.oe8f4ECn5o5E7tUWi7OA-YSxyhJ_ulT6xVEFmrmQBT8
scenes-app-mcp-analytics--dashboard-narrow--dark:
hash: v1.k794b7964.adf40bdb6db463f5f7f57dfc8ac1c177d3527787114b2ea15e1947bb2a7ea9bf.sBunrdrDv-SV516FPaHBw8a201Hp5xf3EKwOSAO6kZA
scenes-app-mcp-analytics--dashboard-narrow--light:
diff --git a/products/mcp_analytics/frontend/leaderboardHome/LabScoreboard.tsx b/products/mcp_analytics/frontend/leaderboardHome/LabScoreboard.tsx
index ed6c4fc76164..0da85caccb2a 100644
--- a/products/mcp_analytics/frontend/leaderboardHome/LabScoreboard.tsx
+++ b/products/mcp_analytics/frontend/leaderboardHome/LabScoreboard.tsx
@@ -3,14 +3,23 @@ import { Card, CardContent, Skeleton, ToggleGroup, ToggleGroupItem } from '@post
import { TileDecorations } from 'lib/components/TileDecorations/TileDecorations'
import { formatPercentage } from 'lib/utils/numbers'
+import { formatNumber } from '../dashboard/formatters'
import { leadingLabs, type LabShare, type ScoreboardMetric } from './leaderboardShares'
import { LoadErrorMessage } from './LoadErrorMessage'
const PODIUM_SIZE = 3
-const METRICS: { value: ScoreboardMetric; label: string; caption: string }[] = [
- { value: 'calls', label: 'Calls', caption: 'of calls from models that name themselves' },
- { value: 'users', label: 'Users', caption: 'of users who called with a model from this lab' },
+const METRICS: { value: ScoreboardMetric; label: string; caption: (count: string, total: string) => string }[] = [
+ {
+ value: 'calls',
+ label: 'Calls',
+ caption: (count, total) => `${count} of ${total} calls from models that name themselves`,
+ },
+ {
+ value: 'users',
+ label: 'Users',
+ caption: (count, total) => `${count} of ${total} users called with a model from this lab`,
+ },
]
export function LabScoreboard({
@@ -69,7 +78,7 @@ export function LabScoreboard({
<LoadErrorMessage />
) : (
<div className="grid min-w-0 grid-cols-1 gap-4 @min-[40rem]/mcp-overview:grid-cols-3">
- {podium.map(({ lab, share }) => (
+ {podium.map(({ lab, share, count, total }) => (
<div key={lab} className="relative">
<TileDecorations badge={leaders.includes(lab) ? 'winner' : null} />
<Card size="sm" className="h-full" data-attr="mcp-leaderboard-lab-tile">
@@ -78,7 +87,9 @@ export function LabScoreboard({
<span className="text-3xl font-semibold tabular-nums text-primary">
{formatPercentage(share, { compact: true })}
</span>
- <span className="text-xs text-secondary">{caption}</span>
+ <span className="text-xs text-secondary tabular-nums">
+ {caption?.(formatNumber(count), formatNumber(total))}
+ </span>
</CardContent>
</Card>
</div>
diff --git a/products/mcp_analytics/frontend/leaderboardHome/ShareOverTimeChart.tsx b/products/mcp_analytics/frontend/leaderboardHome/ShareOverTimeChart.tsx
index d3c7e6ecd081..7d2e5b3761d2 100644
--- a/products/mcp_analytics/frontend/leaderboardHome/ShareOverTimeChart.tsx
+++ b/products/mcp_analytics/frontend/leaderboardHome/ShareOverTimeChart.tsx
@@ -1,11 +1,14 @@
-import { useMemo } from 'react'
+import { useCallback, useMemo } from 'react'
import {
type ChartTheme,
+ createTooltipDateFormatter,
+ DefaultTooltip,
type Series,
type TimeInterval,
TimeSeriesLineChart,
type TimeSeriesLineChartConfig,
+ type TooltipContext,
} from '@posthog/quill-charts'
import { Skeleton } from '@posthog/quill-primitives'
@@ -13,6 +16,7 @@ import { useChartConfig } from 'lib/charts/hooks'
import { formatPercentage } from 'lib/utils/numbers'
import { Card, CardState } from '../dashboard/Card'
+import { formatNumber } from '../dashboard/formatters'
import { type ShareSeries } from './leaderboardShares'
import { LoadErrorMessage } from './LoadErrorMessage'
import { NoDataMessage } from './NoDataMessage'
@@ -58,13 +62,34 @@ export function ShareOverTimeChart({
showCrosshair: true,
showGrid: true,
xAxis: { interval, timezone },
- tooltip: {
- placement: 'cursor',
- valueFormatter: (fraction) => formatPercentage(fraction * 100, { compact: true }),
- },
+ tooltip: { placement: 'cursor' },
}),
[timezone, interval]
)
+ const labelFormatter = useMemo(
+ () => createTooltipDateFormatter({ interval, timezone, allDays: labels }),
+ [interval, timezone, labels]
+ )
+ // A custom tooltip, because the config's value formatter sees only the share, not the hovered
+ // day, so it cannot look up the call count behind it.
+ const renderTooltip = useCallback(
+ (ctx: TooltipContext) => {
+ const callsAt = (s: Series): number => s.data[ctx.dataIndex] ?? 0
+ const totalCalls = ctx.seriesData.reduce((sum, entry) => sum + callsAt(entry.series), 0)
+ return (
+ <DefaultTooltip
+ {...ctx}
+ labelFormatter={labelFormatter}
+ valueFormatter={(fraction, entry) =>
+ `${formatPercentage(fraction * 100, { compact: true })} · ${formatCalls(callsAt(entry.series))}`
+ }
+ showTotal
+ totalFormatter={() => formatCalls(totalCalls)}
+ />
+ )
+ },
+ [labelFormatter]
+ )
return (
<Card title={title} className="min-w-0">
@@ -75,9 +100,19 @@ export function ShareOverTimeChart({
empty={failed ? <LoadErrorMessage /> : <NoDataMessage />}
>
<div className="flex min-h-[300px] flex-1 flex-col">
- <TimeSeriesLineChart series={chartSeries} labels={labels} config={config} theme={theme} />
+ <TimeSeriesLineChart
+ series={chartSeries}
+ labels={labels}
+ config={config}
+ theme={theme}
+ tooltip={renderTooltip}
+ />
</div>
</CardState>
</Card>
)
}
+
+function formatCalls(calls: number): string {
+ return `${formatNumber(calls)} ${calls === 1 ? 'call' : 'calls'}`
+}
diff --git a/products/mcp_analytics/frontend/leaderboardHome/leaderboardShares.test.ts b/products/mcp_analytics/frontend/leaderboardHome/leaderboardShares.test.ts
index 1c6efd43a424..dfcb730e6c03 100644
--- a/products/mcp_analytics/frontend/leaderboardHome/leaderboardShares.test.ts
+++ b/products/mcp_analytics/frontend/leaderboardHome/leaderboardShares.test.ts
@@ -19,7 +19,7 @@ import {
} from './leaderboardShares'
const row = (bucket: string, label: string, calls: number): BucketedFacetRow => ({ bucket, label, calls })
-const labShare = (lab: LabShare['lab'], share: number): LabShare => ({ lab, share })
+const labShare = (lab: LabShare['lab'], share: number): LabShare => ({ lab, share, count: share, total: 100 })
const windowRow = (label: string, calls: number): WindowFacetRow => ({ label, calls, users: 1, errors: 0 })
describe('leaderboardShares', () => {
@@ -98,8 +98,8 @@ describe('leaderboardShares', () => {
row('d1', 'mystery', 10),
])
expect(shares).toEqual([
- { lab: 'Anthropic', share: 40 },
- { lab: 'OpenAI', share: 10 },
+ { lab: 'Anthropic', share: 40, count: 8, total: 20 },
+ { lab: 'OpenAI', share: 10, count: 2, total: 20 },
])
})
@@ -130,8 +130,8 @@ describe('leaderboardShares', () => {
10
)
expect(shares).toEqual([
- { lab: 'Anthropic', share: 90 },
- { lab: 'OpenAI', share: 60 },
+ { lab: 'Anthropic', share: 90, count: 9, total: 10 },
+ { lab: 'OpenAI', share: 60, count: 6, total: 10 },
])
})
diff --git a/products/mcp_analytics/frontend/leaderboardHome/leaderboardShares.ts b/products/mcp_analytics/frontend/leaderboardHome/leaderboardShares.ts
index fdd5e2b83e68..d51a027c5760 100644
--- a/products/mcp_analytics/frontend/leaderboardHome/leaderboardShares.ts
+++ b/products/mcp_analytics/frontend/leaderboardHome/leaderboardShares.ts
@@ -25,6 +25,9 @@ export interface ShareSeries {
export interface LabShare {
lab: ModelLab
share: number
+ // The lab's calls or users, out of `total`, the denominator of `share`.
+ count: number
+ total: number
}
export interface LabUsersRow {
@@ -129,7 +132,7 @@ export function buildLabShares(rows: BucketedFacetRow[]): LabShare[] {
return [...callsByLab.entries()]
.filter(([lab]) => lab !== 'Other')
.sort(([, a], [, b]) => b - a)
- .map(([lab, calls]) => ({ lab, share: total > 0 ? (calls / total) * 100 : 0 }))
+ .map(([lab, calls]) => ({ lab, share: total > 0 ? (calls / total) * 100 : 0, count: calls, total }))
}
// A person can use models from several labs, so these shares do not add up to 100.
@@ -137,7 +140,12 @@ export function buildLabUserShares(rows: LabUsersRow[], namedModelUsers: number)
return rows
.filter((row): row is { lab: ModelLab; users: number } => row.lab !== UNKNOWN && row.lab !== 'Other')
.sort((a, b) => b.users - a.users)
- .map(({ lab, users }) => ({ lab, share: namedModelUsers > 0 ? (users / namedModelUsers) * 100 : 0 }))
+ .map(({ lab, users }) => ({
+ lab,
+ share: namedModelUsers > 0 ? (users / namedModelUsers) * 100 : 0,
+ count: users,
+ total: namedModelUsers,
+ }))
}
export function leadingLabs(shares: LabShare[]): ModelLab[] {