: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(customer-analytics): fit embedded billing charts to their container (#99247)
Arthur Moreira de Deus21e2f5be48cf
diff --git a/docs/internal/customer-analytics-billing-tabs.md b/docs/internal/customer-analytics-billing-tabs.mdnew file mode 100644index 000000000000..68e1c954a581--- /dev/null+++ b/docs/internal/customer-analytics-billing-tabs.md@@ -0,0 +1,9 @@+# Account usage and spend tabs++Usage and Spend display saved billing insights in both expanded account rows and the account detail scene.+The account supplies the organization variable, and the date filter supplies the start and end dates.+SQL variable pickers are hidden because these values are controlled by the account tab.++Supported SQL charts render through `AccountBillingChart`. Other visualizations, including series+breakdowns, render through an embedded `Query` in a fixed-height container. Embedded SQL charts fill+that container; standalone SQL insights retain their viewport-based height.diff --git a/frontend/src/queries/nodes/DataVisualization/DataVisualization.tsx b/frontend/src/queries/nodes/DataVisualization/DataVisualization.tsxindex 4dffeb960b81..68468f4d88e3 100644--- a/frontend/src/queries/nodes/DataVisualization/DataVisualization.tsx+++ b/frontend/src/queries/nodes/DataVisualization/DataVisualization.tsx@@ -191,9 +191,11 @@ function InternalDataTableVisualization(props: DataTableVisualizationProps): JSXchartSettings,dashboardId,dataVisualizationProps,- presetChartHeight,+ presetChartHeight: scenePresetChartHeight,} = useValues(dataVisualizationLogic)+ const presetChartHeight = !props.embedded && scenePresetChartHeight+const { seriesBreakdownData } = useValues(seriesBreakdownLogic({ key: dataVisualizationProps.key }))const { goalLines } = useValues(displayLogic)diff --git a/products/customer_analytics/frontend/components/Accounts/AGENTS.md b/products/customer_analytics/frontend/components/Accounts/AGENTS.mdindex 27f2cb6ee0ec..2318da776561 100644--- a/products/customer_analytics/frontend/components/Accounts/AGENTS.md+++ b/products/customer_analytics/frontend/components/Accounts/AGENTS.md@@ -193,7 +193,7 @@ The Users tab reads its loaded data straight off `accountRelatedUsersLogic`, soThe Usage and Spend tabs render existing saved billing insights — **point users to them, don't rebuild billing as new insights.**-**Customer analytics owns the billing chart render.** Each billing chart is multi-series on one shared axis, so a small-magnitude series (e.g. feature flag requests) is a flat sliver against large ones (events/enhanced persons) and can't be read. To offer per-series show/hide **without touching shared data-viz code**, `AccountBillingChart` renders the saved insight's SQL chart directly via `@posthog/quill-charts` instead of an embedded `<Query>`/DataVisualization. It reuses `dataVisualizationLogic` read-only for fetch + SQL-results→series parsing, and renders via `sqlLineGraphAdapter.ts`'s pure builders — the same series building, render dispatch, and line/bar/combo config building (per-column formatting, area fills, right-axis routing, goal and trend lines, percent stacks, plus the 200-series render cap applied locally) the SQL insight chart uses — while staying off that chart's React layer (`SqlChart`/`useSqlChartModel`). Chart-semantics changes belong in the adapter (covered by `sqlLineGraphAdapter.test.ts`), not here. Hidden series are injected into quill's controlled `legend.hiddenKeys` (excluded from drawing and scales; the rest rescale into the freed space). `AccountBillingSeriesToggle` is the control: a compact chip row under each chart, one chip per series colored to match its line/bar (items come from `legendItemsFromSeries` over the same `buildSeries` output the chart draws, so keys and colors can't drift), plus Select all / Clear all buttons at the end of the row that show or hide every series at once (`setAllSeriesHidden`, dispatched with the chart's own key list). The hidden-keys state lives in `accountBillingLogic` (`ephemeralHiddenSeriesKeysByShortId`, keyed per insight because the spend tab renders two) — per-view only: never written to the saved insight, reset on date change, gone on row collapse. Queries whose shape `AccountBillingChart` can't render (non-DataViz, table/number/pie displays, series breakdowns — see `canRenderBillingChart`) fall back to the embedded `<Query>` with no chips.+**Customer analytics owns the billing chart render.** Each billing chart is multi-series on one shared axis, so a small-magnitude series (e.g. feature flag requests) is a flat sliver against large ones (events/enhanced persons) and can't be read. To offer per-series show/hide **without touching shared data-viz code**, `AccountBillingChart` renders the saved insight's SQL chart directly via `@posthog/quill-charts` instead of an embedded `<Query>`/DataVisualization. It reuses `dataVisualizationLogic` read-only for fetch + SQL-results→series parsing, and renders via `sqlLineGraphAdapter.ts`'s pure builders — the same series building, render dispatch, and line/bar/combo config building (per-column formatting, area fills, right-axis routing, goal and trend lines, percent stacks, plus the 200-series render cap applied locally) the SQL insight chart uses — while staying off that chart's React layer (`SqlChart`/`useSqlChartModel`). Chart-semantics changes belong in the adapter (covered by `sqlLineGraphAdapter.test.ts`), not here. Hidden series are injected into quill's controlled `legend.hiddenKeys` (excluded from drawing and scales; the rest rescale into the freed space). `AccountBillingSeriesToggle` is the control: a compact chip row under each chart, one chip per series colored to match its line/bar (items come from `legendItemsFromSeries` over the same `buildSeries` output the chart draws, so keys and colors can't drift), plus Select all / Clear all buttons at the end of the row that show or hide every series at once (`setAllSeriesHidden`, dispatched with the chart's own key list). The hidden-keys state lives in `accountBillingLogic` (`ephemeralHiddenSeriesKeysByShortId`, keyed per insight because the spend tab renders two) — per-view only: never written to the saved insight, reset on date change, gone on row collapse. Queries whose shape `AccountBillingChart` can't render (non-DataViz, table/number/pie displays, series breakdowns — see `canRenderBillingChart`) fall back to the embedded `<Query>` with no chips. Billing queries stay embedded in both the account list and detail scene: the account and date filter supply SQL variables, so their read-only pickers remain hidden. Embedded SQL charts use their container height instead of the standalone insight viewport height.The Opportunities tab lists the account's Salesforce opportunities from the data-warehouse `salesforce.opportunity` table (joined by the account's `sfdc_id`). The query runs in `accountOpportunitiesLogic` rather than via a bare `<Query>` so the tab owns every state: a missing `sfdc_id` shows a "not linked to Salesforce" empty state, and because `salesforce.opportunity` is **access-gated and production-only**, a failed query degrades to a pretty hog empty state instead of a red error box. The expected denied/absent-table `QueryError` (`You don't have access to table …` / `Unknown table …`) is **not** captured to PostHog — it's the normal empty state, not a bug — while genuine, unexpected query failures are still reported (`isExpectedMissingTableError` in `accountOpportunitiesLogic`). Each opportunity name links to its Salesforce record (`SALESFORCE_ORIGIN/<id>` in `constants.ts`, the same origin the Useful links sidebar uses).diff --git a/products/customer_analytics/frontend/components/Accounts/AccountBillingExpansion.tsx b/products/customer_analytics/frontend/components/Accounts/AccountBillingExpansion.tsxindex 3ae36cc7de1b..fb99f4a84452 100644--- a/products/customer_analytics/frontend/components/Accounts/AccountBillingExpansion.tsx+++ b/products/customer_analytics/frontend/components/Accounts/AccountBillingExpansion.tsx@@ -37,12 +37,10 @@ export function AccountBillingExpansion({accountId,externalId,kind,- embedded = true,}: {accountId: stringexternalId: stringkind: AccountBillingKind- embedded?: boolean}): JSX.Element {const logic = accountBillingLogic({ accountId, externalId, kind })const { savedInsights, savedInsightsLoading, dateRange, variableOverridesByShortId, queryKeyFor } = useValues(logic)@@ -93,7 +91,7 @@ export function AccountBillingExpansion({query={insight.query}variablesOverride={variablesOverride}readOnly- embedded={embedded}+ embedded// Attach the insight's data logic to accountBillingLogic (mounted at the expanded-row// root) so the loaded results survive tab switches instead of refetching on return.attachTo={logic}diff --git a/products/customer_analytics/frontend/components/Accounts/AccountDetailTabs.tsx b/products/customer_analytics/frontend/components/Accounts/AccountDetailTabs.tsxindex ebf240787933..2b490d40a0e0 100644--- a/products/customer_analytics/frontend/components/Accounts/AccountDetailTabs.tsx+++ b/products/customer_analytics/frontend/components/Accounts/AccountDetailTabs.tsx@@ -85,26 +85,12 @@ export function AccountDetailTabs({{key: 'usage',label: 'Usage',- content: (- <AccountBillingExpansion- accountId={accountId}- externalId={externalId}- kind="usage"- embedded={embedded}- />- ),+ content: <AccountBillingExpansion accountId={accountId} externalId={externalId} kind="usage" />,},{key: 'spend',label: 'Spend',- content: (- <AccountBillingExpansion- accountId={accountId}- externalId={externalId}- kind="spend"- embedded={embedded}- />- ),+ content: <AccountBillingExpansion accountId={accountId} externalId={externalId} kind="spend" />,},{key: 'opportunities',