: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(mcp): render web vitals path breakdown results as a table (#115948)
Sam Pennington8c36fa3fe469
diff --git a/services/mcp/src/ui-apps/components/infer-visualization.ts b/services/mcp/src/ui-apps/components/infer-visualization.tsindex 8fc1462fe173..116533445323 100644--- a/services/mcp/src/ui-apps/components/infer-visualization.ts+++ b/services/mcp/src/ui-apps/components/infer-visualization.ts@@ -182,7 +182,12 @@ export function inferVisualizationType(data: unknown): VisualizationType | nullif (kind === 'PathsQuery') {return 'paths'}- if (kind === 'HogQLQuery' || kind === 'WebStatsTableQuery' || kind === 'WebOverviewQuery') {+ if (+ kind === 'HogQLQuery' ||+ kind === 'WebStatsTableQuery' ||+ kind === 'WebOverviewQuery' ||+ kind === 'WebVitalsPathBreakdownQuery'+ ) {return 'table'}diff --git a/services/mcp/src/ui-apps/components/utils.ts b/services/mcp/src/ui-apps/components/utils.tsindex ad7732f5dade..17f4ac79a2de 100644--- a/services/mcp/src/ui-apps/components/utils.ts+++ b/services/mcp/src/ui-apps/components/utils.ts@@ -139,6 +139,13 @@ export function normalizeFunnelSteps(results: FunnelResult): Array<{ name: strin// Web stats columns that drive the web analytics UI only, not data.const HIDDEN_WEB_STATS_COLUMNS = new Set(['ui_fill_fraction', 'cross_sell'])+// Worst band first, so the pages that need work lead the table.+const WEB_VITALS_BANDS = [+ ['poor', 'Poor'],+ ['needs_improvements', 'Needs improvement'],+ ['good', 'Good'],+] as const+function humanizeKey(key: string): string {const text = key.replace(/_/g, ' ')return text.charAt(0).toUpperCase() + text.slice(1)@@ -195,5 +202,20 @@ export function toTableResult(query: unknown, results: unknown, columns: string[),}}+ if (node.kind === 'WebVitalsPathBreakdownQuery' && Array.isArray(results)) {+ const { metric, percentile } = node as { metric?: string; percentile?: string }+ // The response always holds one breakdown object, keyed by band.+ const bands = (results[0] ?? {}) as Partial<Record<string, Array<{ path: string; value: number }>>>+ return {+ columns: ['Path', `${metric ?? 'Value'} (${percentile ?? 'p75'})`, 'Rating'],+ results: WEB_VITALS_BANDS.flatMap(([band, label]) =>+ (bands[band] ?? []).map(({ path, value }) => [+ path,+ metric === 'CLS' ? value.toFixed(2) : `${Math.round(value)} ms`,+ label,+ ])+ ),+ }+ }return results as HogQLResult}diff --git a/services/mcp/tests/unit/insight-visualizations.test.ts b/services/mcp/tests/unit/insight-visualizations.test.tsindex 39364dc2be91..a85f578d62ac 100644--- a/services/mcp/tests/unit/insight-visualizations.test.ts+++ b/services/mcp/tests/unit/insight-visualizations.test.ts@@ -78,6 +78,7 @@ describe('insight visualizations', () => {['HogQLQuery', 'table'],['WebStatsTableQuery', 'table'],['WebOverviewQuery', 'table'],+ ['WebVitalsPathBreakdownQuery', 'table'],] as const)('falls back to %s when results are empty', (kind, expected) => {expect(inferVisualizationType(queryPayload([], kind))).toBe(expected)})@@ -275,6 +276,28 @@ describe('insight visualizations', () => {],})})++ it.each([+ ['LCP', 'p90', 2873.4, '2873 ms'],+ ['CLS', 'p75', 0.314, '0.31'],+ ])('maps %s web vitals bands to path rows, worst first', (metric, percentile, poorValue, poorCell) => {+ const results = [+ {+ good: [{ path: '/', value: 0.01 }],+ needs_improvements: [],+ poor: [{ path: '/pricing', value: poorValue }],+ },+ ]+ expect(+ toTableResult({ kind: 'WebVitalsPathBreakdownQuery', metric, percentile }, results, undefined)+ ).toEqual({+ columns: ['Path', `${metric} (${percentile})`, 'Rating'],+ results: [+ ['/pricing', poorCell, 'Poor'],+ ['/', metric === 'CLS' ? '0.01' : '0 ms', 'Good'],+ ],+ })+ })})describe('buildProportionBarSeries', () => {