Skip to content

: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.

fix(customer-analytics): show EU org members on accounts users tab (#78931)

Arthur Moreira de Deus98b4b53fda58
diff --git a/products/customer_analytics/frontend/components/Accounts/AGENTS.md b/products/customer_analytics/frontend/components/Accounts/AGENTS.md
index 3de9f76193a9..65fd5c9efe4c 100644
--- a/products/customer_analytics/frontend/components/Accounts/AGENTS.md
+++ b/products/customer_analytics/frontend/components/Accounts/AGENTS.md
@@ -47,7 +47,7 @@ AccountsTabContent ── binds dataNodeLogic(ACCOUNTS_HOGQL_DATA_NODE_KEY, acc
| `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`). |
+| `accountRelatedUsersLogic` | Group members / related users for one account (keyed by `externalId`). US-region orgs come from the org-members endpoint; when it returns no members, the logic falls back to the `eu_org_members` data warehouse view (a materialized pre-join of the EU postgres sync, prod-only, refreshed daily), fetched once per expansion and paginated client-side. A missing view (local dev) degrades to the normal empty state. |
| `accountRelationshipsLogic` | Relationship assignments for one account (keyed by `accountId`): fetches the full timeline once (`include_history=true` on the nested relationships endpoint) — the `displayedRelationships` selector (current assignments first, newest first, optionally narrowed by `definitionFilter`) feeds the (paginated) history tab, the `activeRelationships` selector feeds the sidebar summary. Also owns the tab's mutations: `assignRelationship` (definition picker + `MemberSelect`, POSTs the assign endpoint) and `endRelationship` (per active row, POSTs the end endpoint) — both guarded by a shared `relationshipSaving` flag, reload the timeline, and force-refresh the list's data nodes so relationship columns stay in sync. |
| `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, and owns the per-view hidden-series state (`ephemeralHiddenSeriesKeysByShortId`) behind the chart chips. |
| `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. |
diff --git a/products/customer_analytics/frontend/components/Accounts/accountRelatedUsersLogic.test.ts b/products/customer_analytics/frontend/components/Accounts/accountRelatedUsersLogic.test.ts
index f16a4390c906..12387468af30 100644
--- a/products/customer_analytics/frontend/components/Accounts/accountRelatedUsersLogic.test.ts
+++ b/products/customer_analytics/frontend/components/Accounts/accountRelatedUsersLogic.test.ts
@@ -1,4 +1,5 @@
import { expectLogic } from 'kea-test-utils'
+import posthog from 'posthog-js'
import api, { CountedPaginatedResponse } from 'lib/api'
@@ -78,4 +79,64 @@ describe('accountRelatedUsersLogic', () => {
await expectLogic(logic).toFinishAllListeners()
expect(listForOrg).toHaveBeenLastCalledWith('org-uuid', { limit: PAGE_SIZE, offset: PAGE_SIZE })
})
+
+ const buildEuRow = (n: number): unknown[] => [
+ `eu-m-${n}`,
+ `First${n}`,
+ `Last${n}`,
+ `eu${n}@example.com`,
+ `did-${n}`,
+ ]
+
+ it('falls back to the EU warehouse view when the org has no local members', async () => {
+ jest.spyOn(api.organizationMembers, 'listForOrg').mockResolvedValue(buildResponse([], 0))
+ const query = jest.spyOn(api, 'query').mockResolvedValue({ results: [buildEuRow(1), buildEuRow(2)] } as any)
+
+ logic = accountRelatedUsersLogic({ externalId: 'org-uuid' })
+ logic.mount()
+
+ await expectLogic(logic).toFinishAllListeners()
+ expect(query).toHaveBeenCalledTimes(1)
+ expect(logic.values.membersResponse).toMatchObject({
+ count: 2,
+ results: [
+ { id: 'eu-m-1', user: { first_name: 'First1', email: '[email protected]', distinct_id: 'did-1' } },
+ { id: 'eu-m-2', user: { first_name: 'First2', email: '[email protected]', distinct_id: 'did-2' } },
+ ],
+ })
+ })
+
+ it('paginates cached EU members client-side without refetching', async () => {
+ const listForOrg = jest.spyOn(api.organizationMembers, 'listForOrg').mockResolvedValue(buildResponse([], 0))
+ const query = jest
+ .spyOn(api, 'query')
+ .mockResolvedValue({ results: Array.from({ length: PAGE_SIZE + 2 }, (_, i) => buildEuRow(i + 1)) } as any)
+
+ logic = accountRelatedUsersLogic({ externalId: 'org-uuid' })
+ logic.mount()
+ await expectLogic(logic).toFinishAllListeners()
+
+ logic.actions.setPage(2)
+
+ await expectLogic(logic).toFinishAllListeners()
+ expect(listForOrg).toHaveBeenCalledTimes(1)
+ expect(query).toHaveBeenCalledTimes(1)
+ expect(logic.values.membersResponse).toMatchObject({
+ count: PAGE_SIZE + 2,
+ results: [{ id: `eu-m-${PAGE_SIZE + 1}` }, { id: `eu-m-${PAGE_SIZE + 2}` }],
+ })
+ })
+
+ it('degrades to the empty response when the EU view does not exist', async () => {
+ const emptyResponse = buildResponse([], 0)
+ jest.spyOn(api.organizationMembers, 'listForOrg').mockResolvedValue(emptyResponse)
+ jest.spyOn(api, 'query').mockRejectedValue(new Error('Unknown table eu_org_members'))
+ const captureException = jest.spyOn(posthog, 'captureException').mockImplementation(() => undefined)
+
+ logic = accountRelatedUsersLogic({ externalId: 'org-uuid' })
+ logic.mount()
+
+ await expectLogic(logic).toFinishAllListeners().toMatchValues({ membersResponse: emptyResponse })
+ expect(captureException).not.toHaveBeenCalled()
+ })
})
diff --git a/products/customer_analytics/frontend/components/Accounts/accountRelatedUsersLogic.ts b/products/customer_analytics/frontend/components/Accounts/accountRelatedUsersLogic.ts
index 6bd65cf44156..cc261ff9440f 100644
--- a/products/customer_analytics/frontend/components/Accounts/accountRelatedUsersLogic.ts
+++ b/products/customer_analytics/frontend/components/Accounts/accountRelatedUsersLogic.ts
@@ -5,13 +5,71 @@ import posthog from 'posthog-js'
import api, { CountedPaginatedResponse } from 'lib/api'
import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
+import { HogQLQueryResponse, NodeKind } from '~/queries/schema/schema-general'
+import { hogql } from '~/queries/utils'
import { OrganizationMemberType } from '~/types'
+import { CUSTOMER_ANALYTICS_DEFAULT_QUERY_TAGS } from '../../constants'
+
// The account org-members endpoint returns a slim member shape — only id + user are serialized.
export type AccountOrganizationMember = Pick<OrganizationMemberType, 'id' | 'user'>
export const PAGE_SIZE = 5
+// EU-region orgs have no rows in this region's posthog_user tables; eu_org_members is a
+// materialized DWH pre-join of the EU postgres sync (prod-only, refreshed daily).
+const EU_MEMBERS_VIEW = 'eu_org_members'
+const EU_MEMBERS_LIMIT = 3000
+
+const isExpectedMissingViewError = (error: unknown): boolean => {
+ const message = error instanceof Error ? error.message : String(error ?? '')
+ return (
+ message.includes(EU_MEMBERS_VIEW) &&
+ (message.includes("don't have access to table") || message.includes('Unknown table'))
+ )
+}
+
+const paginateMembers = (
+ members: AccountOrganizationMember[],
+ page: number
+): CountedPaginatedResponse<AccountOrganizationMember> => ({
+ results: members.slice((page - 1) * PAGE_SIZE, page * PAGE_SIZE),
+ count: members.length,
+})
+
+const fetchEuMembers = async (externalId: string): Promise<AccountOrganizationMember[] | null> => {
+ try {
+ const response = (await api.query({
+ kind: NodeKind.HogQLQuery,
+ tags: CUSTOMER_ANALYTICS_DEFAULT_QUERY_TAGS,
+ query: hogql`
+ select membership_id, first_name, last_name, email, distinct_id
+ from eu_org_members
+ where organization_id = ${externalId}
+ order by joined_at desc
+ limit ${EU_MEMBERS_LIMIT}
+ `,
+ })) as HogQLQueryResponse
+ const rows = (response.results ?? []) as unknown[][]
+ return rows.map((row) => ({
+ id: String(row[0]),
+ user: {
+ first_name: (row[1] as string | null) ?? '',
+ last_name: (row[2] as string | null) ?? '',
+ email: (row[3] as string | null) ?? '',
+ distinct_id: (row[4] as string | null) ?? '',
+ } as AccountOrganizationMember['user'],
+ }))
+ } catch (error) {
+ if (!isExpectedMissingViewError(error)) {
+ posthog.captureException(error as Error, {
+ scope: 'accountRelatedUsersLogic.fetchEuMembers',
+ })
+ }
+ return null
+ }
+}
+
export interface AccountRelatedUsersLogicProps {
externalId: string
}
@@ -73,17 +131,29 @@ export const accountRelatedUsersLogic = kea<accountRelatedUsersLogicType>([
},
],
}),
- loaders(({ props, values }) => ({
+ loaders(({ cache, props, values }) => ({
membersResponse: [
null as CountedPaginatedResponse<AccountOrganizationMember> | null,
{
loadMembers: async (_ = null, breakpoint) => {
+ if (cache.euMembers) {
+ return paginateMembers(cache.euMembers, values.page)
+ }
try {
const response = await api.organizationMembers.listForOrg(props.externalId, {
limit: PAGE_SIZE,
offset: (values.page - 1) * PAGE_SIZE,
})
breakpoint()
+ if (response.count > 0) {
+ return response
+ }
+ const euMembers = await fetchEuMembers(props.externalId)
+ breakpoint()
+ if (euMembers?.length) {
+ cache.euMembers = euMembers
+ return paginateMembers(euMembers, values.page)
+ }
return response
} catch (error) {
if (!isBreakpoint(error as Error)) {