: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
fix(funnels): apply step renames made outside the rename modal (#90176)
Chris Shine263b273c2005
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex d12a275981a2..41d490981153 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -2813,9 +2813,9 @@ snapshots:insights-funnelstepsbarchart--edit-scene-viewports--wide--light:hash: v1.k794b7964.f1fe4fe0489eae529f52f1b529ade69417e36dc805969661a3395310a9230bdb.3VX77dp5R_vLBzgiXIUB58EqMoYOFsCOV02lqX-vyR8insights-funnelstepsbarchart--edit-scene-with-inline-events--dark:- hash: v1.k794b7964.b1263e91635a5275436a84330b0dad951cc9ec7fd3f0ebf4ae3e814ce9572116.V2quqTLQ2ynVvN2KbCkot7X75ZhscdQU8VyqK3mLOtg+ hash: v1.k794b7964.159e6a21bd67e5a7c7aa6e57731926b6b6f8e0677cbe6ba43df85f0eedd8e70f.psK5ocliwya-xjGAE0AFdMMhk1Nc7WRqmZ_fMo6KnZAinsights-funnelstepsbarchart--edit-scene-with-inline-events--light:- hash: v1.k794b7964.1abd3cdb07926c5bcdcd374fea9a2d410faaa62d07c5d2ddf4e18b9130189746.IOCy51-aovjU7IxbtTEBdUbT5Tc92FbeIBJlQhV9iUY+ hash: v1.k794b7964.e77a98a469ca366c0bd54dd74ebaa93c2445ff3318a4d1a4586930d6deb97b26.cxpxUwbPla-ItwYQoMr3UIrpoyRhS92QxQ212Wazqpwinsights-funneltimetoconverttable--default--dark:hash: v1.k794b7964.39fad6f5fd14cdf0e6d9e538cdc8eea2d6b0dbfc9f215c6226ae1b014b8b0c61.FEIbcPsm2lRRriC_2UPs1yryWU9SP5QiilC5IxwanY4insights-funneltimetoconverttable--default--light:diff --git a/frontend/src/scenes/funnels/funnelDataLogic.test.ts b/frontend/src/scenes/funnels/funnelDataLogic.test.tsindex d33d2988851e..5b79175c5d54 100644--- a/frontend/src/scenes/funnels/funnelDataLogic.test.ts+++ b/frontend/src/scenes/funnels/funnelDataLogic.test.ts@@ -7,9 +7,11 @@ import { AGGREGATION_LABEL_FOR_CUSTOM_DATA_WAREHOUSE } from 'scenes/insights/filimport { teamLogic } from 'scenes/teamLogic'import { dataNodeLogic } from '~/queries/nodes/DataNode/dataNodeLogic'-import { DataNode, FunnelsQuery, NodeKind } from '~/queries/schema/schema-general'+import { DataNode, FunnelsQuery, FunnelsQuerySeriesNodeUnion, NodeKind } from '~/queries/schema/schema-general'import { initKeaTests } from '~/test/init'import {+ EntityType,+ FilterLogicalOperator,FunnelConversionWindowTimeUnit,FunnelStep,FunnelVizType,@@ -432,6 +434,212 @@ describe('funnelDataLogic', () => {})})+ it.each([+ [StepOrderValue.ORDERED, '1. Visited pricing', null],+ [StepOrderValue.UNORDERED, null, null],+ ])(+ 'takes a name-based rename from the saved query for a %s funnel',+ async (funnelOrderType, ...expected) => {+ const query: FunnelsQuery = {+ kind: NodeKind.FunnelsQuery,+ series: [+ { kind: NodeKind.EventsNode, event: '$pageview', name: '1. Visited pricing' },+ { kind: NodeKind.EventsNode, event: '$pageview', name: '$pageview' },+ ],+ 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 })),+ })+ }+ )++ // A group step as the backend serializes it: `name` and `action_id` both hold the joined+ // member list, so a group's own label is machine-composed rather than typed by a person.+ const groupStep: FunnelStep = {+ ...(funnelResult.result as FunnelStep[])[0],+ action_id: '$pageview, $autocapture',+ name: '$pageview, $autocapture',+ // The backend labels a group step `group`, which `EntityType` spells `groups`.+ type: 'group' as EntityType,+ }+ const warehouseStep: FunnelStep = {+ ...(funnelResult.result as FunnelStep[])[0],+ action_id: '',+ name: 'stripe_invoices',+ type: 'data_warehouse',+ }++ const exemptCases: [string, FunnelsQuerySeriesNodeUnion, FunnelStep | null, string | null][] = [+ [+ 'a group, whose name its members compose rather than a person',+ {+ kind: NodeKind.GroupNode,+ operator: FilterLogicalOperator.Or,+ name: '$pageview, signed up',+ nodes: [+ { kind: NodeKind.EventsNode, event: '$pageview' },+ { kind: NodeKind.EventsNode, event: 'signed up' },+ ],+ },+ groupStep,+ null,+ ],+ [+ 'an action, which resolves its name at query time',+ { kind: NodeKind.ActionsNode, id: 1, name: 'Stale action name' },+ null,+ null,+ ],+ [+ 'an event the step no longer describes',+ { kind: NodeKind.EventsNode, event: 'signed up', name: '1. Signed up' },+ null,+ null,+ ],+ [+ 'the default label a new step is created with',+ { kind: NodeKind.EventsNode, event: '$pageview', name: 'Pageview' },+ null,+ null,+ ],+ ['a blank name', { kind: NodeKind.EventsNode, event: '$pageview', name: ' ' }, null, null],+ [+ 'a warehouse step whose table changed',+ {+ kind: NodeKind.FunnelsDataWarehouseNode,+ id: 'stripe_charges',+ id_field: 'id',+ table_name: 'stripe_charges',+ timestamp_field: 'created_at',+ aggregation_target_field: 'user_id',+ name: 'Paid',+ },+ warehouseStep,+ null,+ ],+ [+ 'a warehouse step renamed on its current table',+ {+ kind: NodeKind.FunnelsDataWarehouseNode,+ id: 'stripe_invoices',+ id_field: 'id',+ table_name: 'stripe_invoices',+ timestamp_field: 'created_at',+ aggregation_target_field: 'user_id',+ name: 'Invoiced',+ },+ warehouseStep,+ 'Invoiced',+ ],+ ]++ it.each(exemptCases)('resolves the step label for %s', async (_name, node, step, expected) => {+ const query: FunnelsQuery = {+ kind: NodeKind.FunnelsQuery,+ series: [node, { kind: NodeKind.EventsNode, event: '$pageview', name: '$pageview' }],+ }+ const result = [...(funnelResult.result as FunnelStep[])]+ if (step) {+ result[0] = { ...step, order: 0 }+ }+ const insight: Partial<InsightModel> = {+ filters: { insight: InsightType.FUNNELS },+ result,+ }++ await expectLogic(logic, () => {+ logic.actions.updateQuerySource(query)+ builtDataNodeLogic.actions.loadDataSuccess(insight)+ }).toMatchValues({+ steps: [+ expect.objectContaining({ custom_name: expected }),+ expect.objectContaining({ custom_name: null }),+ ],+ })+ })++ it('labels a renamed step the same way before and after results arrive', async () => {+ const query: FunnelsQuery = {+ kind: NodeKind.FunnelsQuery,+ series: [+ { kind: NodeKind.EventsNode, event: '$pageview', name: '1. Visited pricing' },+ { kind: NodeKind.EventsNode, event: '$pageview', name: '$pageview' },+ ],+ }+ const insight: Partial<InsightModel> = {+ filters: { insight: InsightType.FUNNELS },+ result: funnelResult.result,+ }++ // `stepNames` is the label source the flow graph falls back to while results load.+ await expectLogic(logic, () => {+ logic.actions.updateQuerySource(query)+ }).toMatchValues({+ stepNames: [+ expect.objectContaining({ custom_name: '1. Visited pricing' }),+ expect.objectContaining({ custom_name: null, name: '$pageview' }),+ ],+ })++ await expectLogic(logic, () => {+ builtDataNodeLogic.actions.loadDataSuccess(insight)+ }).toMatchValues({+ steps: [+ expect.objectContaining({ custom_name: '1. Visited pricing' }),+ expect.objectContaining({ custom_name: null }),+ ],+ })+ })++ it('applies a rename to an all-events step before and after results arrive', async () => {+ const query: FunnelsQuery = {+ kind: NodeKind.FunnelsQuery,+ series: [+ // An all-events step carries no event key, so a `name` set here is a rename+ // made outside the modal, the same as for a named event.+ { kind: NodeKind.EventsNode, event: null, name: 'Signed-up funnel start' },+ { kind: NodeKind.EventsNode, event: '$pageview', name: '$pageview' },+ ],+ }+ // The backend serializes an all-events step with a null name and action_id.+ const result = [...(funnelResult.result as FunnelStep[])]+ result[0] = { ...result[0], action_id: null as unknown as string, name: null as unknown as string }+ const insight: Partial<InsightModel> = {+ filters: { insight: InsightType.FUNNELS },+ result,+ }++ await expectLogic(logic, () => {+ logic.actions.updateQuerySource(query)+ }).toMatchValues({+ stepNames: [+ expect.objectContaining({+ custom_name: 'Signed-up funnel start',+ name: 'Signed-up funnel start',+ }),+ expect.objectContaining({ custom_name: null, name: '$pageview' }),+ ],+ })++ await expectLogic(logic, () => {+ builtDataNodeLogic.actions.loadDataSuccess(insight)+ }).toMatchValues({+ steps: [+ expect.objectContaining({ custom_name: 'Signed-up funnel start' }),+ expect.objectContaining({ custom_name: null }),+ ],+ })+ })+it('with breakdown', async () => {const insight: Partial<InsightModel> = {filters: {diff --git a/frontend/src/scenes/funnels/funnelDataLogic.ts b/frontend/src/scenes/funnels/funnelDataLogic.tsindex 38176207e6cd..46c003dc9117 100644--- a/frontend/src/scenes/funnels/funnelDataLogic.ts+++ b/frontend/src/scenes/funnels/funnelDataLogic.ts@@ -5,6 +5,7 @@ import { BIN_COUNT_AUTO } from 'lib/constants'import { dayjs } from 'lib/dayjs'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { average, percentage, sum } from 'lib/utils/numbers'+import { ensureStringIsNotBlank } from 'lib/utils/strings'import {BreakdownColorConfig,computeTileFallbackTokens,@@ -18,6 +19,7 @@ import { insightDataLogic } from 'scenes/insights/insightDataLogic'import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'import { keyForInsightLogicProps } from 'scenes/insights/sharedUtils'import {+ formatEventName,getFunnelDatasetKey,getFunnelDatasetPosition,getFunnelResultCustomization,@@ -191,12 +193,56 @@ function isFunnelsQueryOrLegacyFilter(return isFunnelsQuery(querySource)}+/**+ * The display override a series carries. `custom_name` is set by the "Rename graph series" modal; a+ * `name` that differs from the raw label is a rename applied through the query editor or the API.+ * Mirrors `resolve_series_custom_name` in `query_runner.py`, which the backend runs for trends only.+ *+ * `rawLabel` is the label the series shows without an override. Pass null when there is none to+ * compare against — a `name` is then indistinguishable from a default, so only `custom_name` counts.+ */+function resolveSeriesCustomName(node: FunnelsQuerySeriesNodeUnion, rawLabel: string | null): string | null {+ const customName = ensureStringIsNotBlank(node.custom_name)+ if (customName) {+ return customName+ }+ // An action resolves its name from the database at query time, so a stored copy can be stale. A+ // group composes its name from its members (`actionFilterGroupLogic`), so it is not typed by a+ // person either. Neither is evidence of a rename; both rename through `custom_name`.+ if (node.kind === NodeKind.ActionsNode || node.kind === NodeKind.GroupNode) {+ return null+ }+ const name = ensureStringIsNotBlank(node.name)+ // The picker writes the raw event key as `name`, and defaults write the label the UI renders it+ // as, so a `name` matching either form is the default rather than a rename.+ if (!name || rawLabel === null || name === rawLabel || name === formatEventName(rawLabel)) {+ return null+ }+ return name+}++/**+ * Whether a result step is still the one its series node describes. Results outlive the query that+ * produced them, so a step the node has moved off carries a label from the previous run.+ */+function describesStep(node: FunnelsQuerySeriesNodeUnion, step: FunnelStepWithNestedBreakdown): boolean {+ if (node.kind === NodeKind.EventsNode) {+ return step.action_id === (node.event ?? null)+ }+ if (node.kind === NodeKind.FunnelsDataWarehouseNode) {+ return step.name === node.table_name+ }+ return true+}+/*** 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.+ * stored-result path bypasses: the query wins in both directions. A cleared `custom_name` falls back+ * to a `name` override, and blanks the label only when `name` matches the raw key. The `name` half is+ * a widening `_apply_funnels_custom_names` does not yet share, so backend-rendered surfaces — CSV+ * exports and API consumers reading `results[].custom_name` — keep the raw label until it does.+ * Unordered funnels are exempt because they label steps by position, not by series.*/function applyQueryStepCustomNames(steps: FunnelStepWithNestedBreakdown[],@@ -213,7 +259,10 @@ function applyQueryStepCustomNames(return step}- const customName = node.custom_name || null+ // An all-events step serializes with a null name; the UI renders it as "All events", so that+ // is the raw label a rename is compared against, matching trends and the backend serializer.+ const rawLabel = node.kind === NodeKind.EventsNode && node.event == null ? 'All events' : step.name+ const customName = resolveSeriesCustomName(node, describesStep(node, step) ? rawLabel : 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) =>@@ -862,29 +911,34 @@ export const funnelDataLogic = kea<funnelDataLogicType>([return []}- return querySource.series.map((node, index) => ({- action_id:+ return querySource.series.map((node, index) => {+ // No results yet, so the raw label comes from the node itself rather than a step.+ const rawLabel =node.kind === NodeKind.ActionsNode- ? String(node.id)- : node.kind === NodeKind.EventsNode- ? (node.event ?? '')- : '',- name:- node.custom_name ||- (node.kind === NodeKind.ActionsNode? `Action ${node.id}`: node.kind === NodeKind.EventsNode- ? (node.event ?? '')- : ''),- custom_name: node.custom_name ?? null,- order: index,- count: 0,- type: (node.kind === NodeKind.ActionsNode ? 'actions' : 'events') as EntityType,- average_conversion_time: null,- median_conversion_time: null,- converted_people_url: '',- dropped_people_url: null,- }))+ ? (node.event ?? 'All events')+ : null+ // Same override rule the loaded steps use, so the label does not change on load.+ const customName = resolveSeriesCustomName(node, rawLabel)+ return {+ action_id:+ node.kind === NodeKind.ActionsNode+ ? String(node.id)+ : node.kind === NodeKind.EventsNode+ ? (node.event ?? '')+ : '',+ name: customName || rawLabel || '',+ custom_name: customName,+ order: index,+ count: 0,+ type: (node.kind === NodeKind.ActionsNode ? 'actions' : 'events') as EntityType,+ average_conversion_time: null,+ median_conversion_time: null,+ converted_people_url: '',+ dropped_people_url: null,+ }+ })},],// True when STEPS results carry compare-tagged nested bars (current + previous per step).