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.

fix(insights): fix quill legend position re-query and humanize event names (#65722)

Sam Pennington737c03b183ae
diff --git a/frontend/src/scenes/insights/utils/queryUtils.ts b/frontend/src/scenes/insights/utils/queryUtils.ts
index 6fe5b2492ead..9e649749fe9c 100644
--- a/frontend/src/scenes/insights/utils/queryUtils.ts
+++ b/frontend/src/scenes/insights/utils/queryUtils.ts
@@ -265,6 +265,7 @@ export const cleanInsightQuery = (query: InsightQueryNode, opts?: CompareQueryOp
funnelStepReference: undefined,
breakdownSorting: undefined,
dataColorTheme: undefined,
+ legendPosition: undefined,
}
if (isTrendsQuery(cleanedQuery)) {
diff --git a/posthog/schema_helpers.py b/posthog/schema_helpers.py
index 9c1ec9848bf1..fa29aa3cd712 100644
--- a/posthog/schema_helpers.py
+++ b/posthog/schema_helpers.py
@@ -118,6 +118,7 @@ def to_dict(query: BaseModel) -> dict:
"selectedInterval",
"funnelStepReference",
"breakdownSorting",
+ "legendPosition",
]
}
diff --git a/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.test.tsx b/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.test.tsx
index 3cf0f2715da5..3d1d6e83edaa 100644
--- a/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.test.tsx
+++ b/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.test.tsx
@@ -719,7 +719,7 @@ describe('TrendsBarChart overlays', () => {
})
const legendEl = getInChartLegend(container)
- expect(legendEl.textContent).toContain('$pageview')
+ expect(legendEl.textContent).toContain('Pageview')
expect(legendEl.textContent).toContain('Napped')
})
})
diff --git a/products/product_analytics/frontend/insights/trends/TrendsBarChart/trendsBarChartTransforms.ts b/products/product_analytics/frontend/insights/trends/TrendsBarChart/trendsBarChartTransforms.ts
index 27b41eae1500..a32391a5804b 100644
--- a/products/product_analytics/frontend/insights/trends/TrendsBarChart/trendsBarChartTransforms.ts
+++ b/products/product_analytics/frontend/insights/trends/TrendsBarChart/trendsBarChartTransforms.ts
@@ -3,6 +3,7 @@ import type { Series, TimeInterval, TimeSeriesBarChartConfig } from '@posthog/qu
import { COMPARE_PREVIOUS_DIM_OPACITY, dimHexColor } from '../shared/compareDimming'
import { schemaGoalLinesToConfigs } from '../shared/goalLinesAdapter'
+import { humanizeSeriesLabel } from '../shared/humanizeSeriesLabel'
import { buildTrendsYAxisConfig } from '../shared/trendsAxisFormat'
import type { GoalLineLike, YFormatterFields } from '../shared/trendsChartDisplayOptions'
@@ -62,7 +63,7 @@ function buildMainTrendsBarSeries<R extends TrendsBarResultLike, M = unknown>(
const yAxisId = opts.showMultipleYAxes && index > 0 ? `y${index}` : DEFAULT_Y_AXIS_ID
return {
key: String(r.id),
- label: r.label ?? '',
+ label: humanizeSeriesLabel(r.label),
data,
color,
meta,
diff --git a/products/product_analytics/frontend/insights/trends/TrendsLineChart/trendsChartTransforms.ts b/products/product_analytics/frontend/insights/trends/TrendsLineChart/trendsChartTransforms.ts
index 393336ccebed..5f4d0525bae3 100644
--- a/products/product_analytics/frontend/insights/trends/TrendsLineChart/trendsChartTransforms.ts
+++ b/products/product_analytics/frontend/insights/trends/TrendsLineChart/trendsChartTransforms.ts
@@ -10,6 +10,7 @@ import type {
} from '@posthog/quill-charts'
import { schemaGoalLinesToConfigs } from '../shared/goalLinesAdapter'
+import { humanizeSeriesLabel } from '../shared/humanizeSeriesLabel'
import { buildTrendsYAxisConfig } from '../shared/trendsAxisFormat'
import type { CiRangesFn, GoalLineLike, YFormatterFields } from '../shared/trendsChartDisplayOptions'
@@ -64,7 +65,7 @@ export function buildMainTrendsSeries<R extends TrendsResultLike, M = unknown>(
const meta: M | undefined = opts.buildMeta ? opts.buildMeta(r, index) : undefined
return {
key: String(r.id),
- label: r.label ?? '',
+ label: humanizeSeriesLabel(r.label),
data: r.data,
color: opts.getColor(r, index),
yAxisId,
@@ -141,7 +142,7 @@ export function buildDerivedConfigs<R extends TrendsResultLike>(
trendLines.push({
seriesKey: movingAverageKey(String(r.id)),
kind: 'linear',
- label: `${r.label ?? ''} (Moving avg)`,
+ label: `${humanizeSeriesLabel(r.label)} (Moving avg)`,
})
}
}
diff --git a/products/product_analytics/frontend/insights/trends/shared/humanizeSeriesLabel.ts b/products/product_analytics/frontend/insights/trends/shared/humanizeSeriesLabel.ts
new file mode 100644
index 000000000000..82e1ff8d454a
--- /dev/null
+++ b/products/product_analytics/frontend/insights/trends/shared/humanizeSeriesLabel.ts
@@ -0,0 +1,89 @@
+// Display names for PostHog built-in event names.
+// Keep in sync with frontend/src/taxonomy/core-filter-definitions-by-group.json (events section).
+const POSTHOG_EVENT_DISPLAY_NAMES: Record<string, string> = {
+ $$heatmap: 'Heatmap',
+ $ai_embedding: 'AI embedding (LLM)',
+ $ai_evaluation: 'AI evaluation (LLM)',
+ $ai_feedback: 'AI feedback (LLM)',
+ $ai_generation: 'AI generation (LLM)',
+ $ai_metric: 'AI metric (LLM)',
+ $ai_span: 'AI span (LLM)',
+ $ai_tag: 'AI tag (LLM)',
+ $ai_trace: 'AI trace (LLM)',
+ $autocapture: 'Autocapture',
+ $capture_metrics: 'Capture metrics',
+ $conversation_message_received: 'Conversation message received',
+ $conversation_message_sent: 'Conversation message sent',
+ $conversation_ticket_assigned: 'Conversation ticket assigned',
+ $conversation_ticket_created: 'Conversation ticket created',
+ $conversation_ticket_priority_changed: 'Conversation ticket priority changed',
+ $conversation_ticket_status_changed: 'Conversation ticket status changed',
+ $copy_autocapture: 'Clipboard autocapture',
+ $create_alias: 'Alias',
+ $csp_violation: 'CSP violation',
+ $dead_click: 'Dead click',
+ $element_viewed: 'Element viewed',
+ $error_tracking_issue_created: 'Error tracking issue created',
+ $error_tracking_issue_reopened: 'Error tracking issue reopened',
+ $error_tracking_issue_spiking: 'Error tracking issue spiking',
+ $exception: 'Exception',
+ $feature_enrollment_update: 'Feature enrollment',
+ $feature_flag_called: 'Feature flag called',
+ $feature_interaction: 'Feature interaction',
+ $feature_view: 'Feature view',
+ $groupidentify: 'Group identify',
+ $identify: 'Identify',
+ $mcp_custom: 'MCP custom event',
+ $mcp_initialize: 'MCP initialize',
+ $mcp_missing_capability: 'MCP missing capability',
+ $mcp_prompt_get: 'MCP prompt fetched',
+ $mcp_prompts_list: 'MCP prompts listed',
+ $mcp_resource_read: 'MCP resource read',
+ $mcp_resources_list: 'MCP resources listed',
+ $mcp_tool_call: 'MCP tool call',
+ $mcp_tools_list: 'MCP tools listed',
+ $merge_dangerously: 'Merge',
+ $opt_in: 'Opt in',
+ $pageleave: 'Pageleave',
+ $pageview: 'Pageview',
+ $rageclick: 'Rageclick',
+ $screen: 'Screen',
+ $set: 'Set person properties',
+ $snapshot: 'Session recording snapshot',
+ $web_vitals: 'Web vitals',
+ 'All events': 'All events',
+ 'Application backgrounded': 'Application backgrounded',
+ 'Application became active': 'Application became active',
+ 'Application installed': 'Application installed',
+ 'Application opened': 'Application opened',
+ 'Application updated': 'Application updated',
+ 'Deep link opened': 'Deep link opened',
+ 'mcp feedback submitted': 'MCP feedback submitted',
+ 'mcp init': 'MCP init',
+ 'mcp organization switched': 'MCP organization switched',
+ 'mcp project switched': 'MCP project switched',
+ 'mcp tool call': 'MCP tool call (mcpcat)',
+ 'mcp tool response': 'MCP tool response (mcpcat)',
+ mcp_custom: 'MCP custom event',
+ mcp_initialize: 'MCP initialize',
+ 'mcp_mcpcat:identify': 'MCP identify (mcpcat)',
+ 'mcp_posthog:identify': 'MCP identify (in-tree)',
+ mcp_prompt_get: 'MCP prompt fetched',
+ mcp_prompts_list: 'MCP prompts listed',
+ mcp_resource_read: 'MCP resource read',
+ mcp_resources_list: 'MCP resources listed',
+ mcp_tool_call: 'MCP tool call',
+ mcp_tool_called: 'MCP tool called (in-tree)',
+ mcp_tools_list: 'MCP tools listed',
+ posthog_identify: 'MCP identify',
+}
+
+/** Returns the human-friendly display name for a series label.
+ * Resolves PostHog built-in event names ($pageview → Pageview); passes
+ * everything else through unchanged. Safe to call with null/undefined. */
+export function humanizeSeriesLabel(label: string | null | undefined): string {
+ if (!label) {
+ return ''
+ }
+ return POSTHOG_EVENT_DISPLAY_NAMES[label] ?? label
+}