: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 one decimal on every funnel step rate (#119435)
Sam Penningtond5719b4eb46c
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 4b24d131aa78..bee1a88e03db 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -3875,15 +3875,15 @@ snapshots:insights-funnelstepsbarchart--bar-labels--dark:hash: v1.k794b7964.5de2ee4fdd7ba021e1af1363b1e7977b10a245ce3ae6486008b83552cc41296d.tMGnyCUxbncHrGz42VrPrOAdXqsv6oqpZP2N6hjMW48insights-funnelstepsbarchart--bar-labels--light:- hash: v1.k794b7964.e83a257faa00b86d54af31d9036282287980fb3364f113e8a0d2aecebb45ab67.abnZOn1eB9PVmogPAEiACEwtoKJtInL232ouk55ZBeU+ hash: v1.k794b7964.92a4ba706ab7e815129fda18a18edf460100e74bb965dadcd5f9523c40215479.YIUpY2DlL_TDsfoZsTO_95xWdZ7YmrcCoHbEJomgdFUinsights-funnelstepsbarchart--bar-labels-breakdown--dark:hash: v1.k794b7964.d3675eb469f32b3a3767a993ebae285cf78dadaeece9b92bd9fc5e91080b6068.Lsx3bzPCJAlujEQn8J9l7O77jhh10eNRXSiDPoVe7r4insights-funnelstepsbarchart--bar-labels-breakdown--light:hash: v1.k794b7964.2c3c0f0066ab4d0d241134e6de2ddd48c34ec5996e06067e8097a20a62922cf8.K2qM77LHmP27bs4qp40o8hdxMSEsznlBDv8V2F_BMR4insights-funnelstepsbarchart--bar-labels-many-steps--dark:- hash: v1.k794b7964.f8f7ee9285db3cd93dad1945ba60c8a785dd4884bddda6a2615fef74cef6aa74.vo-lKwvxnbnPRqLX1vuqTnFa7-t_z3l4bmsYSdq5GXM+ hash: v1.k794b7964.d8c49417def3a54db958e7bbf990e0d3b4b43e7203761d24c226b37b0cefd380.mVnR4EgzRXJHZUt-g7PmieIOc6z5lJkrQfsMjmPzzE0insights-funnelstepsbarchart--bar-labels-many-steps--light:- hash: v1.k794b7964.446c2439434ebc7c2548104754e305d55996c802f4bbba92400abe26cf131f87.J8KJa21D37xtnfweXJdk9CSYFCKkUQyv7n0RvofA1gM+ hash: v1.k794b7964.d2e4b9ce0b7c4d694825ad4faf79fc57dec0b8ec49f2d01e9ddfd105f634188d.x3V1W4dTNNFPUo2wjZO5y9O1vnIsFGfaWbfQCm9nZMQinsights-funnelstepsbarchart--breakdown--dark:hash: v1.k794b7964.790ff5760fabe3a875385fc7f09cd89d8096abf331d4b36a59abee7f0a35bc23.3uG4AjVvDhojZ8UlnAa4vzwgAdjl3zsbKVnN6ysAHlsinsights-funnelstepsbarchart--breakdown--light:diff --git a/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/FunnelStepsBarChart.tsx b/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/FunnelStepsBarChart.tsxindex 03dac1b108af..4bb1cafa35cc 100644--- a/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/FunnelStepsBarChart.tsx+++ b/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/FunnelStepsBarChart.tsx@@ -19,8 +19,8 @@ import { funnelDataLogic } from '../funnelDataLogic'import { funnelPersonsModalLogic } from '../funnelPersonsModalLogic'import { FunnelStepsBarTooltip } from './FunnelStepsBarTooltip'import {- buildFunnelStepBarLabelFormatter,buildFunnelStepsBarData,+ formatFunnelStepBarLabel,FUNNEL_STEPS_BAR_TOOLTIP_CONFIG,getConversionChipStepIndexes,resolveFunnelStepClick,@@ -85,7 +85,6 @@ export function FunnelStepsBarChart({}),[steps, getFunnelsColor])- const formatBarLabel = useMemo(() => buildFunnelStepBarLabelFormatter(series), [series])// Feeds the tooltip header only; the visible labels come from the StepLegend footer.const stepLabels = useMemo(() => steps.map((step) => String(step.custom_name ?? step.name ?? '')), [steps])@@ -194,7 +193,7 @@ export function FunnelStepsBarChart({dataAttr="funnel-steps-bar-chart-canvas"onError={handleChartError}>- {hasBarLabels && <ValueLabels valueFormatter={formatBarLabel} offset={4} />}+ {hasBarLabels && <ValueLabels valueFormatter={formatFunnelStepBarLabel} offset={4} />}{conversionChipStepIndexes.length > 0 && (<StepConversionChips steps={steps} stepIndexes={conversionChipStepIndexes} />)}diff --git a/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/funnelStepsBarTransforms.test.ts b/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/funnelStepsBarTransforms.test.tsindex 8e2d5ed54f0a..45c30df466b8 100644--- a/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/funnelStepsBarTransforms.test.ts+++ b/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/funnelStepsBarTransforms.test.ts@@ -4,7 +4,7 @@ import { EntityTypes, FunnelStepReference, type FunnelStepWithConversionMetricsimport {buildFunnelStepsBarData,- formatFunnelStepRates,+ formatFunnelStepRate,FUNNEL_STEPS_SERIES_KEY_PREFIX,getConversionChipStepIndexes,placeStepConversionChips,@@ -269,23 +269,18 @@ describe('placeStepConversionChips', () => {})})-describe('formatFunnelStepRates', () => {+describe('formatFunnelStepRate', () => {test.each([- { name: 'keeps far-apart rates whole', rates: [1, 0.8, 0.201], expected: ['100%', '80%', '20%'] },- { name: 'never shows a drop-off as 100%', rates: [1, 24861 / 24873], expected: ['100%', '99.9%'] },{- name: 'never shows a small rate as 0%',- rates: [1, 77 / 24873, 3 / 24873],- expected: ['100%', '0.3%', '<0.1%'],+ name: 'shows one decimal on close steps',+ rates: [0.909, 0.907, 0.901, 0.9, 0.015],+ expected: ['90.9%', '90.7%', '90.1%', '90.0%', '1.5%'],},- {- name: 'adds a decimal to neighbors that round the same',- rates: [0.454, 0.451, 0.2],- expected: ['45.4%', '45.1%', '20%'],- },- { name: 'keeps equal neighbors whole', rates: [2071 / 24873, 2071 / 24873], expected: ['8%', '8%'] },+ { name: 'keeps exact 0% and 100% whole', rates: [1, 0], expected: ['100%', '0%'] },+ { name: 'never shows a drop-off as 100%', rates: [24872 / 24873], expected: ['99.9%'] },+ { name: 'never shows a small rate as 0%', rates: [3 / 24873], expected: ['<0.1%'] },])('$name', ({ rates, expected }) => {- expect(formatFunnelStepRates(rates)).toEqual(expected)+ expect(rates.map((rate) => formatFunnelStepRate(rate))).toEqual(expected)})})diff --git a/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/funnelStepsBarTransforms.ts b/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/funnelStepsBarTransforms.tsindex 7b4040453a4e..45a16937b2d0 100644--- a/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/funnelStepsBarTransforms.ts+++ b/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/funnelStepsBarTransforms.ts@@ -1,4 +1,4 @@-import type { PointClickData, Series, TooltipConfig, ValueLabelFormatter } from '@posthog/quill-charts'+import type { PointClickData, TooltipConfig, ValueLabelFormatter } from '@posthog/quill-charts'import { percentage } from 'lib/utils/numbers'@@ -153,40 +153,18 @@ export function resolveFunnelStepClick(const SMALLEST_SHOWN_RATE = 0.001const LARGEST_SHOWN_RATE = 0.999-function formatPreciseRate(rate: number): string {- if (rate > 0 && rate < SMALLEST_SHOWN_RATE) {- return `<${percentage(SMALLEST_SHOWN_RATE, 1)}`+// Always one decimal: funnels with close steps or low conversion need it, and per-label rules miss cases.+export function formatFunnelStepRate(rate: number): string {+ if (rate <= 0 || rate >= 1) {+ return percentage(rate, 0)}- if (rate < 1 && rate > LARGEST_SHOWN_RATE) {- return percentage(LARGEST_SHOWN_RATE, 1)+ if (rate < SMALLEST_SHOWN_RATE) {+ return `<${percentage(SMALLEST_SHOWN_RATE, 1)}`}- return percentage(rate, 1)-}--// Adds a decimal only where a whole percentage would hide a difference, from 0%, 100% or a neighboring step.-export function formatFunnelStepRates(rates: number[]): string[] {- const wholes = rates.map((rate) => percentage(rate, 0))- return rates.map((rate, index) => {- const whole = wholes[index]- const hidesDifference =- (whole === '0%' && rate > 0) ||- (whole === '100%' && rate < 1) ||- [index - 1, index + 1].some(- (neighbor) => neighbor in rates && rates[neighbor] !== rate && wholes[neighbor] === whole- )- return hidesDifference ? formatPreciseRate(rate) : whole- })+ return percentage(Math.min(rate, LARGEST_SHOWN_RATE), 1, true)}-export function formatFunnelStepRate(rate: number): string {- return formatFunnelStepRates([rate])[0]-}--export function buildFunnelStepBarLabelFormatter(series: Pick<Series, 'data'>[]): ValueLabelFormatter {- const labels = series.map((s) => formatFunnelStepRates(s.data.map((value) => value / RATE_TO_PERCENT)))- return (value, seriesIndex, dataIndex) =>- labels[seriesIndex]?.[dataIndex] ?? formatFunnelStepRate(value / RATE_TO_PERCENT)-}+export const formatFunnelStepBarLabel: ValueLabelFormatter = (value) => formatFunnelStepRate(value / RATE_TO_PERCENT)export function getConversionChipStepIndexes(steps: FunnelStepWithConversionMetrics[],