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): show saved funnel step custom names (#86148)

willwearing63c25a86301b
diff --git a/frontend/src/scenes/funnels/funnelDataLogic.test.ts b/frontend/src/scenes/funnels/funnelDataLogic.test.ts
index dd2230b4b53b..d33d2988851e 100644
--- a/frontend/src/scenes/funnels/funnelDataLogic.test.ts
+++ b/frontend/src/scenes/funnels/funnelDataLogic.test.ts
@@ -9,7 +9,15 @@ import { teamLogic } from 'scenes/teamLogic'
import { dataNodeLogic } from '~/queries/nodes/DataNode/dataNodeLogic'
import { DataNode, FunnelsQuery, NodeKind } from '~/queries/schema/schema-general'
import { initKeaTests } from '~/test/init'
-import { FunnelConversionWindowTimeUnit, FunnelVizType, InsightLogicProps, InsightModel, InsightType } from '~/types'
+import {
+ FunnelConversionWindowTimeUnit,
+ FunnelStep,
+ FunnelVizType,
+ InsightLogicProps,
+ InsightModel,
+ InsightType,
+ StepOrderValue,
+} from '~/types'
import {
funnelResult,
@@ -253,6 +261,60 @@ describe('funnelDataLogic', () => {
})
})
+ it('clears a custom name removed from the saved query', async () => {
+ const query: FunnelsQuery = {
+ kind: NodeKind.FunnelsQuery,
+ series: [
+ { kind: NodeKind.EventsNode, event: '$pageview' },
+ { kind: NodeKind.EventsNode, event: '$pageview' },
+ ],
+ }
+ const insight: Partial<InsightModel> = {
+ filters: { insight: InsightType.FUNNELS },
+ result: (funnelResult.result as FunnelStep[]).map((step) => ({
+ ...step,
+ custom_name: 'Removed name',
+ })),
+ }
+
+ await expectLogic(logic, () => {
+ logic.actions.updateQuerySource(query)
+ builtDataNodeLogic.actions.loadDataSuccess(insight)
+ }).toMatchValues({
+ steps: [
+ expect.objectContaining({ custom_name: null }),
+ expect.objectContaining({ custom_name: null }),
+ ],
+ })
+ })
+
+ it('gives breakdown rows their parent step custom name', async () => {
+ const query: FunnelsQuery = {
+ kind: NodeKind.FunnelsQuery,
+ series: [
+ { kind: NodeKind.EventsNode, event: '$pageview', custom_name: 'Visited pricing' },
+ { kind: NodeKind.EventsNode, event: '$pageview', custom_name: 'Started checkout' },
+ ],
+ breakdownFilter: { breakdown: '$browser', breakdown_type: 'event' },
+ }
+ const insight: Partial<InsightModel> = {
+ filters: { insight: InsightType.FUNNELS },
+ result: funnelResultWithBreakdown.result,
+ }
+
+ await expectLogic(logic, () => {
+ logic.actions.updateQuerySource(query)
+ builtDataNodeLogic.actions.loadDataSuccess(insight)
+ }).toMatchValues({
+ steps: ['Visited pricing', 'Started checkout'].map((custom_name) =>
+ expect.objectContaining({
+ custom_name,
+ nested_breakdown: expect.arrayContaining([expect.objectContaining({ custom_name })]),
+ })
+ ),
+ })
+ })
+
it('with breakdown', async () => {
const insight: Partial<InsightModel> = {
result: funnelResultWithBreakdown.result,
@@ -343,6 +405,33 @@ describe('funnelDataLogic', () => {
})
})
+ it.each([
+ [StepOrderValue.ORDERED, 'Visited pricing', 'Started checkout'],
+ [StepOrderValue.STRICT, 'Visited pricing', 'Started checkout'],
+ [StepOrderValue.UNORDERED, null, null],
+ ])('takes custom names from the saved query for a %s funnel', async (funnelOrderType, ...expected) => {
+ const query: FunnelsQuery = {
+ kind: NodeKind.FunnelsQuery,
+ series: [
+ { kind: NodeKind.EventsNode, event: '$pageview', custom_name: 'Visited pricing' },
+ { kind: NodeKind.EventsNode, event: '$pageview', custom_name: 'Started checkout' },
+ ],
+ funnelsFilter: { funnelOrderType },
+ }
+ const insight: Partial<InsightModel> = {
+ filters: { insight: InsightType.FUNNELS },
+ result: funnelResult.result,
+ }
+
+ await expectLogic(logic, () => {
+ logic.actions.updateQuerySource(query)
+ builtDataNodeLogic.actions.loadDataSuccess(insight)
+ }).toMatchValues({
+ steps: expected.map((custom_name) => expect.objectContaining({ custom_name })),
+ stepsWithConversionMetrics: expected.map((custom_name) => expect.objectContaining({ custom_name })),
+ })
+ })
+
it('with breakdown', async () => {
const insight: Partial<InsightModel> = {
filters: {
diff --git a/frontend/src/scenes/funnels/funnelDataLogic.ts b/frontend/src/scenes/funnels/funnelDataLogic.ts
index 97f526d0552a..38176207e6cd 100644
--- a/frontend/src/scenes/funnels/funnelDataLogic.ts
+++ b/frontend/src/scenes/funnels/funnelDataLogic.ts
@@ -191,6 +191,45 @@ function isFunnelsQueryOrLegacyFilter(
return isFunnelsQuery(querySource)
}
+/**
+ * Cached results carry the step names from the run that produced them, so a step renamed since then
+ * renders under its old label. Mirrors `_apply_funnels_custom_names` in `query_runner.py`, which the
+ * stored-result path bypasses: the query wins in both directions, and a cleared name blanks the label.
+ * Only `custom_name` is taken from the query — `name` stays backend-owned, since actions resolve theirs
+ * live. Unordered funnels are exempt because they label steps by position rather than by series.
+ */
+function applyQueryStepCustomNames(
+ steps: FunnelStepWithNestedBreakdown[],
+ querySource: FunnelsQuery | null
+): FunnelStepWithNestedBreakdown[] {
+ if (!querySource?.series?.length || querySource.funnelsFilter?.funnelOrderType === StepOrderValue.UNORDERED) {
+ return steps
+ }
+
+ let changed = false
+ const renamed = steps.map((step) => {
+ const node = querySource.series[step.order]
+ if (!node) {
+ return step
+ }
+
+ const customName = node.custom_name || null
+ // Nested rows are breakdown or compare variants of the same step, so they take the parent's
+ // name. Their own `order` can hold a breakdown rank, which is not a series index.
+ const nested = step.nested_breakdown?.map((row) =>
+ row.custom_name === customName ? row : { ...row, custom_name: customName }
+ )
+ const nestedChanged = nested?.some((row, i) => row !== step.nested_breakdown?.[i])
+ if (customName === step.custom_name && !nestedChanged) {
+ return step
+ }
+
+ changed = true
+ return { ...step, custom_name: customName, ...(nested ? { nested_breakdown: nested } : {}) }
+ })
+ return changed ? renamed : steps
+}
+
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface funnelDataLogicValues {
featureFlags: FeatureFlagsSet // featureFlagLogic
@@ -786,7 +825,7 @@ export const funnelDataLogic = kea<funnelDataLogicType>([
// Reshape into one step per order with current+previous as nested bars. Trends
// also tags rows with compare_label but renders via indexedSteps, so gate on STEPS.
if (isStepsFunnel && isFunnelStepsCompareResult(results)) {
- return aggregateFunnelCompareResult(results)
+ return applyQueryStepCustomNames(aggregateFunnelCompareResult(results), querySource)
}
if (isBreakdownFunnelResults(results)) {
const breakdownProperty = breakdownFilter?.breakdowns
@@ -797,11 +836,20 @@ export const funnelDataLogic = kea<funnelDataLogicType>([
// precede the plain breakdown path, which would otherwise treat each period
// as an independent breakdown value (and double-count the step aggregate).
if (isStepsFunnel && isFunnelStepsBreakdownCompareResult(results)) {
- return aggregateBreakdownCompareResult(results, breakdownProperty)
+ return applyQueryStepCustomNames(
+ aggregateBreakdownCompareResult(results, breakdownProperty),
+ querySource
+ )
}
- return aggregateBreakdownResult(results, breakdownProperty).sort((a, b) => a.order - b.order)
+ return applyQueryStepCustomNames(
+ aggregateBreakdownResult(results, breakdownProperty).sort((a, b) => a.order - b.order),
+ querySource
+ )
}
- return results.sort((a, b) => a.order - b.order)
+ return applyQueryStepCustomNames(
+ results.sort((a, b) => a.order - b.order),
+ querySource
+ )
}
return []