: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): restore drop-off vs converted click on hog-charts steps bar (#61758)
Adam Bowker7d1edb194760
diff --git a/packages/quill/packages/charts/src/charts/BarChart/BarChart.test.tsx b/packages/quill/packages/charts/src/charts/BarChart/BarChart.test.tsxindex 1bded1743b9a..6386a0275d06 100644--- a/packages/quill/packages/charts/src/charts/BarChart/BarChart.test.tsx+++ b/packages/quill/packages/charts/src/charts/BarChart/BarChart.test.tsx@@ -486,6 +486,41 @@ describe('BarChart', () => {expect(click.dataIndex).toBe(1)expect(click.series.key).toBe(key)expect(click.value).toBe(value)+ // Cursor is in the track above the bar's fill — funnel drop-off relies on this.+ expect(click.inTrackArea).toBe(true)+ }+ )++ // Complement of the track test above: a click inside the bar's filled extent must report+ // `inTrackArea: false` so funnel "converted" clicks route correctly.+ it.each<[string, number, string]>([+ ['left sub-bar (a)', 1.3, 'a'],+ ['right sub-bar (b)', 1.65, 'b'],+ ])(+ 'grouped onPointClick reports inTrackArea false when the cursor is within the bar fill — %s',+ async (_name, stepMultiplier, key) => {+ const onPointClick = jest.fn()+ const { chart } = renderHogChart(+ <BarChart+ series={SERIES}+ labels={LABELS}+ theme={THEME}+ config={{ barLayout: 'grouped' }}+ onPointClick={onPointClick}+ />+ )+ const step = dimensions.plotWidth / LABELS.length+ // Same column as the sub-bar at index 1, but just above the baseline so the+ // cursor sits inside the fill rather than in the track above it.+ fireEvent.mouseMove(chart.element, {+ clientX: dimensions.plotLeft + step * stepMultiplier,+ clientY: dimensions.plotTop + dimensions.plotHeight - 2,+ })+ fireEvent.click(chart.element)+ const click: PointClickData = onPointClick.mock.calls[0][0]+ expect(click.dataIndex).toBe(1)+ expect(click.series.key).toBe(key)+ expect(click.inTrackArea).toBe(false)})diff --git a/packages/quill/packages/charts/src/charts/BarChart/BarChart.tsx b/packages/quill/packages/charts/src/charts/BarChart/BarChart.tsxindex 95efca845191..03b104e526ec 100644--- a/packages/quill/packages/charts/src/charts/BarChart/BarChart.tsx+++ b/packages/quill/packages/charts/src/charts/BarChart/BarChart.tsx@@ -714,7 +714,11 @@ export function resolveClickedBarSeries<Meta>({continue}const hit = crossSeriesData.find((d) => d.series.key === s.key)- return hit ? rewrite(hit.series, hit.value, dataIndex) : null+ if (!hit) {+ return null+ }+ const inTrackArea = cursorOutsideBarFillExtent(bar, cursor, isHorizontal)+ return { ...rewrite(hit.series, hit.value, dataIndex), inTrackArea }}return null}diff --git a/packages/quill/packages/charts/src/core/types.ts b/packages/quill/packages/charts/src/core/types.tsindex 3fc52d9bd5d1..bba5778e9f5e 100644--- a/packages/quill/packages/charts/src/core/types.ts+++ b/packages/quill/packages/charts/src/core/types.ts@@ -108,6 +108,11 @@ export interface PointClickData<Meta = unknown> {/** Cursor position in pixels relative to the chart wrapper at click time, or `null`* when unavailable. Same origin as `TooltipContext.hoverPosition`. */cursor: { x: number; y: number } | null+ /** Grouped layouts only: `true` when the cursor was in the bar's band slot but beyond its+ * filled value extent — i.e. the track region above (vertical) or past (horizontal) a short+ * bar. Lets consumers route "clicked the empty remainder" differently from "clicked the bar"+ * (e.g. funnel drop-off vs converted). `undefined` outside grouped click resolution. */+ inTrackArea?: boolean}/** Context object passed to the `renderTooltip` render prop and tooltip event callbacks. */diff --git a/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/FunnelStepsBarChart.tsx b/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/FunnelStepsBarChart.tsxindex 424daf4693f5..877df46f10fd 100644--- a/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/FunnelStepsBarChart.tsx+++ b/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/FunnelStepsBarChart.tsx@@ -14,10 +14,14 @@ import { insightLogic } from 'scenes/insights/insightLogic'import { themeLogic } from '~/layout/navigation-3000/themeLogic'import { groupsModel } from '~/models/groupsModel'-import { ChartParams, type FunnelStepWithConversionMetrics } from '~/types'+import { ChartParams } from '~/types'import { FunnelStepsBarTooltip } from './FunnelStepsBarTooltip'-import { buildFunnelStepsBarData, type FunnelStepsBarSeriesMeta } from './funnelStepsBarTransforms'+import {+ buildFunnelStepsBarData,+ type FunnelStepsBarSeriesMeta,+ resolveFunnelStepClick,+} from './funnelStepsBarTransforms'const BASE_STEP_WIDTH_PX = 240const PER_BAR_WIDTH_PX = 20@@ -86,13 +90,11 @@ export function FunnelStepsBarChart({const onPointClick = useCallback((clickData: PointClickData<FunnelStepsBarSeriesMeta>): void => {- const step = steps[clickData.dataIndex]- if (!step) {+ const target = resolveFunnelStepClick(steps, clickData)+ if (!target) {return}- const breakdownIndex = clickData.series.meta?.breakdownIndex ?? 0- const variant: FunnelStepWithConversionMetrics = step.nested_breakdown?.[breakdownIndex] ?? step- openPersonsModalForSeries({ step, series: variant, converted: true })+ openPersonsModalForSeries(target)},[steps, openPersonsModalForSeries])diff --git a/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/funnelStepsBarTransforms.test.ts b/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/funnelStepsBarTransforms.test.tsindex 0d9c4e7ed51d..354228725fd6 100644--- a/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/funnelStepsBarTransforms.test.ts+++ b/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/funnelStepsBarTransforms.test.ts@@ -1,6 +1,13 @@+import type { PointClickData, Series } from '@posthog/quill-charts'+import { EntityTypes, type FunnelStepWithConversionMetrics } from '~/types'-import { buildFunnelStepsBarData, FUNNEL_STEPS_SERIES_KEY_PREFIX } from './funnelStepsBarTransforms'+import {+ buildFunnelStepsBarData,+ FUNNEL_STEPS_SERIES_KEY_PREFIX,+ type FunnelStepsBarSeriesMeta,+ resolveFunnelStepClick,+} from './funnelStepsBarTransforms'type StepOverrides = Partial<FunnelStepWithConversionMetrics> & { fromBasisStep: number }@@ -112,3 +119,48 @@ describe('buildFunnelStepsBarData', () => {expect(labels).toEqual([])})})++function makeSeries(breakdownIndex: number): Series<FunnelStepsBarSeriesMeta> {+ return {+ key: `${FUNNEL_STEPS_SERIES_KEY_PREFIX}${breakdownIndex}`,+ label: 'series',+ data: [],+ meta: { breakdownIndex },+ }+}++function makeClick(+ overrides: Partial<Pick<PointClickData<FunnelStepsBarSeriesMeta>, 'dataIndex' | 'series' | 'inTrackArea'>>+): Pick<PointClickData<FunnelStepsBarSeriesMeta>, 'dataIndex' | 'series' | 'inTrackArea'> {+ return { dataIndex: 0, series: makeSeries(0), ...overrides }+}++describe('resolveFunnelStepClick', () => {+ it.each<[string, boolean | undefined, boolean]>([+ ['filled bar (inTrackArea false) opens converted', false, true],+ ['track above the bar (inTrackArea true) opens drop-off', true, false],+ ['non-grouped click (inTrackArea undefined) falls back to converted', undefined, true],+ ])('%s', (_name, inTrackArea, expectedConverted) => {+ const target = resolveFunnelStepClick(noBreakdownSteps, makeClick({ dataIndex: 1, inTrackArea }))++ expect(target).not.toBeNull()+ expect(target?.step).toBe(noBreakdownSteps[1])+ expect(target?.series).toBe(noBreakdownSteps[1])+ expect(target?.converted).toBe(expectedConverted)+ })++ it('resolves the breakdown variant via the series meta breakdownIndex', () => {+ const target = resolveFunnelStepClick(+ breakdownSteps,+ makeClick({ dataIndex: 1, series: makeSeries(1), inTrackArea: false })+ )++ expect(target?.step).toBe(breakdownSteps[1])+ expect(target?.series).toBe(breakdownSteps[1].nested_breakdown?.[1])+ expect(target?.converted).toBe(true)+ })++ it('returns null when the clicked column has no step', () => {+ expect(resolveFunnelStepClick(noBreakdownSteps, makeClick({ dataIndex: 99 }))).toBeNull()+ })+})diff --git a/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/funnelStepsBarTransforms.ts b/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/funnelStepsBarTransforms.tsindex be9e57b24635..79ab4ffcc735 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 { Series } from '@posthog/quill-charts'+import type { PointClickData, Series } from '@posthog/quill-charts'import type { FunnelStepWithConversionMetrics } from '~/types'@@ -69,3 +69,26 @@ export function buildFunnelStepsBarData(return { series, labels: steps.map((_, stepIndex) => `${stepIndex + 1}`) }}++export interface FunnelStepClickTarget {+ step: FunnelStepWithConversionMetrics+ series: FunnelStepWithConversionMetrics+ converted: boolean+}++/** Resolves a grouped-bar click back to the funnel step, breakdown variant, and whether the+ * converted or drop-off actors should open. The bar's filled extent is the converted portion;+ * the track above it (`inTrackArea`) is the drop-off — restoring the legacy StepBar behavior.+ * Returns `null` when the click does not map to a step. */+export function resolveFunnelStepClick(+ steps: FunnelStepWithConversionMetrics[],+ clickData: Pick<PointClickData<FunnelStepsBarSeriesMeta>, 'dataIndex' | 'series' | 'inTrackArea'>+): FunnelStepClickTarget | null {+ const step = steps[clickData.dataIndex]+ if (!step) {+ return null+ }+ const breakdownIndex = clickData.series.meta?.breakdownIndex ?? 0+ const variant = step.nested_breakdown?.[breakdownIndex] ?? step+ return { step, series: variant, converted: !clickData.inTrackArea }+}