: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(funnels): show per-period rows in compare detailed results table (#68145)
Thomas Obermüllerfeadcf52f1d1
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 7d43fa656f48..50baeaa25c12 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -5877,9 +5877,9 @@ snapshots:scenes-app-insights-funnels--funnel-left-to-right-breakdown-edit--light:hash: v1.k794b7964.74b546c76cf253175d30369f7ee3f5c1a4b6f7b68c2a094f3acf63350b0c545d.4vHP0Tt8HAgBIIQmgQY97lNOfTKAbiOCq1k1JB7g7QAscenes-app-insights-funnels--funnel-left-to-right-compare--dark:- hash: v1.k794b7964.0b73549ffdbd7ff8b55d142105452ba3d4655cc1df7beb2e05d2e3b2c19d6e6e.ind4l6a0Ihimcyji13CbKmEsHHospSpK4N50JfYl_S8+ hash: v1.k794b7964.c324ef56bb71c8bd6be1734fc952d0d748c1e7f2c29d3af5041f6c9557cd5ab0.xVrxxIsOYEr9ZWjVrfZY9EIlkFVYMnne1GnGhJZO7H4scenes-app-insights-funnels--funnel-left-to-right-compare--light:- hash: v1.k794b7964.3d708ee43b8a6a4e220a356434b90f2743b53b02df241ff3221716cb1c0e02b9.MqMSm8tBzEMEKaWtclu8Xg217fol8zFVTaG0rzIZ_uQ+ hash: v1.k794b7964.d7140c56c7b923ffc6b4ef7c4e6ee429c306ce59ba5e66845f429c1011d3790a.6oVvLragCNMr1hQ_T_8Hwtus67thdAhMPR4_k8nWqA4scenes-app-insights-funnels--funnel-left-to-right-edit--dark:hash: v1.k794b7964.c822087b9f3b4dacc14222ae665653fcd28858c9d617f2366b5e1151ec753443.AmafMWLkpuA4Ef8YS5XEP5a5fYpfNh3fUMsu47OqFGMscenes-app-insights-funnels--funnel-left-to-right-edit--light:@@ -5912,6 +5912,10 @@ snapshots:hash: v1.k794b7964.186af367d7220a6d8e08fb3e2d75b49fbf740a0a7a6fe51fd70662ae8e84352b.VEDaHnLEB6bWGXG2Ey2PgXMoeTj_eHeEXYzG9tcv7gUscenes-app-insights-funnels--funnel-top-to-bottom-breakdown--light:hash: v1.k794b7964.7bcd00bd90318d2b7f75676d74ea3216d298c2e51bc0e85ba29cf6fab0264372.YOaTHT9GG-5jzOkcc-_4eN7ECP3N5MxhsckVWuU6Tx0+ scenes-app-insights-funnels--funnel-top-to-bottom-breakdown-compare--dark:+ hash: v1.k794b7964.5ff8a0715d91c8e57bdd195c840f398c190f5474a2e5e30dc2dd77f12ded9cdb.utFlv1FJakAUeHqSczyq9p6tbHB-wA1qacoBrq4knKo+ scenes-app-insights-funnels--funnel-top-to-bottom-breakdown-compare--light:+ hash: v1.k794b7964.2bc2f48c847265069aa6776a824cb96b8e71905e212f2254eb6340b67222a420.ENDQudz4GTRaNxRpu0HPYo4gFiblMEnGZlDVdcHu7e4scenes-app-insights-funnels--funnel-top-to-bottom-breakdown-edit--dark:hash: v1.k794b7964.2824bf7b86b2602a6dda0fdd44f55469758e922b786aee1175096222c04e48fe.hhGVA6jWLUELBA-KLJWFiccDd7zRU-nm-GAd2C04uIEscenes-app-insights-funnels--funnel-top-to-bottom-breakdown-edit--light:diff --git a/frontend/src/queries/nodes/InsightViz/ResultCustomizationsModal.tsx b/frontend/src/queries/nodes/InsightViz/ResultCustomizationsModal.tsxindex 0780299ecdd5..923338ca68dc 100644--- a/frontend/src/queries/nodes/InsightViz/ResultCustomizationsModal.tsx+++ b/frontend/src/queries/nodes/InsightViz/ResultCustomizationsModal.tsx@@ -140,7 +140,8 @@ function FunnelsInfo({ dataset }: FunnelsInfoProps): JSX.Element {return (<>You are customizing the appearance of the{' '}- {dataset.breakdown_value?.[0] === 'Baseline' ? (+ {/* Pure-compare rows carry no breakdown value but customize the baseline color. */}+ {dataset.breakdown_value?.[0] === 'Baseline' || !dataset.breakdown_value ? (<b>Baseline</b>) : (<>diff --git a/frontend/src/scenes/funnels/funnelDataLogic.test.ts b/frontend/src/scenes/funnels/funnelDataLogic.test.tsindex 983fc0361ddb..f28e66a1ab1d 100644--- a/frontend/src/scenes/funnels/funnelDataLogic.test.ts+++ b/frontend/src/scenes/funnels/funnelDataLogic.test.ts@@ -1575,14 +1575,31 @@ describe('funnelDataLogic', () => {expect(previousColor).not.toBe(currentColor)})- it('exposes no breakdown table for a pure compare funnel', async () => {+ it('builds one baseline table row per period for a pure compare funnel', async () => {await loadStepsCompare(funnelResultStepsCompare.result)- // Pure compare: current/previous bars are not real breakdown values.+ // Pure compare: current/previous bars are not real breakdown values, but each period+ // still gets a baseline row in the detailed results table.expect(logic.values.isComparedFunnel).toBe(true)expect(logic.values.isBreakdownCompareFunnel).toBe(false)- // So the breakdown table / flattened breakdown rows stay empty.- expect(logic.values.flattenedBreakdowns).toEqual([])++ const rows = logic.values.flattenedBreakdowns+ expect(rows.map((r) => [r.compare_label, r.breakdownIndex, r.colorIndex, r.isBaseline])).toEqual([+ ['current', 0, 0, true],+ ['previous', 1, 0, true],+ ])+ // Rows carry no breakdown value so their color/customization key matches the chart bars.+ expect(rows.map((r) => r.breakdown_value)).toEqual([undefined, undefined])+ // Each row aggregates its own period: current 200->100, previous 150->60.+ expect(rows[0].steps?.map((s) => s.count)).toEqual([200, 100])+ expect(rows[1].steps?.map((s) => s.count)).toEqual([150, 60])+ expect(rows[0].conversionRates?.total).toBe(0.5)+ expect(rows[1].conversionRates?.total).toBe(0.4)++ // The previous row's ribbon is the dimmed current color, matching the chart bars.+ expect(logic.values.getFunnelsColor(rows[1])).toBe(+ dimPreviousPeriodColor(logic.values.getFunnelsColor(rows[0]))+ )})it('leaves a non-compared steps funnel unchanged (single bar per step)', async () => {@@ -1682,19 +1699,36 @@ describe('funnelDataLogic', () => {expect(color(safariPrev)).toBe(dimPreviousPeriodColor(color(safariCur)))})- it('keeps the breakdown table populated with the real breakdown values', async () => {+ it('doubles the breakdown table into one row per value and period', async () => {await loadBreakdownCompare(funnelResultStepsBreakdownCompare.result)// Breakdown + compare is distinguished from pure compare so breakdown behavior survives.expect(logic.values.isComparedFunnel).toBe(true)expect(logic.values.isBreakdownCompareFunnel).toBe(true)- // The table is built from the current-period bars: one row per real value (Chrome,- // Safari), not one per period — the compare periods are not breakdown values.- const breakdownValues = logic.values.flattenedBreakdowns- .filter((b) => !b.isBaseline)- .map((b) => getVisibilityKey(b.breakdown_value))- expect(breakdownValues).toEqual(['Chrome', 'Safari'])+ const rows = logic.values.flattenedBreakdowns+ expect(rows.map((r) => [getVisibilityKey(r.breakdown_value), r.compare_label])).toEqual([+ ['Baseline', 'current'],+ ['Baseline', 'previous'],+ ['Chrome', 'current'],+ ['Chrome', 'previous'],+ ['Safari', 'current'],+ ['Safari', 'previous'],+ ])+ // Unique row keys with pair-shared color positions.+ expect(rows.map((r) => r.breakdownIndex)).toEqual([0, 1, 2, 3, 4, 5])+ expect(rows.map((r) => r.colorIndex)).toEqual([0, 0, 1, 1, 2, 2])++ // The previous baseline has no upstream aggregate — it's synthesized from the previous+ // bars: 105 -> 40, with the period's weighted conversion time.+ expect(rows[1].steps?.map((s) => s.count)).toEqual([105, 40])+ expect(rows[1].conversionRates?.total).toBe(40 / 105)+ expect(rows[1].steps?.[1].average_conversion_time).toBe(4200)++ // Row ribbons pair up per value: previous is the dimmed current, distinct across values.+ const color = logic.values.getFunnelsColor+ expect(color(rows[3])).toBe(dimPreviousPeriodColor(color(rows[2])))+ expect(color(rows[2])).not.toBe(color(rows[4]))})it('hides both periods of a breakdown value when its legend entry is hidden', async () => {@@ -1721,11 +1755,12 @@ describe('funnelDataLogic', () => {['Safari', 'previous'],])- // The table still lists Chrome (just unchecked), so it can be toggled back on.+ // The table still lists both of Chrome's period rows (just unchecked), so it can be+ // toggled back on.const breakdownValues = logic.values.flattenedBreakdowns.filter((b) => !b.isBaseline).map((b) => getVisibilityKey(b.breakdown_value))- expect(breakdownValues).toEqual(['Chrome', 'Safari'])+ expect(breakdownValues).toEqual(['Chrome', 'Chrome', 'Safari', 'Safari'])})})})diff --git a/frontend/src/scenes/funnels/funnelDataLogic.ts b/frontend/src/scenes/funnels/funnelDataLogic.tsindex 5b9ee20eee6e..4c1996f8c59f 100644--- a/frontend/src/scenes/funnels/funnelDataLogic.ts+++ b/frontend/src/scenes/funnels/funnelDataLogic.ts@@ -49,6 +49,8 @@ import {aggregationLabelForHogQL,dimPreviousPeriodColor,flattenedStepsByBreakdown,+ flattenedStepsByBreakdownCompare,+ flattenedStepsByCompare,getIncompleteConversionWindowStartDate,getLastFilledStep,getReferenceStep,@@ -475,19 +477,14 @@ export const funnelDataLogic = kea<funnelDataLogicType>([isComparedFunnel: boolean,isBreakdownCompareFunnel: boolean): FlattenedFunnelStepByBreakdown[] => {- // Pure compare's current/previous bars are not breakdown values — no breakdown table.- if (isComparedFunnel && !isBreakdownCompareFunnel) {- return []- }- // Breakdown + compare: build the table from the current-period bars so each real- // breakdown value yields one row (not one row per period).- const tableSteps = isBreakdownCompareFunnel- ? steps.map((step) => ({- ...step,- nested_breakdown: step.nested_breakdown?.filter((b) => b.compare_label !== 'previous'),- }))- : steps- const breakdowns = flattenedStepsByBreakdown(tableSteps, funnelsFilter?.layout, disableBaseline, true)+ // Pure compare's current/previous bars are not breakdown values — one baseline row+ // per period. Breakdown × compare doubles every row into interleaved period pairs.+ const breakdowns =+ isComparedFunnel && !isBreakdownCompareFunnel+ ? flattenedStepsByCompare(steps)+ : isBreakdownCompareFunnel+ ? flattenedStepsByBreakdownCompare(steps, funnelsFilter?.layout, disableBaseline)+ : flattenedStepsByBreakdown(steps, funnelsFilter?.layout, disableBaseline, true)if (!breakdownSorting) {return breakdowns}@@ -530,7 +527,9 @@ export const funnelDataLogic = kea<funnelDataLogicType>([if (isComparedFunnel && !isBreakdownCompareFunnel) {return steps}- const isOnlySeries = flattenedBreakdowns.length <= 1+ // Count values, not rows — compare doubles rows per period, and a single-value+ // breakdown × compare funnel must not flip into multi-series hidden-legend filtering.+ const isOnlySeries = flattenedBreakdowns.filter((b) => b.compare_label !== 'previous').length <= 1// Breakdown + compare: apply hidden-legend filtering by real breakdown value, but keep// the grouped current/previous pairing and the shared per-value orders that drive the// bar colors — don't run the baseline-prepend / order-remap path below.diff --git a/frontend/src/scenes/funnels/funnelUtils.test.ts b/frontend/src/scenes/funnels/funnelUtils.test.tsindex a7fcc5b3ba8d..39da23564eb6 100644--- a/frontend/src/scenes/funnels/funnelUtils.test.ts+++ b/frontend/src/scenes/funnels/funnelUtils.test.ts@@ -1,3 +1,4 @@+import { FunnelLayout } from 'lib/constants'import { dayjs } from 'lib/dayjs'import { formatDateRange } from 'lib/utils/datetime'@@ -15,8 +16,11 @@ import {import {aggregateBreakdownCompareResult,aggregateBreakdownResult,+ aggregateFunnelCompareResult,dimPreviousPeriodColor,EMPTY_BREAKDOWN_VALUES,+ flattenedStepsByBreakdownCompare,+ flattenedStepsByCompare,funnelComparePeriodDateRange,funnelTooltipHeaderLabel,isFunnelStepsBreakdownCompareResult,@@ -560,6 +564,117 @@ describe('aggregateBreakdownCompareResult', () => {})})+describe('flattenedStepsByCompare', () => {+ it('emits no previous row when the result carries only the current period', () => {+ const flat: FunnelStep[] = [+ makeStep({+ count: 200,+ order: 0,+ breakdown: undefined,+ breakdown_value: undefined,+ compare_label: 'current',+ }),+ makeStep({+ count: 100,+ order: 1,+ breakdown: undefined,+ breakdown_value: undefined,+ compare_label: 'current',+ }),+ ]+ const steps = stepsWithConversionMetrics(aggregateFunnelCompareResult(flat), FunnelStepReference.total)++ expect(flattenedStepsByCompare(steps).map((r) => [r.rowKey, r.compare_label])).toEqual([+ ['baseline_current', 'current'],+ ])+ })+})++describe('flattenedStepsByBreakdownCompare', () => {+ const build = (): FunnelStep[][] => [+ [+ makeStep({ count: 70, order: 0, breakdown_value: 'Chrome', compare_label: 'current' }),+ makeStep({ count: 40, order: 1, breakdown_value: 'Chrome', compare_label: 'current' }),+ ],+ [+ makeStep({ count: 30, order: 0, breakdown_value: 'Safari', compare_label: 'current' }),+ makeStep({ count: 10, order: 1, breakdown_value: 'Safari', compare_label: 'current' }),+ ],+ [+ makeStep({ count: 50, order: 0, breakdown_value: 'Chrome', compare_label: 'previous' }),+ makeStep({ count: 20, order: 1, breakdown_value: 'Chrome', compare_label: 'previous' }),+ ],+ [+ makeStep({ count: 25, order: 0, breakdown_value: 'Safari', compare_label: 'previous' }),+ makeStep({ count: 5, order: 1, breakdown_value: 'Safari', compare_label: 'previous' }),+ ],+ ]+ const toSteps = (results: FunnelStep[][]): ReturnType<typeof stepsWithConversionMetrics> =>+ stepsWithConversionMetrics(aggregateBreakdownCompareResult(results, 'browser'), FunnelStepReference.total)++ // The baseline pair must key off the number of values, not nested entries — compare doubles the+ // entries, so a single value would otherwise wrongly count as "more than one breakdown".+ it.each([+ {+ scenario: 'horizontal layout: no baseline pair, color positions unshifted',+ groups: build(),+ layout: FunnelLayout.horizontal,+ disableBaseline: false,+ expectedKeys: [+ ['Chrome', 'current'],+ ['Chrome', 'previous'],+ ['Safari', 'current'],+ ['Safari', 'previous'],+ ],+ expectedColorIndexes: [0, 0, 1, 1],+ },+ {+ scenario: 'disabled baseline (experiments): no baseline rows, color positions keep the offset',+ groups: build(),+ layout: FunnelLayout.vertical,+ disableBaseline: true,+ expectedKeys: [+ ['Chrome', 'current'],+ ['Chrome', 'previous'],+ ['Safari', 'current'],+ ['Safari', 'previous'],+ ],+ expectedColorIndexes: [1, 1, 2, 2],+ },+ {+ scenario: 'single breakdown value: two period rows but no baseline pair',+ groups: build().filter((group) => group[0].breakdown_value === 'Chrome'),+ layout: FunnelLayout.vertical,+ disableBaseline: false,+ expectedKeys: [+ ['Chrome', 'current'],+ ['Chrome', 'previous'],+ ],+ expectedColorIndexes: [0, 0],+ },+ ])('$scenario', ({ groups, layout, disableBaseline, expectedKeys, expectedColorIndexes }) => {+ const rows = flattenedStepsByBreakdownCompare(toSteps(groups), layout, disableBaseline)++ expect(rows.map((r) => [getVisibilityKey(r.breakdown_value), r.compare_label])).toEqual(expectedKeys)+ expect(rows.map((r) => r.colorIndex)).toEqual(expectedColorIndexes)+ })++ it('keeps a value present in only one period as a single row', () => {+ const withoutSafariPrevious = build().filter(+ (group) => !(group[0].breakdown_value === 'Safari' && group[0].compare_label === 'previous')+ )+ const rows = flattenedStepsByBreakdownCompare(toSteps(withoutSafariPrevious), FunnelLayout.vertical, false)++ expect(rows.map((r) => [getVisibilityKey(r.breakdown_value), r.compare_label])).toEqual([+ ['Baseline', 'current'],+ ['Baseline', 'previous'],+ ['Chrome', 'current'],+ ['Chrome', 'previous'],+ ['Safari', 'current'],+ ])+ })+})+describe('funnelTooltipHeaderLabel', () => {it('shows the breakdown value alone when there is no compare', () => {expect(funnelTooltipHeaderLabel({ breakdownLabel: 'Chrome' })).toBe('Chrome')diff --git a/frontend/src/scenes/funnels/funnelUtils.tsx b/frontend/src/scenes/funnels/funnelUtils.tsxindex d2b50f93b5f5..491cb806c6c2 100644--- a/frontend/src/scenes/funnels/funnelUtils.tsx+++ b/frontend/src/scenes/funnels/funnelUtils.tsx@@ -693,6 +693,126 @@ export function flattenedStepsByBreakdown(return flattenedStepsByBreakdown}+/**+ * Build the detailed-results rows for a pure compare STEPS funnel (no breakdown): one baseline row+ * per period. Rows keep `breakdown_value` undefined so their customization key and color position+ * match the chart's compare bars — the pair shares one color token and the previous row is dimmed+ * via its `compare_label`, not a separate token.+ */+export function flattenedStepsByCompare(steps: FunnelStepWithConversionMetrics[]): FlattenedFunnelStepByBreakdown[] {+ const periodCount = steps[0]?.nested_breakdown?.length ?? 0+ const rows: FlattenedFunnelStepByBreakdown[] = []+ for (let i = 0; i < periodCount; i++) {+ const stepsInPeriod = steps+ .filter((s) => !!s?.nested_breakdown?.[i])+ .map((s) => s.nested_breakdown?.[i] as FunnelStepWithConversionMetrics)+ const compareLabel = stepsInPeriod[0]?.compare_label ?? (i === 0 ? 'current' : 'previous')+ rows.push({+ rowKey: `baseline_${compareLabel}`,+ isBaseline: true,+ breakdownIndex: i,+ colorIndex: 0,+ compare_label: compareLabel,+ steps: stepsInPeriod,+ conversionRates: {+ total: (stepsInPeriod[stepsInPeriod.length - 1]?.count ?? 0) / (stepsInPeriod[0]?.count ?? 1),+ },+ })+ }+ return rows+}++/**+ * Build the detailed-results rows for a breakdown × compare STEPS funnel: interleaved+ * current/previous row pairs per breakdown value, preceded by a per-period baseline pair when the+ * baseline is shown (vertical layout with more than one value — the same rule as plain breakdowns).+ * Both rows of a pair share a `colorIndex` so they resolve to one color token (previous dimmed).+ */+export function flattenedStepsByBreakdownCompare(+ steps: FunnelStepWithConversionMetrics[],+ layout: FunnelLayout | undefined,+ disableBaseline: boolean+): FlattenedFunnelStepByBreakdown[] {+ const rows: FlattenedFunnelStepByBreakdown[] = []+ const entries = steps[0]?.nested_breakdown ?? []+ if (!entries.length) {+ return rows+ }++ // Entries of one value share an `order` (see `aggregateBreakdownCompareResult`), so the value+ // count is the highest order + 1.+ const valueCount = Math.max(...entries.map((entry) => entry.order ?? 0)) + 1+ const hasBaseline = (layout || FunnelLayout.vertical) === FunnelLayout.vertical && valueCount > 1++ if (hasBaseline && !disableBaseline) {+ // Top-level steps already aggregate the current period (see `aggregateBreakdownCompareResult`);+ // the compare label is inherited from whichever period happened to come first, so set it explicitly.+ const currentBaselineSteps = steps.map((s) => ({+ ...s,+ nested_breakdown: undefined,+ breakdown_value: 'Baseline',+ compare_label: 'current' as const,+ }))+ // No previous-period aggregate exists upstream — synthesize one from the previous bars and+ // reuse the standard conversion math. This pass omits optional steps, so with optional steps+ // the previous baseline's `fromPrevious` references the immediately preceding step rather+ // than the last non-optional one.+ const previousBaselineSteps = stepsWithConversionMetrics(+ steps.map((s) => {+ const previousEntries = s.nested_breakdown?.filter((b) => b.compare_label === 'previous') ?? []+ return {+ ...s,+ count: previousEntries.reduce((sum, b) => sum + b.count, 0),+ average_conversion_time: calculateAverageConversionTime(previousEntries),+ median_conversion_time: null,+ nested_breakdown: undefined,+ breakdown_value: 'Baseline',+ compare_label: 'previous' as const,+ }+ }),+ FunnelStepReference.total+ )+ for (const baselineSteps of [currentBaselineSteps, previousBaselineSteps]) {+ const compareLabel = baselineSteps[0].compare_label+ rows.push({+ ...getBreakdownStepValues(baselineSteps[0], 0, true),+ rowKey: `baseline_0_${compareLabel}`,+ isBaseline: true,+ breakdownIndex: rows.length,+ colorIndex: 0,+ compare_label: compareLabel,+ steps: baselineSteps,+ conversionRates: {+ total: (baselineSteps[baselineSteps.length - 1]?.count ?? 0) / (baselineSteps[0]?.count || 1),+ },+ })+ }+ }++ // The offset follows `hasBaseline` regardless of `disableBaseline`, mirroring+ // `flattenedStepsByBreakdown`, so color positions stay stable when the baseline is suppressed.+ const baselineOffset = hasBaseline ? 1 : 0+ entries.forEach((entry, entryIndex) => {+ const stepsInSeries = steps+ .filter((s) => !!s?.nested_breakdown?.[entryIndex])+ .map((s) => s.nested_breakdown?.[entryIndex] as FunnelStepWithConversionMetrics)+ rows.push({+ ...getBreakdownStepValues(entry, rows.length),+ isBaseline: false,+ breakdownIndex: rows.length,+ colorIndex: (entry.order ?? 0) + baselineOffset,+ compare_label: entry.compare_label,+ steps: stepsInSeries,+ conversionRates: {+ total: (stepsInSeries[stepsInSeries.length - 1]?.count ?? 0) / (stepsInSeries[0]?.count ?? 1),+ },+ significant: stepsInSeries.some((step) => step.significant?.total || step.significant?.fromPrevious),+ })+ })++ return rows+}+/*** Transform pre-#12113 funnel series keys to the current more reliable format.*diff --git a/frontend/src/scenes/insights/Funnels.stories.tsx b/frontend/src/scenes/insights/Funnels.stories.tsxindex 5c84ddaad587..4bd650be8d82 100644--- a/frontend/src/scenes/insights/Funnels.stories.tsx+++ b/frontend/src/scenes/insights/Funnels.stories.tsx@@ -18,6 +18,7 @@ import __funnelLeftToRightWithInlineEvents from '../../mocks/fixtures/api/projecimport __funnelTimeToConvert from '../../mocks/fixtures/api/projects/team_id/insights/funnelTimeToConvert.json'import __funnelTopToBottom from '../../mocks/fixtures/api/projects/team_id/insights/funnelTopToBottom.json'import __funnelTopToBottomBreakdown from '../../mocks/fixtures/api/projects/team_id/insights/funnelTopToBottomBreakdown.json'+import __funnelTopToBottomBreakdownCompare from '../../mocks/fixtures/api/projects/team_id/insights/funnelTopToBottomBreakdownCompare.json'type Story = StoryObj<{}>const meta: Meta = {@@ -118,6 +119,14 @@ export const FunnelTopToBottomBreakdownEdit: Story = createInsightStory(__funnelFunnelTopToBottomBreakdownEdit.parameters = {testOptions: { waitForSelector: ['[data-attr=funnel-bar-horizontal] canvas[role="img"]'] },}+// Breakdown × compare: each value renders a current and a (desaturated) previous bar, and the+// detailed results table doubles into per-period rows tagged Current/Previous. The funnels-compare+// flag gates the toggle — without it the compare data degrades and the snapshot is wrong.+export const FunnelTopToBottomBreakdownCompare: Story = createInsightStory(__funnelTopToBottomBreakdownCompare as any)+FunnelTopToBottomBreakdownCompare.parameters = {+ featureFlags: [FEATURE_FLAGS.PRODUCT_ANALYTICS_FUNNELS_COMPARE],+ testOptions: { waitForSelector: ['[data-attr=funnel-bar-horizontal] canvas[role="img"]'] },+}export const FunnelHistoricalTrends: Story = createInsightStory(__funnelHistoricalTrends as any)FunnelHistoricalTrends.parameters = {testOptions: { waitForSelector: '[data-attr=trend-line-graph-funnel] > canvas' },diff --git a/frontend/src/scenes/insights/utils.tsx b/frontend/src/scenes/insights/utils.tsxindex 0da837549bd1..2eec38ace22d 100644--- a/frontend/src/scenes/insights/utils.tsx+++ b/frontend/src/scenes/insights/utils.tsx@@ -625,7 +625,7 @@ export function getFunnelDatasetPosition(return disableFunnelBreakdownBaseline ? (dataset.order ?? 0) + 1 : (dataset.order ?? 0)}- return dataset?.breakdownIndex ?? 0+ return dataset?.colorIndex ?? dataset?.breakdownIndex ?? 0}export function getTrendResultCustomizationKey(diff --git a/frontend/src/scenes/insights/views/Funnels/FunnelStepsTable.tsx b/frontend/src/scenes/insights/views/Funnels/FunnelStepsTable.tsxindex 47e599d2ebec..cf1e01657ba4 100644--- a/frontend/src/scenes/insights/views/Funnels/FunnelStepsTable.tsx+++ b/frontend/src/scenes/insights/views/Funnels/FunnelStepsTable.tsx@@ -2,7 +2,7 @@ import { useActions, useValues } from 'kea'import { compare as compareFn } from 'natural-orderby'import { IconFlag } from '@posthog/icons'-import { LemonColorButton } from '@posthog/lemon-ui'+import { LemonColorButton, LemonTag } from '@posthog/lemon-ui'import { EntityFilterInfo } from 'lib/components/EntityFilterInfo'import { LemonCheckbox } from 'lib/lemon-ui/LemonCheckbox'@@ -11,6 +11,7 @@ import { LemonTable, LemonTableColumn, LemonTableColumnGroup } from 'lib/lemon-uimport { Lettermark, LettermarkColor } from 'lib/lemon-ui/Lettermark'import { humanFriendlyDuration } from 'lib/utils/durations'import { humanFriendlyNumber, percentage } from 'lib/utils/numbers'+import { capitalizeFirstLetter } from 'lib/utils/strings'import { funnelDataLogic } from 'scenes/funnels/funnelDataLogic'import { funnelPersonsModalLogic } from 'scenes/funnels/funnelPersonsModalLogic'import { getVisibilityKey } from 'scenes/funnels/funnelUtils'@@ -39,7 +40,8 @@ export function FunnelStepsTable(): JSX.Element | null {const { openPersonsModalForSeries } = useActions(funnelPersonsModalLogic(insightProps))const { openModal } = useActions(resultCustomizationsModalLogic(insightProps))- const isOnlySeries = flattenedBreakdowns.length <= 1+ // Count values, not rows — compare mode shows one row per period for each value.+ const isOnlySeries = flattenedBreakdowns.filter((b) => b.compare_label !== 'previous').length <= 1const { allCohorts } = useValues(cohortsModel)const { formatPropertyValueForDisplay } = useValues(propertyDefinitionsModel)@@ -69,10 +71,17 @@ export function FunnelStepsTable(): JSX.Element | null {<LemonCheckboxchecked={allChecked ? true : someChecked ? 'indeterminate' : false}onChange={() => {- // Either toggle all breakdowns on or off+ // Either toggle all breakdowns on or off. Deduped — both rows of+ // a compare pair share one visibility key.setHiddenLegendBreakdowns(allChecked- ? flattenedBreakdowns.map((b) => getVisibilityKey(b.breakdown_value))+ ? Array.from(+ new Set(+ flattenedBreakdowns.map((b) =>+ getVisibilityKey(b.breakdown_value)+ )+ )+ ): [])}}@@ -122,14 +131,24 @@ export function FunnelStepsTable(): JSX.Element | null {const color = getFunnelsColor(breakdown)+ // Pure-compare rows carry no breakdown value (their color/customization key+ // must match the chart bars), so fall back to the baseline label.+ const labelText =+ formatBreakdownLabel(+ value,+ breakdownFilter,+ allCohorts.results,+ formatPropertyValueForDisplay+ ) || (breakdown.isBaseline ? 'Baseline' : '')+const label = (<div className="flex justify-between items-center">- {formatBreakdownLabel(- value,- breakdownFilter,- allCohorts.results,- formatPropertyValueForDisplay- )}+ <span className="inline-flex items-center gap-2">+ {labelText}+ {breakdown.compare_label && (+ <LemonTag>{capitalizeFirstLetter(breakdown.compare_label)}</LemonTag>+ )}+ </span>{showCustomizationIcon && (<LemonColorButtononClick={() => openModal(breakdown)}diff --git a/frontend/src/types.ts b/frontend/src/types.tsindex 6e940358a849..81d304713af7 100644--- a/frontend/src/types.ts+++ b/frontend/src/types.ts@@ -3489,6 +3489,10 @@ export interface FlattenedFunnelStepByBreakdown {// :KLUDGE: Data transforms done in `getBreakdownStepValues`breakdown_value?: Array<string | number>breakdownIndex?: number+ /** Compare period this row represents; both rows of a pair share breakdown_value and color. */+ compare_label?: 'current' | 'previous'+ /** Color position shared by both rows of a compare pair; falls back to breakdownIndex. */+ colorIndex?: numberconversionRates?: {total: number}