: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): load overview tiles independently of accounts list (#66360)
Arthur Moreira de Deus1d0845a6e69e
diff --git a/products/customer_analytics/frontend/components/Accounts/AGENTS.md b/products/customer_analytics/frontend/components/Accounts/AGENTS.mdindex d0e672c506c2..f41224764200 100644--- a/products/customer_analytics/frontend/components/Accounts/AGENTS.md+++ b/products/customer_analytics/frontend/components/Accounts/AGENTS.md@@ -14,10 +14,11 @@ An **Account** is a customer organization. The list is a HogQL-backed table over## Architecture-The scene renders `AccountsTabContent`, which binds one `dataNodeLogic` (key `ACCOUNTS_HOGQL_DATA_NODE_KEY`, from `../../constants`) to the query built by `accountsLogic.hogqlQuery`. Everything else reads from that bound data node or from the logics below.+The scene renders `AccountsTabContent`, which binds **two** `dataNodeLogic` instances (keys from `../../constants`): `ACCOUNTS_HOGQL_DATA_NODE_KEY` for the list rows (`accountsLogic.hogqlQuery.source`) and `ACCOUNTS_METRICS_DATA_NODE_KEY` for the overview-tile aggregations (`accountsLogic.metricsQuery`). They are deliberately split so the tiles' slower aggregations never block the list rows from rendering — each fires its own request and carries its own loading state. The table reads the list node; `accountsOverviewTilesLogic` reads the metrics node. Both queries share the same filters via `applyAccountFilters`, so they always describe the same set of accounts. Everything else reads from those bound data nodes or from the logics below.```text-AccountsTabContent ── binds dataNodeLogic(ACCOUNTS_HOGQL_DATA_NODE_KEY, accountsLogic.hogqlQuery.source)+AccountsTabContent ── binds dataNodeLogic(ACCOUNTS_HOGQL_DATA_NODE_KEY, accountsLogic.hogqlQuery.source) [list rows]+ └─ binds dataNodeLogic(ACCOUNTS_METRICS_DATA_NODE_KEY, accountsLogic.metricsQuery) [overview tiles, metrics-only]├── AccountsMaxTools registers the `open_account` Max contextual tool → accountsLogic.openAccount├── AccountsTabFilters two rows: (1) search + Refresh; (2) tags / "assigned to" (incl. unassigned-only) /│ "my accounts" on the left, AccountsOverviewTilesButton + AccountsColumnConfigurator on the right@@ -33,22 +34,22 @@ AccountsTabContent ── binds dataNodeLogic(ACCOUNTS_HOGQL_DATA_NODE_KEY, acc### Logics and what each owns-| Logic | Owns |-| ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |-| `accountsLogic` | The hub. Search (debounced), tag and assigned-to/unassigned filters, sort, inline role assignment, the `hogqlQuery` selector, shareable URL-hash view state, and `openAccount` (the Max entry point). `connect`s column-config, overview-tiles, and expansion logics. |-| `accountsViewsLogic` | Saved-views lifecycle (list/create/update/delete/select). Connects to `accountsLogic`, `accountsColumnConfigLogic`, and `accountsOverviewTilesLogic`; is the single owner of reading and writing the `ColumnConfiguration` rows for this area. |-| `accountsColumnConfigLogic` | Selected columns (`selectColumns` / `visibleColumnNames`), the column-picker groups built from the DB schema + data-warehouse joins, and the per-team saved column config (`columnConfigurations` API). |-| `accountsExpansionLogic` | Which rows are expanded (`expandedAccountIds`) and the active tab per account (`activeTabByAccount`). Pure state — no DOM, no data fetching. |-| `accountsOverviewTilesLogic` | The overview metric tiles (saved in views via `properties.tiles`); feeds `metrics` into the query. Reads legacy per-team localStorage tiles **read-only** on mount + emits an `OverviewTilesLocalStorageRead` tombstone; never writes localStorage. |-| `accountNotebooksLogic` | Notes/notebooks linked to one account (keyed by `accountId`): server-side pagination (`page`/`notebooksCount`), debounced title+content search (`searchTerm`), sort (`sorting` by created date/author), and `createNote` (creates an internal account notebook and opens it in the side panel). |-| `accountRelatedUsersLogic` | Group members / related users for one account (keyed by `externalId`). |-| `accountBillingLogic` | Billing data behind the Usage and Spend tabs (keyed by `accountId:kind`); injects the account's org + date range into saved billing insights' SQL variables. |-| `accountOpportunitiesLogic` | Salesforce opportunities behind the Opportunities tab (keyed by `accountId`): fetches the account's `sfdc_id`, then queries the data-warehouse `salesforce.opportunity` table via HogQL. Degrades to an empty state (not an error) when the table is absent — it's production-only. |-| `accountLinksLogic` | The "Useful links" sidebar for one account (keyed by `accountId`). |+| Logic | Owns |+| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |+| `accountsLogic` | The hub. Search (debounced), tag and assigned-to/unassigned filters, sort, inline role assignment, the `hogqlQuery` selector, shareable URL-hash view state, and `openAccount` (the Max entry point). `connect`s column-config, overview-tiles, and expansion logics. |+| `accountsViewsLogic` | Saved-views lifecycle (list/create/update/delete/select). Connects to `accountsLogic`, `accountsColumnConfigLogic`, and `accountsOverviewTilesLogic`; is the single owner of reading and writing the `ColumnConfiguration` rows for this area. |+| `accountsColumnConfigLogic` | Selected columns (`selectColumns` / `visibleColumnNames`), the column-picker groups built from the DB schema + data-warehouse joins, and the per-team saved column config (`columnConfigurations` API). |+| `accountsExpansionLogic` | Which rows are expanded (`expandedAccountIds`) and the active tab per account (`activeTabByAccount`). Pure state — no DOM, no data fetching. |+| `accountsOverviewTilesLogic` | The overview metric tiles (saved in views via `properties.tiles`); its `metrics` feed `accountsLogic.metricsQuery`, the separate metrics-only data node (key `ACCOUNTS_METRICS_DATA_NODE_KEY`) it reads `response`/`responseLoading` back from — independent of the list rows. Reads legacy per-team localStorage tiles **read-only** on mount + emits an `OverviewTilesLocalStorageRead` tombstone; never writes localStorage. |+| `accountNotebooksLogic` | Notes/notebooks linked to one account (keyed by `accountId`): server-side pagination (`page`/`notebooksCount`), debounced title+content search (`searchTerm`), sort (`sorting` by created date/author), and `createNote` (creates an internal account notebook and opens it in the side panel). |+| `accountRelatedUsersLogic` | Group members / related users for one account (keyed by `externalId`). |+| `accountBillingLogic` | Billing data behind the Usage and Spend tabs (keyed by `accountId:kind`); injects the account's org + date range into saved billing insights' SQL variables. |+| `accountOpportunitiesLogic` | Salesforce opportunities behind the Opportunities tab (keyed by `accountId`): fetches the account's `sfdc_id`, then queries the data-warehouse `salesforce.opportunity` table via HogQL. Degrades to an empty state (not an error) when the table is absent — it's production-only. |+| `accountLinksLogic` | The "Useful links" sidebar for one account (keyed by `accountId`). |## Data & query model-`accountsLogic.hogqlQuery` builds a `DataTableNode` wrapping an `AccountsQuery` (`select`, plus optional `search`, `tagNames`, `allRolesUnassigned`, `assignedToUserIds`, `filterExpression`, `metrics`, `orderBy`). The backend runner (`accounts_query_runner`) returns **rows as arrays** aligned to `visibleColumnNames`. `assignedToUserIds` is the "assigned to" filter — a list of user ids the runner expands into `csm IN ids OR account_executive IN ids` (the single user-facing role filter; there are no separate per-role CSM/AE/owner filters). The `allRolesUnassigned` flag (the "Unassigned only" option, surfaced inside the "Assigned to" picker — mutually exclusive with picking people via the cascade in `accountsLogic` listeners) restricts to accounts with no csm/AE/owner. The "My accounts" checkbox is a client-side shortcut: `accountsLogic` resolves it to `[currentUserId]` (from `userLogic`) before the query is sent, so the backend only ever receives explicit ids and a shared URL resolves to the same accounts for every viewer. Two cell shapes matter:+`accountsLogic.hogqlQuery` builds a `DataTableNode` wrapping an `AccountsQuery` for the list rows (`select`, plus optional `search`, `tagNames`, `allRolesUnassigned`, `assignedToUserIds`, `filterExpression`, `orderBy`). The overview-tile `metrics` are **not** on this query — `accountsLogic.metricsQuery` is a separate metrics-only `AccountsQuery` (`metrics` set, no `select`; `null` when there are no tiles) that the backend runner answers with its own aggregation query, so the tiles load without blocking the rows. Both queries share filters via `applyAccountFilters`. The backend runner (`accounts_query_runner`) returns **rows as arrays** aligned to `visibleColumnNames`, and tile aggregations in `metricsResults`. `assignedToUserIds` is the "assigned to" filter — a list of user ids the runner expands into `csm IN ids OR account_executive IN ids` (the single user-facing role filter; there are no separate per-role CSM/AE/owner filters). The `allRolesUnassigned` flag (the "Unassigned only" option, surfaced inside the "Assigned to" picker — mutually exclusive with picking people via the cascade in `accountsLogic` listeners) restricts to accounts with no csm/AE/owner. The "My accounts" checkbox is a client-side shortcut: `accountsLogic` resolves it to `[currentUserId]` (from `userLogic`) before the query is sent, so the backend only ever receives explicit ids and a shared URL resolves to the same accounts for every viewer. Two cell shapes matter:- **`name` column** (mandatory, `ACCOUNTS_NAME_COLUMN`) — emitted as `tuple(name, external_id, id)`, read as `{ name, external_id, id }`. This is the row's identity: `id` (the account PK) drives expansion/scroll/role updates; `external_id` is the copy-able group key. `getNameCell()` in `AccountsHogQLTable.tsx` is the canonical accessor; never assume a column index.- **role columns** (`csm`, `account_executive`, `account_owner`) — emitted as `tuple(id, email)`, rendered with `MemberSelect`. Sorting these uses `tupleElement(col, 2)` (email) so visual order matches.diff --git a/products/customer_analytics/frontend/components/Accounts/AccountsTabContent.tsx b/products/customer_analytics/frontend/components/Accounts/AccountsTabContent.tsxindex 7b3d2ae967f8..4743bd113027 100644--- a/products/customer_analytics/frontend/components/Accounts/AccountsTabContent.tsx+++ b/products/customer_analytics/frontend/components/Accounts/AccountsTabContent.tsx@@ -2,7 +2,7 @@ import { BindLogic, useValues } from 'kea'import { dataNodeLogic } from '~/queries/nodes/DataNode/dataNodeLogic'-import { ACCOUNTS_HOGQL_DATA_NODE_KEY } from '../../constants'+import { ACCOUNTS_HOGQL_DATA_NODE_KEY, ACCOUNTS_METRICS_DATA_NODE_KEY } from '../../constants'import { AccountsHogQLTable } from './AccountsHogQLTable'import { accountsLogic } from './accountsLogic'import { AccountsMaxTools } from './AccountsMaxTools'@@ -10,7 +10,7 @@ import { AccountsOverviewTiles } from './AccountsOverviewTiles'import { AccountsTabFilters } from './AccountsTabFilters'export function AccountsTabContent(): JSX.Element {- const { hogqlQuery } = useValues(accountsLogic)+ const { hogqlQuery, metricsQuery } = useValues(accountsLogic)return (<BindLogic@@ -20,12 +20,20 @@ export function AccountsTabContent(): JSX.Element {query: hogqlQuery.source,}}>- <div className="flex flex-col gap-3">- <AccountsMaxTools />- <AccountsTabFilters />- <AccountsOverviewTiles />- <AccountsHogQLTable />- </div>+ <BindLogic+ logic={dataNodeLogic}+ props={{+ key: ACCOUNTS_METRICS_DATA_NODE_KEY,+ query: metricsQuery,+ }}+ >+ <div className="flex flex-col gap-3">+ <AccountsMaxTools />+ <AccountsTabFilters />+ <AccountsOverviewTiles />+ <AccountsHogQLTable />+ </div>+ </BindLogic></BindLogic>)}diff --git a/products/customer_analytics/frontend/components/Accounts/accountsLogic.test.ts b/products/customer_analytics/frontend/components/Accounts/accountsLogic.test.tsindex 1a23f10c79c5..10aa1cccd6c8 100644--- a/products/customer_analytics/frontend/components/Accounts/accountsLogic.test.ts+++ b/products/customer_analytics/frontend/components/Accounts/accountsLogic.test.ts@@ -97,9 +97,15 @@ describe('accountsLogic', () => {expect(logic.values.searchQuery).toBe('')})- it('carries the overview tile metrics on the same AccountsQuery', () => {+ it('keeps the overview tile metrics off the list query so it loads independently', () => {const source = logic.values.hogqlQuery.source as AccountsQuery- expect(source.metrics).toEqual(['count()'])+ expect(source.metrics).toBeUndefined()+ })++ it('exposes the overview tile metrics on a separate metrics-only query (no select)', () => {+ const metricsQuery = logic.values.metricsQuery as AccountsQuery+ expect(metricsQuery.metrics).toEqual(['count()'])+ expect(metricsQuery.select).toBeUndefined()})it('setAllRolesUnassigned toggles the flag', () => {diff --git a/products/customer_analytics/frontend/components/Accounts/accountsLogic.ts b/products/customer_analytics/frontend/components/Accounts/accountsLogic.tsindex 1445fcc139b8..9507678cffdd 100644--- a/products/customer_analytics/frontend/components/Accounts/accountsLogic.ts+++ b/products/customer_analytics/frontend/components/Accounts/accountsLogic.ts@@ -19,7 +19,11 @@ import type {PatchedAccountApiProperties,} from 'products/customer_analytics/frontend/generated/api.schemas'-import { ACCOUNTS_HOGQL_DATA_NODE_KEY, CUSTOMER_ANALYTICS_DEFAULT_QUERY_TAGS } from '../../constants'+import {+ ACCOUNTS_HOGQL_DATA_NODE_KEY,+ ACCOUNTS_METRICS_DATA_NODE_KEY,+ CUSTOMER_ANALYTICS_DEFAULT_QUERY_TAGS,+} from '../../constants'import {ACCOUNTS_HOGQL_DEFAULT_SELECT,ACCOUNTS_NAME_COLUMN,@@ -95,6 +99,46 @@ export function deriveAccountsOrderByExpr(column: string): string {return column}+interface AccountQueryFilters {+ searchQuery: string+ tagsFilter: string[]+ allRolesUnassigned: boolean+ assignedToFilter: RoleFilterValue+ accountIdFilter: string | null+ tileFilter: TileFilter | null+}++// Shared filter clauses for the list-rows query and the overview-metrics query,+// so both always aggregate/list over the exact same set of accounts.+function applyAccountFilters(source: AccountsQuery, filters: AccountQueryFilters): void {+ const trimmed = filters.searchQuery.trim()+ if (trimmed) {+ source.search = trimmed+ }+ if (filters.tagsFilter.length > 0) {+ source.tagNames = filters.tagsFilter+ }+ if (filters.allRolesUnassigned) {+ source.allRolesUnassigned = true+ }+ if (filters.assignedToFilter.length > 0) {+ source.assignedToUserIds = filters.assignedToFilter+ }+ // Combine the overview-tile filter with the single-account filter (path route). The+ // id is the account PK; compare it stringified, matching how the name-cell id is built.+ // accountIdFilter is only ever a validated UUID (set from the route), so it's injection-safe.+ const filterExpressions: string[] = []+ if (filters.tileFilter) {+ filterExpressions.push(filters.tileFilter.expression)+ }+ if (filters.accountIdFilter) {+ filterExpressions.push(`toString(id) = '${filters.accountIdFilter}'`)+ }+ if (filterExpressions.length > 0) {+ source.filterExpression = filterExpressions.map((expr) => `(${expr})`).join(' AND ')+ }+}+const ROLE_LABELS: Record<AccountRoleKey, string> = {csm: 'CSM',account_executive: 'Account executive',@@ -323,7 +367,6 @@ export const accountsLogic = kea<accountsLogicType>([s.assignedToFilter,s.accountIdFilter,s.tileFilter,- s.overviewMetrics,s.sortOrder,s.selectColumns,],@@ -334,7 +377,6 @@ export const accountsLogic = kea<accountsLogicType>([assignedToFilter: RoleFilterValue,accountIdFilter: string | null,tileFilter: TileFilter | null,- overviewMetrics: string[],sortOrder: AccountSortOrder,selectColumns: string[]): DataTableNode => {@@ -343,35 +385,14 @@ export const accountsLogic = kea<accountsLogicType>([select: selectColumns,tags: { ...CUSTOMER_ANALYTICS_DEFAULT_QUERY_TAGS, name: 'customer_analytics_accounts_list' },}- if (overviewMetrics.length > 0) {- source.metrics = overviewMetrics- }- const trimmed = searchQuery.trim()- if (trimmed) {- source.search = trimmed- }- if (tagsFilter.length > 0) {- source.tagNames = tagsFilter- }- if (allRolesUnassigned) {- source.allRolesUnassigned = true- }- if (assignedToFilter.length > 0) {- source.assignedToUserIds = assignedToFilter- }- // Combine the overview-tile filter with the single-account filter (path route). The- // id is the account PK; compare it stringified, matching how the name-cell id is built.- // accountIdFilter is only ever a validated UUID (set from the route), so it's injection-safe.- const filterExpressions: string[] = []- if (tileFilter) {- filterExpressions.push(tileFilter.expression)- }- if (accountIdFilter) {- filterExpressions.push(`toString(id) = '${accountIdFilter}'`)- }- if (filterExpressions.length > 0) {- source.filterExpression = filterExpressions.map((expr) => `(${expr})`).join(' AND ')- }+ applyAccountFilters(source, {+ searchQuery,+ tagsFilter,+ allRolesUnassigned,+ assignedToFilter,+ accountIdFilter,+ tileFilter,+ })if (sortOrder) {const expr = deriveAccountsOrderByExpr(sortOrder.column)source.orderBy = [sortOrder.direction === 'asc' ? expr : `${expr} DESC`]@@ -388,6 +409,49 @@ export const accountsLogic = kea<accountsLogicType>([}},],+ // The overview-tile aggregations run as their own metrics-only query (no+ // `select`), keyed to ACCOUNTS_METRICS_DATA_NODE_KEY, so they load+ // independently of the list rows. Null when there are no tiles — the+ // data node then stays idle. Shares the list's filters so tiles+ // aggregate over the same set the table shows.+ metricsQuery: [+ (s) => [+ s.overviewMetrics,+ s.searchQuery,+ s.tagsFilter,+ s.allRolesUnassigned,+ s.assignedToFilter,+ s.accountIdFilter,+ s.tileFilter,+ ],+ (+ overviewMetrics: string[],+ searchQuery: string,+ tagsFilter: string[],+ allRolesUnassigned: boolean,+ assignedToFilter: RoleFilterValue,+ accountIdFilter: string | null,+ tileFilter: TileFilter | null+ ): AccountsQuery | null => {+ if (overviewMetrics.length === 0) {+ return null+ }+ const source: AccountsQuery = {+ kind: NodeKind.AccountsQuery,+ metrics: overviewMetrics,+ tags: { ...CUSTOMER_ANALYTICS_DEFAULT_QUERY_TAGS, name: 'customer_analytics_accounts_overview' },+ }+ applyAccountFilters(source, {+ searchQuery,+ tagsFilter,+ allRolesUnassigned,+ assignedToFilter,+ accountIdFilter,+ tileFilter,+ })+ return source+ },+ ],}),listeners(({ actions, values, cache }) => ({setSearchInput: async ({ query }, breakpoint) => {@@ -477,6 +541,7 @@ export const accountsLogic = kea<accountsLogicType>([sort_column: values.sortOrder?.column ?? null,})dataNodeLogic.findMounted({ key: ACCOUNTS_HOGQL_DATA_NODE_KEY })?.actions.loadData('force_async')+ dataNodeLogic.findMounted({ key: ACCOUNTS_METRICS_DATA_NODE_KEY })?.actions.loadData('force_async')},updateAccountRole: async ({ accountId, role, user }) => {if (values.isRoleSaving(accountId, role)) {@@ -499,6 +564,7 @@ export const accountsLogic = kea<accountsLogicType>([source: 'list_row',})dataNodeLogic.findMounted({ key: ACCOUNTS_HOGQL_DATA_NODE_KEY })?.actions.loadData('force_async')+ dataNodeLogic.findMounted({ key: ACCOUNTS_METRICS_DATA_NODE_KEY })?.actions.loadData('force_async')} catch (error) {posthog.captureException(error as Error, { scope: 'accountsLogic.updateAccountRole' })lemonToast.error(`Failed to update ${ROLE_LABELS[role]}`)diff --git a/products/customer_analytics/frontend/components/Accounts/accountsOverviewTilesLogic.ts b/products/customer_analytics/frontend/components/Accounts/accountsOverviewTilesLogic.tsindex cc98583a4c03..7af2051d5eeb 100644--- a/products/customer_analytics/frontend/components/Accounts/accountsOverviewTilesLogic.ts+++ b/products/customer_analytics/frontend/components/Accounts/accountsOverviewTilesLogic.ts@@ -7,7 +7,7 @@ import { objectsEqual } from 'lib/utils/objects'import { dataNodeLogic } from '~/queries/nodes/DataNode/dataNodeLogic'import { AccountsQueryResponse, DataNode } from '~/queries/schema/schema-general'-import { ACCOUNTS_HOGQL_DATA_NODE_KEY } from '../../constants'+import { ACCOUNTS_METRICS_DATA_NODE_KEY } from '../../constants'import { AccountColumnGroup, AccountColumnOption, accountsColumnConfigLogic } from './accountsColumnConfigLogic'import type { accountsOverviewTilesLogicType } from './accountsOverviewTilesLogicType'import {@@ -182,7 +182,7 @@ export const accountsOverviewTilesLogic = kea<accountsOverviewTilesLogicType>([values: [accountsColumnConfigLogic,['accountsColumnGroups'],- dataNodeLogic({ key: ACCOUNTS_HOGQL_DATA_NODE_KEY, query: {} as DataNode }),+ dataNodeLogic({ key: ACCOUNTS_METRICS_DATA_NODE_KEY, query: {} as DataNode }),['response as accountsResponse', 'responseLoading as accountsResponseLoading'],],})),diff --git a/products/customer_analytics/frontend/constants.ts b/products/customer_analytics/frontend/constants.tsindex 191004e3d417..c43034889524 100644--- a/products/customer_analytics/frontend/constants.ts+++ b/products/customer_analytics/frontend/constants.ts@@ -4,6 +4,10 @@ export const CUSTOMER_ANALYTICS_DATA_COLLECTION_NODE_ID = 'customer-analytics'export const ACCOUNTS_HOGQL_DATA_NODE_KEY = 'customer-analytics-accounts-hogql'+// Overview-tile metrics load through their own data node so their (slower)+// aggregations never block the list rows from rendering.+export const ACCOUNTS_METRICS_DATA_NODE_KEY = 'customer-analytics-accounts-metrics'+export const CUSTOMER_ANALYTICS_DEFAULT_QUERY_TAGS: QueryLogTags = {productKey: ProductKey.CUSTOMER_ANALYTICS,}