: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(insights): use the API's per-bucket labels on the stickiness x-axis (#93575)
Jack Tomeiecc416f59275
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex c38cbdf7794d..01310122085d 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -3133,21 +3133,21 @@ snapshots:insights-sqlscattergraph--multiple-series-with-legend--light:hash: v1.k794b7964.126c1ab8792efb2eb2067a114290f8b15d0c6d8101e7a9f6ab03421ccf09d7b3.H-ayjpYGiaEvQ22GkDbmDuI1dBPgmvemo9RLaS7j8Vcinsights-stickinessbarchart--stacked--dark:- hash: v1.k794b7964.d5be1db7b3a836f2079373df9e450e82c6ce0f3b0527a9293037f1191289004f.PSzZmvwfQYG3q0lT4lis8t8f_4y7NfSJZu-FY9RQIGA+ hash: v1.k794b7964.dc96a61b394d20182806edb45772810c353fc65350894b83e2ebf22e873cba59.SQhn9fGEwyUYKQKdw1Almb1NVAWBeSaxz21dcAybdhwinsights-stickinessbarchart--stacked--light:- hash: v1.k794b7964.5910c399514ebe819eb8b8537f3b43e161585df9984f6966d51ccf5d4dd823b4.DB78l3dcfY_pdo3zZ-Qq_sKwMmury11oxpOfiqkI1Ew+ hash: v1.k794b7964.f74c18e85e7acd0d0c83d2a0ed272d7e2bdac5e4ad40471a6cd52bcaab056ef1.ypns-8MKic0aA5zELlNco5XYHLaYN8YZIJNbcpUzPs0insights-stickinessbarchart--unstacked--dark:- hash: v1.k794b7964.172beb9d6b152e628cbddd0fb0e2b849605e6fb32ac1d8ee56027f9cc92d217f.EEHxYE0WFIsMbwK4S9tr2sqevzl8S1aJqGdzkEKrIpY+ hash: v1.k794b7964.ccd6ea687274be6dbfc9db2d183a132c7aed0a228118f38b0bc85c95ac2f41eb.5zNmKkzSMsx_zHa52ms1B6EVJHC76dTMoBwRJN_4SLAinsights-stickinessbarchart--unstacked--light:- hash: v1.k794b7964.f68d39a4d2eba312ca9d0a706b4989f97d8340de314b2f695898d4f187f2791f.2EjkbVPglFjmVAsSJVBXqVJUG1MH7sjybYGoSjMuSKI+ hash: v1.k794b7964.d92e81e88b5b41d45ac099498db32a8bffb9806b67c866a6f28422f2c1cf71e1.FqLPZoT_1mcy6WtXOFLqG-Bkj-vAlPmVxtaC7NgvBfEinsights-stickinesslinechart--area--dark:- hash: v1.k794b7964.6adac88e74f2e675963c5feb2f452ee63ec01084b277e1549a4c0c5cd4f51eb4.0HmSO_EnoHFQMDVWtoBIvB4fGfDgsFVXx0OgMHl7IQ0+ hash: v1.k794b7964.903b10d60459a690c62517cb65262f109f872a2cef9dc156d59cbaacbd441a5f.hvt-n4_pULRoFbQNEAWh2iWiO1Ct9XtcW5THyKphpyginsights-stickinesslinechart--area--light:- hash: v1.k794b7964.f5770537b151ccf6816d0df18ab49405d8cf87936cbbc41f6722b2fbf0406912.jQ81yLsBlA6WGpPV2v4mMQOT6gHKrAKvM-XbawdAsVs+ hash: v1.k794b7964.82cfce8d03bcdf6ddda05c293acd9d711168021a4f5aec9b4dd647c558a45d15.w4CBRWPFvVL6P6It4CHAeugmbRrwmbyIuCP-NrZ0jFQinsights-stickinesslinechart--default--dark:- hash: v1.k794b7964.d364776b8ed7ba7002901b71756536dc1ee0028136e9739b2414d92dc547fb6a.KUzxS6wrm01K6FIvoQQfmGiVLBFLHGsE9jdji3sH5mM+ hash: v1.k794b7964.343e609b51a4f5650391c3ebbd672a491420fb18b0ba2407117cc946941bb2e9.NEdff_j6gYNysq0K9FpPngVh4VHNoSn_fgUP3ODI66Ainsights-stickinesslinechart--default--light:- hash: v1.k794b7964.fce3fac48f295e832697006e14ef17cb8840494c835c9fadd1df36e5ecba5fe8.oScAuhvF3d1ej90sE3nwueNzsfU5dd2QtDnh2W0sF2A+ hash: v1.k794b7964.3691c1fd17c6b2a5a844fc850df6b3c2ca5ebfee8088b4d6b1fe406dc07521f7.ZdQw5tsh6gi1NnTl1OYOmivX6Cd0d8glKOStTzAXTecinsights-trendsbarchart--aggregated-compare-breakdown--dark:hash: v1.k794b7964.85ef8d6c1f570b23b3178b895e71f9ebdf34c8d668619d0dc6b0056a30a4b246.M1jJLUgTCGwdWxX1MpRcF6eZMrkNssTizjV5HydLnIwinsights-trendsbarchart--aggregated-compare-breakdown--light:diff --git a/products/product_analytics/frontend/insights/stickiness/StickinessBarChart/StickinessBarChart.tsx b/products/product_analytics/frontend/insights/stickiness/StickinessBarChart/StickinessBarChart.tsxindex 09dfda8a27d2..18dec2daf549 100644--- a/products/product_analytics/frontend/insights/stickiness/StickinessBarChart/StickinessBarChart.tsx+++ b/products/product_analytics/frontend/insights/stickiness/StickinessBarChart/StickinessBarChart.tsx@@ -32,7 +32,6 @@ import {import { useInsightsLegendConfig } from '../../trends/shared/useInsightsLegendConfig'import { handleStickinessChartClick } from '../StickinessLineChart/handleStickinessChartClick'import {- buildStickinessLabels,buildStickinessTooltipTitle,stickinessPercentFormatter,STICKINESS_TOOLTIP_CONFIG,@@ -86,8 +85,7 @@ export function StickinessBarChart({ context }: StickinessBarChartProps): JSX.Elconst resolvedGroupTypeLabel = context?.groupTypeLabel ?? resolveGroupTypeLabel(labelGroupType, aggregationLabel)- const bucketCount = currentPeriodResult?.labels?.length ?? 0- const labels = useMemo(() => buildStickinessLabels(bucketCount, interval), [bucketCount, interval])+ const labels = currentPeriodResult?.labels ?? []const hasData = hasTrendsChartData(indexedResults)diff --git a/products/product_analytics/frontend/insights/stickiness/StickinessBarChart/stickinessBarChartTransforms.test.ts b/products/product_analytics/frontend/insights/stickiness/StickinessBarChart/stickinessBarChartTransforms.test.tsindex ec63257ffa36..9dea20208d2d 100644--- a/products/product_analytics/frontend/insights/stickiness/StickinessBarChart/stickinessBarChartTransforms.test.ts+++ b/products/product_analytics/frontend/insights/stickiness/StickinessBarChart/stickinessBarChartTransforms.test.ts@@ -14,7 +14,7 @@ describe('buildStickinessBarTimeSeriesConfig', () => {expect(buildStickinessBarTimeSeriesConfig({ isGrouped }).barLayout).toBe(expected)})- it('omits the xAxis date config (labels are pre-formatted interval counts)', () => {+ it('omits the xAxis date config, since labels come from the API per bucket', () => {expect(buildStickinessBarTimeSeriesConfig({ isGrouped: false }).xAxis).toBeUndefined()})diff --git a/products/product_analytics/frontend/insights/stickiness/StickinessBarChart/stickinessBarChartTransforms.ts b/products/product_analytics/frontend/insights/stickiness/StickinessBarChart/stickinessBarChartTransforms.tsindex d1e28ffcbb47..3f59222d445d 100644--- a/products/product_analytics/frontend/insights/stickiness/StickinessBarChart/stickinessBarChartTransforms.ts+++ b/products/product_analytics/frontend/insights/stickiness/StickinessBarChart/stickinessBarChartTransforms.ts@@ -20,7 +20,7 @@ export interface BuildStickinessBarTimeSeriesConfigOpts {export function buildStickinessBarTimeSeriesConfig(opts: BuildStickinessBarTimeSeriesConfigOpts): TimeSeriesBarChartConfig & { yAxis?: YAxisConfig } {- // No xAxis date config — labels are pre-formatted interval counts (Day 0, Day 1, …).+ // No xAxis date config: labels come from the API's own per-bucket labels (e.g. "1 day", "2 days").return {yAxis: buildStickinessYAxisConfig({ yAxisScaleType: opts.yAxisScaleType, showGrid: opts.showGrid }),valueLabels: opts.valueLabels,diff --git a/products/product_analytics/frontend/insights/stickiness/StickinessLineChart/StickinessLineChart.test.tsx b/products/product_analytics/frontend/insights/stickiness/StickinessLineChart/StickinessLineChart.test.tsxindex 09315469a3be..fb7365ca467d 100644--- a/products/product_analytics/frontend/insights/stickiness/StickinessLineChart/StickinessLineChart.test.tsx+++ b/products/product_analytics/frontend/insights/stickiness/StickinessLineChart/StickinessLineChart.test.tsx@@ -6,7 +6,7 @@ import { setupJsdom, setupSyncRaf } from '@posthog/quill-charts/testing'import { ExportType } from '~/exporter/types'import { NodeKind } from '~/queries/schema/schema-general'-import { buildStickinessQuery, chart, personsModal, renderInsight } from '~/test/insight-testing'+import { buildStickinessQuery, chart, getHogChart, personsModal, renderInsight } from '~/test/insight-testing'configure({ asyncUtilTimeout: 5000 })// With asyncUtilTimeout at 5s, a single legitimate waitFor can exhaust Jest's default@@ -37,6 +37,19 @@ describe('StickinessLineChart', () => {})})+ describe('axes', () => {+ it('labels the x-axis with the interval count per bucket, not an ordinal position', async () => {+ renderInsight({ query: buildStickinessQuery() })+ await screen.findByLabelText(/chart with 1 data series/i)++ await waitFor(() => {+ expect(getHogChart().xTicks()).toEqual(+ expect.arrayContaining(['1 day', '2 days', '3 days', '4 days', '5 days'])+ )+ })+ })+ })+describe('tooltips', () => {it('formats series values as percentages of the series total', async () => {renderInsight({ query: buildStickinessQuery() })diff --git a/products/product_analytics/frontend/insights/stickiness/StickinessLineChart/StickinessLineChart.tsx b/products/product_analytics/frontend/insights/stickiness/StickinessLineChart/StickinessLineChart.tsxindex c954ce20c03a..e53b9f18e574 100644--- a/products/product_analytics/frontend/insights/stickiness/StickinessLineChart/StickinessLineChart.tsx+++ b/products/product_analytics/frontend/insights/stickiness/StickinessLineChart/StickinessLineChart.tsx@@ -32,7 +32,6 @@ import {import { useInsightsLegendConfig } from '../../trends/shared/useInsightsLegendConfig'import { handleStickinessChartClick } from './handleStickinessChartClick'import {- buildStickinessLabels,buildStickinessLineTimeSeriesConfig,buildStickinessSeries,buildStickinessTooltipTitle,@@ -86,8 +85,7 @@ export function StickinessLineChart({ context }: StickinessLineChartProps): JSX.[breakdownFilter, allCohorts?.results, formatPropertyValueForDisplay])- const bucketCount = currentPeriodResult?.labels?.length ?? 0- const labels = useMemo(() => buildStickinessLabels(bucketCount, interval), [bucketCount, interval])+ const labels = currentPeriodResult?.labels ?? []const hasData = hasTrendsChartData(indexedResults)diff --git a/products/product_analytics/frontend/insights/stickiness/StickinessLineChart/stickinessChartTransforms.test.ts b/products/product_analytics/frontend/insights/stickiness/StickinessLineChart/stickinessChartTransforms.test.tsindex 4885093269f1..9779f6af74fa 100644--- a/products/product_analytics/frontend/insights/stickiness/StickinessLineChart/stickinessChartTransforms.test.ts+++ b/products/product_analytics/frontend/insights/stickiness/StickinessLineChart/stickinessChartTransforms.test.ts@@ -7,7 +7,6 @@ import type { SeriesDatum } from 'scenes/insights/InsightTooltip/insightTooltipUimport { ChartDisplayType } from '~/types'import {- buildStickinessLabels,buildStickinessLineTimeSeriesConfig,buildStickinessMainSeries,buildStickinessSeries,@@ -170,26 +169,6 @@ describe('stickinessChartTransforms', () => {})})- describe('buildStickinessLabels', () => {- it.each([- ['day', 3, ['Day 0', 'Day 1', 'Day 2']],- ['week', 2, ['Week 0', 'Week 1']],- ['hour', 2, ['Hour 0', 'Hour 1']],- ['month', 2, ['Month 0', 'Month 1']],- ] as const)('emits "%s"-prefixed labels by index', (interval, count, expected) => {- expect(buildStickinessLabels(count, interval)).toEqual(expected)- })-- it('defaults to "Day" when interval is null/undefined', () => {- expect(buildStickinessLabels(2, null)).toEqual(['Day 0', 'Day 1'])- expect(buildStickinessLabels(2, undefined)).toEqual(['Day 0', 'Day 1'])- })-- it('returns empty array when count is 0', () => {- expect(buildStickinessLabels(0, 'day')).toEqual([])- })- })-describe('stickinessPercentFormatter', () => {it.each([[0, '0.0%'],@@ -243,7 +222,7 @@ describe('stickinessChartTransforms', () => {expect(yAxis.scale).toBe('log')})- it('omits an xAxis date config — labels are pre-formatted interval counts', () => {+ it('omits an xAxis date config, since labels come from the API per bucket', () => {const config = buildStickinessLineTimeSeriesConfig({})expect(config.xAxis).toBeUndefined()})diff --git a/products/product_analytics/frontend/insights/stickiness/StickinessLineChart/stickinessChartTransforms.ts b/products/product_analytics/frontend/insights/stickiness/StickinessLineChart/stickinessChartTransforms.tsindex 834dac2424ff..79c81c86fe66 100644--- a/products/product_analytics/frontend/insights/stickiness/StickinessLineChart/stickinessChartTransforms.ts+++ b/products/product_analytics/frontend/insights/stickiness/StickinessLineChart/stickinessChartTransforms.ts@@ -1,7 +1,6 @@import { DEFAULT_Y_AXIS_ID } from '@posthog/quill-charts'import type { Series, TimeSeriesLineChartConfig, TooltipConfig, YAxisConfig } from '@posthog/quill-charts'-import { capitalizeFirstLetter } from 'lib/utils/strings'import type { SeriesDatum } from 'scenes/insights/InsightTooltip/insightTooltipUtils'import { ChartDisplayType } from '~/types'@@ -83,14 +82,6 @@ export function buildStickinessSeries<R extends StickinessResultLike, M = unknowreturn results.map((r, index) => buildStickinessMainSeries(r, index, opts, yAxisIds?.[index]))}-/** Produce per-bucket labels ("Day 0", "Day 1", …). The API's own "X day(s)" labels- * duplicate the interval prefix when paired with a stickiness-style axis, so we- * synthesize them from the bucket count. Mirrors `formatIntervalLabels` in the legacy LineGraph. */-export function buildStickinessLabels(count: number, interval: string | null | undefined): string[] {- const prefix = capitalizeFirstLetter(interval ?? 'day')- return Array.from({ length: count }, (_, i) => `${prefix} ${i}`)-}-/** Emit `85.0%`-style ticks — legacy parity with `${value.toFixed(1)}%` in LineGraph. */export function stickinessPercentFormatter(value: number): string {return `${value.toFixed(1)}%`@@ -134,7 +125,7 @@ export function buildStickinessLineTimeSeriesConfig(opts: BuildStickinessLineTimeSeriesConfigOpts): TimeSeriesLineChartConfig {return {- // No xAxis date config — labels are pre-formatted interval counts (Day 0, Day 1, …).+ // No xAxis date config: labels come from the API's own per-bucket labels (e.g. "1 day", "2 days").yAxis: buildStickinessYAxisConfig({ yAxisScaleType: opts.yAxisScaleType, showGrid: opts.showGrid }),valueLabels: opts.valueLabels,showCrosshair: opts.showCrosshair,