: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): show breakdown baseline in the compare chart (#68744)
Thomas Obermüller62032f1a905e
diff --git a/frontend/src/scenes/funnels/funnelDataLogic.test.ts b/frontend/src/scenes/funnels/funnelDataLogic.test.tsindex f28e66a1ab1d..50abcb1f9e65 100644--- a/frontend/src/scenes/funnels/funnelDataLogic.test.ts+++ b/frontend/src/scenes/funnels/funnelDataLogic.test.ts@@ -1654,15 +1654,19 @@ describe('funnelDataLogic', () => {const steps = logic.values.visibleStepsWithConversionMetricsexpect(steps).toHaveLength(2)- // Chrome (current 100) outranks Safari (current 40): Chrome pair first, then Safari pair,- // current before previous within each value.- expect(steps[0].nested_breakdown?.map((b) => [b.breakdown_value, b.compare_label])).toEqual([- [['Chrome'], 'current'],- [['Chrome'], 'previous'],- [['Safari'], 'current'],- [['Safari'], 'previous'],+ // The baseline pair (both periods aggregated) leads, then Chrome (current 100) outranks+ // Safari (current 40): each value's pair grouped, current before previous.+ expect(+ steps[0].nested_breakdown?.map((b) => [getVisibilityKey(b.breakdown_value), b.compare_label])+ ).toEqual([+ ['Baseline', 'current'],+ ['Baseline', 'previous'],+ ['Chrome', 'current'],+ ['Chrome', 'previous'],+ ['Safari', 'current'],+ ['Safari', 'previous'],])- expect(steps[0].nested_breakdown?.map((b) => b.count)).toEqual([100, 80, 40, 25])+ expect(steps[0].nested_breakdown?.map((b) => b.count)).toEqual([140, 105, 100, 80, 40, 25])// The step's aggregate (shown in the legend) is the current period's total only —// not current+previous summed together.@@ -1670,33 +1674,51 @@ describe('funnelDataLogic', () => {expect(steps[1].count).toBe(70) // 50 Chrome + 20 Safari})- it('shares each period’s height across its breakdown values at the first step (larger period fills)', async () => {+ it('shares each period’s height across its breakdown values (larger period fills), keeping the first-step basis at later steps', async () => {await loadBreakdownCompare(funnelResultStepsBreakdownCompare.result)- const [chromeCur, chromePrev, safariCur, safariPrev] =+ const [baselineCur, baselinePrev, chromeCur, chromePrev, safariCur, safariPrev] =logic.values.visibleStepsWithConversionMetrics[0].nested_breakdown!// At the first step every value converts 100% of its own entrants, so a period's values all// share one height — the period's share of the larger baseline: current (140) fills, previous- // (105) → 105/140. Chrome and Safari read identically within each period.+ // (105) → 105/140. Baseline, Chrome and Safari read identically within each period.+ expect(baselineCur.conversionRates.fromBasisStep).toBe(1)+ expect(baselinePrev.conversionRates.fromBasisStep).toBe(105 / 140)expect(chromeCur.conversionRates.fromBasisStep).toBe(1)expect(chromePrev.conversionRates.fromBasisStep).toBe(105 / 140)expect(safariCur.conversionRates.fromBasisStep).toBe(1)expect(safariPrev.conversionRates.fromBasisStep).toBe(105 / 140)++ // Later steps keep the first-step denominator (largest period's entrants, 140), so each+ // baseline bar reads as the share of that starting cohort still left: not a per-step+ // rescale, and not silently dropped past step 0.+ const [baselineCur1, baselinePrev1] = logic.values.visibleStepsWithConversionMetrics[1].nested_breakdown!+ expect(baselineCur1.count).toBe(70)+ expect(baselineCur1.conversionRates.fromBasisStep).toBe(70 / 140)+ expect(baselinePrev1.count).toBe(40)+ expect(baselinePrev1.conversionRates.fromBasisStep).toBe(40 / 140)})- it('colors each breakdown value distinctly and desaturates its previous-period bar', async () => {+ it('colors each breakdown value distinctly, desaturates its previous-period bar, and matches the table', async () => {await loadBreakdownCompare(funnelResultStepsBreakdownCompare.result)- const [chromeCur, chromePrev, safariCur, safariPrev] =+ const [baselineCur, baselinePrev, chromeCur, chromePrev, safariCur, safariPrev] =logic.values.visibleStepsWithConversionMetrics[0].nested_breakdown!const color = logic.values.getFunnelsColor- // Distinct hue per breakdown value...+ // Distinct hue per breakdown value, baseline included...expect(color(chromeCur)).not.toBe(color(safariCur))+ expect(color(baselineCur)).not.toBe(color(chromeCur))// ...with each value's previous-period bar the same hue, desaturated.+ expect(color(baselinePrev)).toBe(dimPreviousPeriodColor(color(baselineCur)))expect(color(chromePrev)).toBe(dimPreviousPeriodColor(color(chromeCur)))expect(color(safariPrev)).toBe(dimPreviousPeriodColor(color(safariCur)))++ // The chart bars now include the baseline the table always showed, in the same order, so+ // the two share colors bar-for-row instead of being shifted by one slot.+ const chartColors = logic.values.visibleStepsWithConversionMetrics[0].nested_breakdown!.map(color)+ expect(chartColors).toEqual(logic.values.flattenedBreakdowns.map(color))})it('doubles the breakdown table into one row per value and period', async () => {@@ -1745,12 +1767,14 @@ describe('funnelDataLogic', () => {builtDataNodeLogic.actions.loadDataSuccess(insight)}).toFinishAllListeners()- // Hiding Chrome drops its current AND previous bars; Safari's pair remains, still grouped.+ // Hiding Chrome drops its current AND previous bars; the baseline and Safari's pair remain.const visibleValues = logic.values.visibleStepsWithConversionMetrics[0].nested_breakdown?.map((b) => [getVisibilityKey(b.breakdown_value),b.compare_label,])expect(visibleValues).toEqual([+ ['Baseline', 'current'],+ ['Baseline', 'previous'],['Safari', 'current'],['Safari', 'previous'],])diff --git a/frontend/src/scenes/funnels/funnelDataLogic.ts b/frontend/src/scenes/funnels/funnelDataLogic.tsindex 4c1996f8c59f..5842bbd440ea 100644--- a/frontend/src/scenes/funnels/funnelDataLogic.ts+++ b/frontend/src/scenes/funnels/funnelDataLogic.ts@@ -530,17 +530,42 @@ export const funnelDataLogic = kea<funnelDataLogicType>([// 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.+ // Breakdown + compare: draw the per-period baseline pair (kept in flattenedBreakdowns)+ // as the leading grouped bars — same as the plain-breakdown path below — and shift every+ // real value's color position past the baseline's single slot so the chart bar colors+ // line up with the detailed-results table. Preserve the grouped current/previous pairing+ // and per-value orders (both periods of a value share one order, hence one color).if (isBreakdownCompareFunnel) {- return steps.map((step) => ({- ...step,- nested_breakdown: step.nested_breakdown?.filter(- (b) =>- isOnlySeries || !hiddenLegendBreakdowns?.includes(getVisibilityKey(b.breakdown_value))- ),- }))+ const baselineRows = flattenedBreakdowns.filter((b) => b.isBaseline)+ const baselineOffset = baselineRows.length > 0 ? 1 : 0+ // Size each baseline bar by its period's share of the larger period (the larger fills,+ // the smaller is proportionally shorter) — matching how the value and pure-compare bars+ // are scaled, so the previous baseline isn't drawn at full height.+ const compareBasis = Math.max(0, ...baselineRows.map((row) => row.steps?.[0]?.count ?? 0))+ return steps.map((step, stepIndex) => {+ const baselineEntries = baselineRows+ .map((row) => row.steps?.[stepIndex])+ .filter((s): s is FunnelStepWithConversionMetrics => s != null)+ .map((s) => ({+ ...s,+ order: 0,+ conversionRates: {+ ...s.conversionRates,+ fromBasisStep: compareBasis > 0 ? s.count / compareBasis : 0,+ },+ }))+ const valueEntries = (step.nested_breakdown ?? [])+ .filter(+ (b) =>+ isOnlySeries ||+ !hiddenLegendBreakdowns?.includes(getVisibilityKey(b.breakdown_value))+ )+ .map((b) => ({ ...b, order: (b.order ?? 0) + baselineOffset }))+ return {+ ...step,+ nested_breakdown: [...baselineEntries, ...valueEntries],+ }+ })}const baseLineSteps = flattenedBreakdowns.find((b) => b.isBaseline)