: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
feat(customer-analytics): show custom property columns in accounts list (#66448)
Arthur Moreira de Deusc9075c613ff9
diff --git a/posthog/hogql/database/schema/account_aggregates.py b/posthog/hogql/database/schema/account_aggregates.pyindex 42653feff1e7..d9ae88799a06 100644--- a/posthog/hogql/database/schema/account_aggregates.py+++ b/posthog/hogql/database/schema/account_aggregates.py@@ -80,6 +80,15 @@ _account_custom_property_values: _AccountScopedPostgresTable = _AccountScopedPosname="_account_custom_property_values",postgres_table_name="customer_analytics_custompropertyvalue",description="Internal federated table (PostgreSQL `customer_analytics_custompropertyvalue`) of custom property values per account; not for direct querying — use `system.accounts.custom_properties`.",+ # Scope through team-filtered accounts (as the other junction tables do) AND prune+ # soft-deleted rows, so superseded `value_*` data can't be read via direct selection+ # of this hidden backing table — matching the `NOT cpv.is_deleted` filter in the lazy join.+ predicates=[+ parse_expr("account_id IN (SELECT id FROM system.accounts)"),+ # `NOT is_deleted` (not `is_deleted != true`): the predicate is pushed into the federated+ # PostgreSQL query, where comparing a boolean column to an integer literal is a type error.+ parse_expr("NOT is_deleted"),+ ],fields={"id": UUIDDatabaseField(name="id", description="Primary key of the custom property value row."),"definition_id": UUIDDatabaseField(diff --git a/products/customer_analytics/frontend/components/Accounts/AGENTS.md b/products/customer_analytics/frontend/components/Accounts/AGENTS.mdindex e2c4c6e2adbc..a40b747724f4 100644--- a/products/customer_analytics/frontend/components/Accounts/AGENTS.md+++ b/products/customer_analytics/frontend/components/Accounts/AGENTS.md@@ -54,7 +54,9 @@ AccountsTabContent ── binds dataNodeLogic(ACCOUNTS_HOGQL_DATA_NODE_KEY, acc- **`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.-Default columns (`ACCOUNTS_HOGQL_DEFAULT_SELECT`): `name`, `tag_names`, `notebook_count`, `csm`, `account_executive`, `account_owner`. The name column is force-kept (`ensureNameColumn`) — removing it breaks identity, scroll, and role edits. Extra columns come from account properties, lazy/virtual-table joins under `system.accounts`, data-warehouse joins, or freeform SQL — all assembled by `buildAccountColumnGroups`.+Default columns (`ACCOUNTS_HOGQL_DEFAULT_SELECT`): `name`, `tag_names`, `notebook_count`, `csm`, `account_executive`, `account_owner`. The name column is force-kept (`ensureNameColumn`) — removing it breaks identity, scroll, and role edits. Extra columns come from account properties, lazy/virtual-table joins under `system.accounts`, data-warehouse joins, freeform SQL, or **custom properties** — all assembled by `buildAccountColumnGroups`.++**Custom property columns** surface the team's `CustomPropertyDefinition`s (loaded in `accountsColumnConfigLogic` via the generated `customPropertyDefinitionsList`) as a "Custom properties" picker group. Each is selected as `accounts.custom_properties.values.\`<definition-id>\` AS cp*<id>`— a JSON dot-access through the`custom_properties`lazy join on`system.accounts`(backed by the`customer_analytics_custompropertyvalue`EAV table; one JOIN regardless of column count). Because the alias is an opaque`cp*<id>`, every label-bearing surface must resolve it back via the`aliasToDefinition`selector: the table header (`useContextColumns`in`AccountsHogQLTable`) and the configurator's "Visible columns" list (`SelectedAccountColumn`). Cells render by display type (`CustomPropertyCell`: date→`TZLabel`, boolean→icon, numeric→`formatCustomPropertyValue`). v1 is display-only with lexical sort (the JSON value is a string). Numeric custom properties (display type`number`/`currency`/`percent`) are also selectable in the **overview tiles** sum/avg/threshold pickers —`numericColumnOptions`recognizes the display type and wraps the (string) value in`toFloatOrNull(...)` so aggregation is numeric.Sort safety: removing the sorted column drops the sort (`clearSortIfColumnRemoved`), else the backend gets an `orderBy` referencing a missing alias.diff --git a/products/customer_analytics/frontend/components/Accounts/AccountsColumnConfigurator.tsx b/products/customer_analytics/frontend/components/Accounts/AccountsColumnConfigurator.tsxindex 139285111668..640ff4092ad0 100644--- a/products/customer_analytics/frontend/components/Accounts/AccountsColumnConfigurator.tsx+++ b/products/customer_analytics/frontend/components/Accounts/AccountsColumnConfigurator.tsx@@ -127,8 +127,11 @@ function SelectedAccountColumn({onEdit: (column: string, index: number) => voidonRemove: (column: string) => void}): JSX.Element {+ const { aliasToDefinition } = useValues(accountsColumnConfigLogic)const { setNodeRef, attributes, transform, transition, listeners } = useSortable({ id: column })- const label = extractDisplayLabel(column)+ const alias = extractDisplayLabel(column)+ // Custom-property columns are aliased to an opaque `cp_<id>`; show the definition name instead.+ const label = aliasToDefinition[alias]?.name ?? alias// `name` carries the row identity (account id) and external_id for the// Account cell — removing it would break row expansion and role updates.const isMandatory = column === ACCOUNTS_NAME_COLUMNdiff --git a/products/customer_analytics/frontend/components/Accounts/AccountsHogQLTable.tsx b/products/customer_analytics/frontend/components/Accounts/AccountsHogQLTable.tsxindex 80586e1f1804..e261bfd4d475 100644--- a/products/customer_analytics/frontend/components/Accounts/AccountsHogQLTable.tsx+++ b/products/customer_analytics/frontend/components/Accounts/AccountsHogQLTable.tsx@@ -1,11 +1,13 @@import { useActions, useValues } from 'kea'import { useMemo } from 'react'+import { IconCheck, IconX } from '@posthog/icons'import { LemonButton, LemonSkeleton, LemonTable, ProfilePicture } from '@posthog/lemon-ui'import { CopyToClipboardInline } from 'lib/components/CopyToClipboard'import { MemberSelect } from 'lib/components/MemberSelect'import { ObjectTags } from 'lib/components/ObjectTags/ObjectTags'+import { TZLabel } from 'lib/components/TZLabel'import { LemonTableColumns } from 'lib/lemon-ui/LemonTable'import { SortingIndicator } from 'lib/lemon-ui/LemonTable/sorting'@@ -14,7 +16,10 @@ import { DataTable } from '~/queries/nodes/DataTable/DataTable'import { DataTableNode } from '~/queries/schema/schema-general'import { QueryContext, QueryContextColumn, QueryContextColumnComponent } from '~/queries/types'+import type { CustomPropertyDefinitionApi } from 'products/customer_analytics/frontend/generated/api.schemas'+import { ACCOUNTS_HOGQL_DATA_NODE_KEY } from '../../constants'+import { formatCustomPropertyValue } from '../../scenes/CustomerAnalyticsConfigurationScene/account/customPropertyTypes'import { AccountNotebooksExpansion } from './AccountNotebooksExpansion'import { ACCOUNTS_NAME_COLUMN, accountsColumnConfigLogic } from './accountsColumnConfigLogic'import { accountsExpansionLogic } from './accountsExpansionLogic'@@ -156,6 +161,31 @@ function RoleAssignmentCell({ record, role }: { record: unknown; role: AccountRo)}+function CustomPropertyCell({+ record,+ column,+ definition,+}: {+ record: unknown+ column: string+ definition: CustomPropertyDefinitionApi+}): JSX.Element {+ const getCell = useGetCell()+ const raw = getCell(record, column)+ const value = raw === null || raw === undefined ? '' : String(raw)++ if (!value) {+ return <span className="text-muted">—</span>+ }+ if (definition.display_type === 'date' || definition.display_type === 'datetime') {+ return <TZLabel time={value} showSeconds={definition.display_type === 'datetime'} />+ }+ if (definition.display_type === 'boolean') {+ return value === 'true' || value === '1' ? <IconCheck /> : <IconX className="text-muted" />+ }+ return <span>{formatCustomPropertyValue(value, definition)}</span>+}+function SortableColumnHeader({ column, label }: { column: string; label: string }): JSX.Element {const { sortOrder } = useValues(accountsLogic)const { toggleSort } = useActions(accountsLogic)@@ -225,10 +255,18 @@ const KNOWN_COLUMN_TEMPLATES: Record<string, KnownColumnTemplate> = {}function useContextColumns(): Record<string, QueryContextColumn> {- const { visibleColumnNames } = useValues(accountsColumnConfigLogic)+ const { visibleColumnNames, aliasToDefinition } = useValues(accountsColumnConfigLogic)return useMemo(() => {const columns: Record<string, QueryContextColumn> = {}for (const key of visibleColumnNames) {+ const definition = aliasToDefinition[key]+ if (definition) {+ columns[key] = {+ renderTitle: () => <SortableColumnHeader column={key} label={definition.name} />,+ render: ({ record }) => <CustomPropertyCell record={record} column={key} definition={definition} />,+ }+ continue+ }const template = KNOWN_COLUMN_TEMPLATES[key]const label = template?.label ?? keycolumns[key] = {@@ -238,7 +276,7 @@ function useContextColumns(): Record<string, QueryContextColumn> {}}return columns- }, [visibleColumnNames])+ }, [visibleColumnNames, aliasToDefinition])}function useExpandable(): QueryContext<DataTableNode>['expandable'] {diff --git a/products/customer_analytics/frontend/components/Accounts/accountsColumnConfigLogic.test.ts b/products/customer_analytics/frontend/components/Accounts/accountsColumnConfigLogic.test.tsnew file mode 100644index 000000000000..1358171e024f--- /dev/null+++ b/products/customer_analytics/frontend/components/Accounts/accountsColumnConfigLogic.test.ts@@ -0,0 +1,69 @@+import { extractDisplayLabel } from '~/queries/nodes/DataTable/utils'++import type { CustomPropertyDefinitionApi } from 'products/customer_analytics/frontend/generated/api.schemas'++import { buildAccountColumnGroups, customPropertyAlias } from './accountsColumnConfigLogic'++function definition(+ id: string,+ name: string,+ overrides: Partial<CustomPropertyDefinitionApi> = {}+): CustomPropertyDefinitionApi {+ return {+ id,+ name,+ display_type: 'text',+ is_big_number: false,+ description: null,+ created_at: '2024-01-01T00:00:00Z',+ created_by: null,+ updated_at: null,+ ...overrides,+ }+}++describe('buildAccountColumnGroups custom properties', () => {+ it('emits a custom_properties group with one option per definition, right after account_properties', () => {+ const defs = [+ definition('11111111-2222-3333-4444-555555555555', 'Plan', { display_type: 'currency' }),+ definition('66666666-7777-8888-9999-000000000000', 'Renewal', { display_type: 'date' }),+ ]+ const groups = buildAccountColumnGroups({}, [], defs)++ const keys = groups.map((group) => group.key)+ expect(keys[0]).toBe('account_properties')+ expect(keys[1]).toBe('custom_properties')++ const group = groups.find((g) => g.key === 'custom_properties')!+ expect(group.label).toBe('Custom properties')+ expect(group.options).toEqual([+ {+ name: 'Plan',+ type: 'currency',+ expression: `accounts.custom_properties.values.\`11111111-2222-3333-4444-555555555555\` AS ${customPropertyAlias(+ '11111111-2222-3333-4444-555555555555'+ )}`,+ },+ {+ name: 'Renewal',+ type: 'date',+ expression: `accounts.custom_properties.values.\`66666666-7777-8888-9999-000000000000\` AS ${customPropertyAlias(+ '66666666-7777-8888-9999-000000000000'+ )}`,+ },+ ])+ })++ it('omits the group entirely when the team has no definitions', () => {+ const groups = buildAccountColumnGroups({}, [], [])+ expect(groups.map((group) => group.key)).not.toContain('custom_properties')+ })++ it('round-trips the alias: extractDisplayLabel of the expression yields the column alias', () => {+ const id = 'abcdabcd-1234-5678-9abc-def012345678'+ const group = buildAccountColumnGroups({}, [], [definition(id, 'Plan')]).find(+ (g) => g.key === 'custom_properties'+ )!+ expect(extractDisplayLabel(group.options[0].expression)).toBe(customPropertyAlias(id))+ })+})diff --git a/products/customer_analytics/frontend/components/Accounts/accountsColumnConfigLogic.ts b/products/customer_analytics/frontend/components/Accounts/accountsColumnConfigLogic.tsindex 929acbd1cb38..1c6411f04c95 100644--- a/products/customer_analytics/frontend/components/Accounts/accountsColumnConfigLogic.ts+++ b/products/customer_analytics/frontend/components/Accounts/accountsColumnConfigLogic.ts@@ -1,13 +1,17 @@import { actions, afterMount, connect, kea, path, reducers, selectors } from 'kea'+import { loaders } from 'kea-loaders'import { objectsEqual } from 'lib/utils/objects'import { databaseTableListLogic } from 'scenes/data-management/database/databaseTableListLogic'+import { projectLogic } from 'scenes/projectLogic'import { teamLogic } from 'scenes/teamLogic'import { extractDisplayLabel } from '~/queries/nodes/DataTable/utils'import { DatabaseSchemaField, DatabaseSchemaTable } from '~/queries/schema/schema-general'import type { DataWarehouseViewLink } from '~/types'+import { customPropertyDefinitionsList } from 'products/customer_analytics/frontend/generated/api'+import type { CustomPropertyDefinitionApi } from 'products/customer_analytics/frontend/generated/api.schemas'import { joinsLogic } from 'products/data_warehouse/frontend/shared/logics/joinsLogic'import type { accountsColumnConfigLogicType } from './accountsColumnConfigLogicType'@@ -56,7 +60,14 @@ export const ACCOUNTS_ACCOUNTS_TABLE_NAME = 'system.accounts'// of which name the backend hands us.const ACCOUNTS_JOIN_SOURCE_TABLE_NAMES = new Set(['accounts', ACCOUNTS_ACCOUNTS_TABLE_NAME])-export type AccountColumnGroupKey = 'account_properties' | 'sql_expression' | `accounts.${string}`+export type AccountColumnGroupKey = 'account_properties' | 'custom_properties' | 'sql_expression' | `accounts.${string}`++// Custom property definition ids are UUIDs, which aren't valid HogQL identifiers (hyphens).+// Strip them so the column alias is a clean identifier, and so the renderer can map a visible+// column name back to its definition.+export function customPropertyAlias(id: string): string {+ return `cp_${id.replace(/-/g, '')}`+}export type AccountColumnOption = {name: string@@ -110,9 +121,20 @@ function joinOptionsFromSchema(return buildJoinOptions(field.name, names, joinedTable)}+function customPropertyOptions(definitions: CustomPropertyDefinitionApi[]): AccountColumnOption[] {+ return definitions.map((definition) => ({+ name: definition.name,+ type: definition.display_type,+ // JSON dot-access through the lazy join (`events.person.properties.foo` analog), aliased to a+ // clean identifier so the alias round-trips through `visibleColumnNames` / `aliasToDefinition`.+ expression: `accounts.custom_properties.values.\`${definition.id}\` AS ${customPropertyAlias(definition.id)}`,+ }))+}+export function buildAccountColumnGroups(allTablesMap: Record<string, DatabaseSchemaTable> | null | undefined,- warehouseJoins: DataWarehouseViewLink[]+ warehouseJoins: DataWarehouseViewLink[],+ customPropertyDefinitions: CustomPropertyDefinitionApi[] = []): AccountColumnGroup[] {const accountsTable = allTablesMap?.[ACCOUNTS_ACCOUNTS_TABLE_NAME]const directOptions: AccountColumnOption[] = []@@ -169,8 +191,22 @@ export function buildAccountColumnGroups(addJoinGroup(join.field_name, buildJoinOptions(join.field_name, columnNames, joinedTable))}+ // Omit the group entirely when the team has no definitions, so the category dropdown+ // doesn't show an empty "Custom properties" entry.+ const customPropertyGroups: AccountColumnGroup[] =+ customPropertyDefinitions.length > 0+ ? [+ {+ key: 'custom_properties',+ label: 'Custom properties',+ options: customPropertyOptions(customPropertyDefinitions),+ },+ ]+ : []+return [{ key: 'account_properties', label: 'Account properties', options: directOptions },+ ...customPropertyGroups,...joinGroups,{ key: 'sql_expression', label: 'SQL expression', options: [], isFreeform: true },]@@ -182,6 +218,8 @@ export const accountsColumnConfigLogic = kea<accountsColumnConfigLogicType>([values: [teamLogic,['currentTeamId'],+ projectLogic,+ ['currentProjectId'],databaseTableListLogic,['allTablesMap', 'databaseLoading'],joinsLogic,@@ -226,17 +264,37 @@ export const accountsColumnConfigLogic = kea<accountsColumnConfigLogicType>([},],}),+ loaders(({ values }) => ({+ customPropertyDefinitions: [+ [] as CustomPropertyDefinitionApi[],+ {+ loadCustomPropertyDefinitions: async (): Promise<CustomPropertyDefinitionApi[]> => {+ const response = await customPropertyDefinitionsList(String(values.currentProjectId))+ return response.results+ },+ },+ ],+ })),selectors({visibleColumnNames: [(s) => [s.selectColumns],(selectColumns: string[]): string[] => selectColumns.map((c) => extractDisplayLabel(c)),],accountsColumnGroups: [- (s) => [s.allTablesMap, s.warehouseJoins],+ (s) => [s.allTablesMap, s.warehouseJoins, s.customPropertyDefinitions],(allTablesMap: Record<string, DatabaseSchemaTable>,- warehouseJoins: DataWarehouseViewLink[]- ): AccountColumnGroup[] => buildAccountColumnGroups(allTablesMap, warehouseJoins),+ warehouseJoins: DataWarehouseViewLink[],+ customPropertyDefinitions: CustomPropertyDefinitionApi[]+ ): AccountColumnGroup[] =>+ buildAccountColumnGroups(allTablesMap, warehouseJoins, customPropertyDefinitions),+ ],+ aliasToDefinition: [+ (s) => [s.customPropertyDefinitions],+ (customPropertyDefinitions: CustomPropertyDefinitionApi[]): Record<string, CustomPropertyDefinitionApi> =>+ Object.fromEntries(+ customPropertyDefinitions.map((definition) => [customPropertyAlias(definition.id), definition])+ ),],}),afterMount(({ actions, values }) => {@@ -245,5 +303,6 @@ export const accountsColumnConfigLogic = kea<accountsColumnConfigLogicType>([if (!values.allTablesMap || Object.keys(values.allTablesMap).length === 0) {actions.loadDatabase()}+ actions.loadCustomPropertyDefinitions()}),])diff --git a/products/customer_analytics/frontend/components/Accounts/accountsOverviewTilesLogic.test.ts b/products/customer_analytics/frontend/components/Accounts/accountsOverviewTilesLogic.test.tsindex 2b71485b2643..77718df90fec 100644--- a/products/customer_analytics/frontend/components/Accounts/accountsOverviewTilesLogic.test.ts+++ b/products/customer_analytics/frontend/components/Accounts/accountsOverviewTilesLogic.test.ts@@ -46,9 +46,17 @@ describe('isNumericColumnType', () => {expect(isNumericColumnType('decimal')).toBe(true)})+ it('accepts numeric custom-property display types', () => {+ expect(isNumericColumnType('number')).toBe(true)+ expect(isNumericColumnType('currency')).toBe(true)+ expect(isNumericColumnType('percent')).toBe(true)+ })+it('rejects non-numeric types', () => {expect(isNumericColumnType('string')).toBe(false)expect(isNumericColumnType('boolean')).toBe(false)+ expect(isNumericColumnType('text')).toBe(false)+ expect(isNumericColumnType('date')).toBe(false)expect(isNumericColumnType(undefined)).toBe(false)})})@@ -76,6 +84,26 @@ describe('numericColumnOptions', () => {{ name: 'score', expression: 'accounts.health.score', type: 'float' },])})++ it('includes numeric custom properties and casts their string value for aggregation', () => {+ const options = numericColumnOptions([+ {+ key: 'custom_properties',+ label: 'Custom properties',+ options: [+ { name: 'Seats', expression: 'accounts.custom_properties.values.`abc` AS cp_abc', type: 'number' },+ { name: 'Plan', expression: 'accounts.custom_properties.values.`def` AS cp_def', type: 'text' },+ ],+ },+ ])+ expect(options).toEqual([+ {+ name: 'Seats',+ type: 'number',+ expression: 'toFloatOrNull(accounts.custom_properties.values.`abc`)',+ },+ ])+ })})describe('tileMetricExpression', () => {diff --git a/products/customer_analytics/frontend/components/Accounts/accountsOverviewTilesLogic.ts b/products/customer_analytics/frontend/components/Accounts/accountsOverviewTilesLogic.tsindex 7af2051d5eeb..d68a8e073367 100644--- a/products/customer_analytics/frontend/components/Accounts/accountsOverviewTilesLogic.ts+++ b/products/customer_analytics/frontend/components/Accounts/accountsOverviewTilesLogic.ts@@ -7,7 +7,10 @@ import { objectsEqual } from 'lib/utils/objects'import { dataNodeLogic } from '~/queries/nodes/DataNode/dataNodeLogic'import { AccountsQueryResponse, DataNode } from '~/queries/schema/schema-general'+import type { CustomPropertyDisplayTypeEnumApi } from 'products/customer_analytics/frontend/generated/api.schemas'+import { ACCOUNTS_METRICS_DATA_NODE_KEY } from '../../constants'+import { isNumericDisplayType } from '../../scenes/CustomerAnalyticsConfigurationScene/account/customPropertyTypes'import { AccountColumnGroup, AccountColumnOption, accountsColumnConfigLogic } from './accountsColumnConfigLogic'import type { accountsOverviewTilesLogicType } from './accountsOverviewTilesLogicType'import {@@ -53,7 +56,11 @@ export function stripHogqlAlias(expression: string): string {}export function isNumericColumnType(type: string | undefined): boolean {- return !!type && NUMERIC_FIELD_TYPES.has(type)+ if (!type) {+ return false+ }+ // Regular columns carry a HogQL field type; custom-property columns carry a display type.+ return NUMERIC_FIELD_TYPES.has(type) || isNumericDisplayType(type as CustomPropertyDisplayTypeEnumApi)}export function numericColumnOptions(groups: AccountColumnGroup[]): AccountColumnOption[] {@@ -62,10 +69,14 @@ export function numericColumnOptions(groups: AccountColumnGroup[]): AccountColum.flatMap((group) =>group.options.filter((option) => isNumericColumnType(option.type))- .map((option) => ({- ...option,- expression: stripHogqlAlias(option.expression),- }))+ .map((option) => {+ const expression = stripHogqlAlias(option.expression)+ return {+ ...option,+ // Custom-property values are stored as coalesced strings; cast so sum/avg aggregate numerically.+ expression: group.key === 'custom_properties' ? `toFloatOrNull(${expression})` : expression,+ }+ }))}diff --git a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyTypes.test.ts b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyTypes.test.tsindex 5bb8a4555ff5..910f35eee185 100644--- a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyTypes.test.ts+++ b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyTypes.test.ts@@ -1,4 +1,18 @@-import { DISPLAY_TYPE_OPTIONS, isNumericDisplayType, labelForDisplayType } from './customPropertyTypes'+import type { CustomPropertyDisplayTypeEnumApi } from 'products/customer_analytics/frontend/generated/api.schemas'++import {+ DISPLAY_TYPE_OPTIONS,+ formatCustomPropertyValue,+ isNumericDisplayType,+ labelForDisplayType,+} from './customPropertyTypes'++function definition(+ display_type: CustomPropertyDisplayTypeEnumApi,+ is_big_number = false+): { display_type: CustomPropertyDisplayTypeEnumApi; is_big_number: boolean } {+ return { display_type, is_big_number }+}describe('customPropertyTypes', () => {it('labels each display type with its option label', () => {@@ -19,4 +33,28 @@ describe('customPropertyTypes', () => {expect(isNumericDisplayType('text')).toBe(false)expect(isNumericDisplayType('boolean')).toBe(false)})++ describe('formatCustomPropertyValue', () => {+ it('renders an em dash for missing values', () => {+ expect(formatCustomPropertyValue(null, definition('text'))).toBe('—')+ expect(formatCustomPropertyValue(undefined, definition('currency'))).toBe('—')+ expect(formatCustomPropertyValue('', definition('number'))).toBe('—')+ })++ it('formats currency, percent and numbers', () => {+ expect(formatCustomPropertyValue('1234.5', definition('currency'))).toBe('$1,234.50')+ expect(formatCustomPropertyValue('0.234', definition('percent'))).toBe('23.4%')+ expect(formatCustomPropertyValue('1234', definition('number'))).toBe('1,234')+ })++ it('abbreviates big numbers only when the definition opts in', () => {+ expect(formatCustomPropertyValue('12000', definition('number', true))).toBe('12K')+ expect(formatCustomPropertyValue('12000', definition('number', false))).toBe('12,000')+ })++ it('returns text and non-numeric input as-is', () => {+ expect(formatCustomPropertyValue('enterprise', definition('text'))).toBe('enterprise')+ expect(formatCustomPropertyValue('n/a', definition('number'))).toBe('n/a')+ })+ })})diff --git a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyTypes.ts b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyTypes.tsindex 00ea8c993a2e..2711a9cad217 100644--- a/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyTypes.ts+++ b/products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/account/customPropertyTypes.ts@@ -1,4 +1,9 @@-import type { CustomPropertyDisplayTypeEnumApi } from 'products/customer_analytics/frontend/generated/api.schemas'+import { humanFriendlyCurrency, humanFriendlyLargeNumber, humanFriendlyNumber, percentage } from 'lib/utils/numbers'++import type {+ CustomPropertyDefinitionApi,+ CustomPropertyDisplayTypeEnumApi,+} from 'products/customer_analytics/frontend/generated/api.schemas'// The backend stores the granular display type directly, so the form value maps 1:1 to the API.// This file holds only the UI metadata (label + whether the big-number switch applies).@@ -26,3 +31,34 @@ export function labelForDisplayType(displayType: CustomPropertyDisplayTypeEnumApexport function isNumericDisplayType(displayType: CustomPropertyDisplayTypeEnumApi): boolean {return DISPLAY_TYPE_OPTIONS.find((option) => option.value === displayType)?.isNumeric ?? false}++const EMPTY_VALUE = '—'++// Formats a custom property value (always a string off the JSON column) for display per its+// definition's display type. Date/datetime/boolean are handled by the cell (TZLabel / icon),+// so this returns the raw string for them and focuses on the numeric formats.+export function formatCustomPropertyValue(+ raw: string | null | undefined,+ definition: Pick<CustomPropertyDefinitionApi, 'display_type' | 'is_big_number'>+): string {+ if (raw === null || raw === undefined || raw === '') {+ return EMPTY_VALUE+ }+ const numeric = Number(raw)+ const isNumber = Number.isFinite(numeric)+ switch (definition.display_type) {+ case 'currency':+ return isNumber ? humanFriendlyCurrency(numeric) : raw+ // Percent values are stored as fractions (0.5 → 50%), matching how the backend coerces them+ // (see test_custom_property_values.py: a `percent` definition stores 0.5). percentage() multiplies by 100.+ case 'percent':+ return isNumber ? percentage(numeric) : raw+ case 'number':+ if (!isNumber) {+ return raw+ }+ return definition.is_big_number ? humanFriendlyLargeNumber(numeric) : humanFriendlyNumber(numeric)+ default:+ return raw+ }+}