: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(billing): separate usage and spend type pickers (#78845)
Adam Bowker5116b7e1734b
diff --git a/ee/hogai/tools/read_billing_tool/tool.py b/ee/hogai/tools/read_billing_tool/tool.pyindex cff14570e33e..645bec7ac6c2 100644--- a/ee/hogai/tools/read_billing_tool/tool.py+++ b/ee/hogai/tools/read_billing_tool/tool.py@@ -36,6 +36,16 @@ USAGE_TYPES = [{"label": "PostHog AI", "value": "ai_credits_used_in_period"},{"label": "Inbox credits", "value": "signals_credits_used_in_period"},{"label": "PostHog Desktop credits", "value": "posthog_code_credits_used_in_period"},+ {"label": "PostHog Desktop token credits", "value": "posthog_code_token_credits_used_in_period"},+ {"label": "Sandbox compute credits", "value": "sandbox_compute_credits_used_in_period"},+ {+ "label": "Sandbox compute CPU millicore-seconds",+ "value": "sandbox_compute_cpu_millicore_seconds_in_period",+ },+ {+ "label": "Sandbox compute memory MiB-seconds",+ "value": "sandbox_compute_memory_mib_seconds_in_period",+ },{"label": "Replay vision credits", "value": "replay_vision_credits_used_in_period"},{"label": "Workflow emails", "value": "workflow_emails_sent_in_period"},{"label": "Workflow push notifications", "value": "workflow_push_sent_in_period"},diff --git a/frontend/src/scenes/billing/BillingSpendView.tsx b/frontend/src/scenes/billing/BillingSpendView.tsxindex e0e6fe741928..66775be90f5d 100644--- a/frontend/src/scenes/billing/BillingSpendView.tsx+++ b/frontend/src/scenes/billing/BillingSpendView.tsx@@ -17,7 +17,7 @@ import { getAccessControlDisabledReason } from 'lib/utils/accessControlUtils'import { AccessControlLevel, AccessControlResourceType, ExporterFormat } from '~/types'-import { buildBillingCsv, currencyFormatter, getUsageTypeOptions } from './billing-utils'+import { buildBillingCsv, currencyFormatter, getSpendTypeOptions } from './billing-utils'import { BillingDataTable } from './BillingDataTable'import { BillingEarlyAccessBanner } from './BillingEarlyAccessBanner'import { BillingEmptyState } from './BillingEmptyState'@@ -105,7 +105,7 @@ export function BillingSpendView(): JSX.Element {value={filters.usage_types || []}onChange={(value: string[]) => setFilters({ usage_types: value })}placeholder="All products"- options={getUsageTypeOptions(featureFlags)}+ options={getSpendTypeOptions(featureFlags)}allowCustomValues={false}/></div>diff --git a/frontend/src/scenes/billing/billing-utils.test.ts b/frontend/src/scenes/billing/billing-utils.test.tsindex ab7d8b5c8f9d..54a4ef15e820 100644--- a/frontend/src/scenes/billing/billing-utils.test.ts+++ b/frontend/src/scenes/billing/billing-utils.test.ts@@ -1,7 +1,12 @@import { FEATURE_FLAGS } from 'lib/constants'import type { FeatureFlagsSet } from 'lib/logic/featureFlagLogic'-import { getUsageTypeOptions } from './billing-utils'+import {+ buildSpendTrackingProperties,+ filterSpendUsageTypes,+ getSpendTypeOptions,+ getUsageTypeOptions,+} from './billing-utils'describe('getUsageTypeOptions', () => {it.each<[string, FeatureFlagsSet, boolean]>([@@ -17,4 +22,53 @@ describe('getUsageTypeOptions', () => {expect(options.some((opt) => opt.key === 'event_count_in_period')).toBe(true)})++ it('includes informational Desktop component metrics in Usage but not Spend', () => {+ const usageOptions = getUsageTypeOptions({})+ const spendOptions = getSpendTypeOptions({})+ const componentTypes = [+ 'posthog_code_token_credits_used_in_period',+ 'sandbox_compute_credits_used_in_period',+ 'sandbox_compute_cpu_millicore_seconds_in_period',+ 'sandbox_compute_memory_mib_seconds_in_period',+ ]++ for (const usageType of componentTypes) {+ expect(usageOptions.some((option) => option.key === usageType)).toBe(true)+ expect(spendOptions.some((option) => option.key === usageType)).toBe(false)+ }+ })++ it.each<[string, FeatureFlagsSet]>([+ ['on', { [FEATURE_FLAGS.REPLAY_VISION]: true }],+ ['off', { [FEATURE_FLAGS.REPLAY_VISION]: false }],+ ])(+ 'reports only selectable Spend types in interaction analytics when Replay Vision is %s',+ (_name, featureFlags) => {+ const properties = buildSpendTrackingProperties(+ 'filters_changed',+ {+ filters: {},+ dateFrom: '2026-08-01',+ dateTo: '2026-08-06',+ excludeEmptySeries: false,+ teamOptions: [],+ },+ featureFlags+ )++ expect(properties.usage_types_total).toBe(getSpendTypeOptions(featureFlags).length)+ }+ )++ it('removes Usage-only types when switching to Spend', () => {+ expect(+ filterSpendUsageTypes([+ 'posthog_code_token_credits_used_in_period',+ 'sandbox_compute_credits_used_in_period',+ 'event_count_in_period',+ ])+ ).toEqual(['event_count_in_period'])+ expect(filterSpendUsageTypes(['sandbox_compute_cpu_millicore_seconds_in_period'])).toEqual([])+ })})diff --git a/frontend/src/scenes/billing/billing-utils.ts b/frontend/src/scenes/billing/billing-utils.tsindex 49c2c2d5a5b5..ea450347443e 100644--- a/frontend/src/scenes/billing/billing-utils.ts+++ b/frontend/src/scenes/billing/billing-utils.ts@@ -14,7 +14,7 @@ import { Params } from 'scenes/sceneTypes'import { BillingPeriod, BillingProductV2AddonType, BillingProductV2Type, BillingTierType, BillingType } from '~/types'-import { USAGE_TYPES } from './constants'+import { SPEND_TYPES, USAGE_TYPES } from './constants'import type { BillingFilters, BillingSeriesForCsv, BillingUsageInteractionProps, BuildBillingCsvOptions } from './types'import { BillingGaugeItemKind, BillingGaugeItemType } from './types'@@ -489,7 +489,8 @@ export function buildTrackingProperties(dateTo: stringexcludeEmptySeries: booleanteamOptions: { key: string; label: string }[]- }+ },+ usageTypesTotal: number = USAGE_TYPES.length): BillingUsageInteractionProps {return {action,@@ -498,7 +499,7 @@ export function buildTrackingProperties(date_to: values.dateTo,exclude_empty: values.excludeEmptySeries,usage_types_count: values.filters.usage_types?.length || 0,- usage_types_total: USAGE_TYPES.length,+ usage_types_total: usageTypesTotal,teams_count: values.filters.team_ids?.length || 0,teams_total: values.teamOptions.length,has_team_breakdown: (values.filters.breakdowns || []).includes('team'),@@ -506,12 +507,28 @@ export function buildTrackingProperties(}}+export const buildSpendTrackingProperties = (+ action: BillingUsageInteractionProps['action'],+ values: Parameters<typeof buildTrackingProperties>[1],+ featureFlags: FeatureFlagsSet+): BillingUsageInteractionProps => buildTrackingProperties(action, values, getSpendTypeOptions(featureFlags).length)+// The Replay vision entry stays hidden until the replay-vision flag rolls out with the pricing launchexport const getUsageTypeOptions = (featureFlags: FeatureFlagsSet): { key: string; label: string }[] =>USAGE_TYPES.filter((opt) => opt.value !== 'replay_vision_credits_used_in_period' || featureFlags[FEATURE_FLAGS.REPLAY_VISION]).map((opt) => ({ key: opt.value, label: opt.label }))+export const getSpendTypeOptions = (featureFlags: FeatureFlagsSet): { key: string; label: string }[] =>+ SPEND_TYPES.filter(+ (opt) => opt.value !== 'replay_vision_credits_used_in_period' || featureFlags[FEATURE_FLAGS.REPLAY_VISION]+ ).map((opt) => ({ key: opt.value, label: opt.label }))++const SPEND_TYPE_VALUES = new Set<string>(SPEND_TYPES.map((option) => option.value))++export const filterSpendUsageTypes = (usageTypes: string[] | undefined): string[] =>+ usageTypes?.filter((usageType) => SPEND_TYPE_VALUES.has(usageType)) ?? []+export const isAddonVisible = (product: BillingProductV2Type,addon: BillingProductV2AddonType,diff --git a/frontend/src/scenes/billing/billingSpendLogic.ts b/frontend/src/scenes/billing/billingSpendLogic.tsindex b323d0f42a8d..86e4eb7c3720 100644--- a/frontend/src/scenes/billing/billingSpendLogic.ts+++ b/frontend/src/scenes/billing/billingSpendLogic.ts@@ -9,6 +9,7 @@ import { lemonToast } from '@posthog/lemon-ui'import api from 'lib/api'import { dayjs } from 'lib/dayjs'+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { dateMapping } from 'lib/utils/dateFilters'import { eventUsageLogic } from 'lib/utils/eventUsageLogic'import { toParams } from 'lib/utils/url'@@ -19,8 +20,9 @@ import { DateMappingOption, OrganizationType } from '~/types'import type { BillingPeriod, BillingType } from '../../types'import {- buildTrackingProperties,+ buildSpendTrackingProperties,calculateBillingPeriodMarkers,+ filterSpendUsageTypes,syncBillingSearchParams,updateBillingSearchParams,} from './billing-utils'@@ -542,8 +544,11 @@ export const billingSpendLogic = kea<billingSpendLogicType>([const filtersFromUrl: Partial<BillingFilters> = {}- if (params.usage_types && !equal(params.usage_types, values.filters.usage_types)) {- filtersFromUrl.usage_types = params.usage_types+ if (params.usage_types) {+ const usageTypes = filterSpendUsageTypes(params.usage_types)+ if (!equal(params.usage_types, usageTypes) || !equal(usageTypes, values.filters.usage_types)) {+ filtersFromUrl.usage_types = usageTypes+ }}if (params.team_ids && !equal(params.team_ids, values.filters.team_ids)) {filtersFromUrl.team_ids = params.team_ids@@ -580,19 +585,25 @@ export const billingSpendLogic = kea<billingSpendLogicType>([setFilters: async ({ shouldDebounce }, breakpoint) => {if (shouldDebounce) {await breakpoint(200)- actions.reportBillingSpendInteraction(buildTrackingProperties('filters_changed', values))+ actions.reportBillingSpendInteraction(+ buildSpendTrackingProperties('filters_changed', values, featureFlagLogic.values.featureFlags)+ )}actions.loadBillingSpend()},setDateRange: async ({ shouldDebounce }, breakpoint) => {if (shouldDebounce) {await breakpoint(200)- actions.reportBillingSpendInteraction(buildTrackingProperties('date_changed', values))+ actions.reportBillingSpendInteraction(+ buildSpendTrackingProperties('date_changed', values, featureFlagLogic.values.featureFlags)+ )}actions.loadBillingSpend()},resetFilters: async () => {- actions.reportBillingSpendInteraction(buildTrackingProperties('filters_cleared', values))+ actions.reportBillingSpendInteraction(+ buildSpendTrackingProperties('filters_cleared', values, featureFlagLogic.values.featureFlags)+ )actions.loadBillingSpend()},toggleAllSeries: () => {@@ -602,7 +613,9 @@ export const billingSpendLogic = kea<billingSpendLogicType>([: seriesconst ids = potentiallyVisible.map((s) => s.id)const isAllVisible = ids.length > 0 && ids.every((id) => !userHiddenSeries.includes(id))- actions.reportBillingSpendInteraction(buildTrackingProperties('series_toggled', values))+ actions.reportBillingSpendInteraction(+ buildSpendTrackingProperties('series_toggled', values, featureFlagLogic.values.featureFlags)+ )if (isAllVisible) {// Hide all series@@ -614,7 +627,9 @@ export const billingSpendLogic = kea<billingSpendLogicType>([},toggleBreakdown: async (_payload, breakpoint) => {await breakpoint(200)- actions.reportBillingSpendInteraction(buildTrackingProperties('breakdown_toggled', values))+ actions.reportBillingSpendInteraction(+ buildSpendTrackingProperties('breakdown_toggled', values, featureFlagLogic.values.featureFlags)+ )actions.loadBillingSpend()},})),diff --git a/frontend/src/scenes/billing/constants.ts b/frontend/src/scenes/billing/constants.tsindex e29a3d77e34a..59e568c207ae 100644--- a/frontend/src/scenes/billing/constants.ts+++ b/frontend/src/scenes/billing/constants.ts@@ -1,6 +1,6 @@// sync with ee/hogai/tools/read_billing_tool/tool.py// Values are sent to the `billing` repo as `usage_types`; keep in sync with accepted types in `billing/types/usage.py`.-export const USAGE_TYPES = [+export const SPEND_TYPES = [{ label: 'Events', value: 'event_count_in_period' },{ label: 'Identified events', value: 'enhanced_persons_event_count_in_period' },{ label: 'Group analytics', value: 'group_analytics' },@@ -26,6 +26,15 @@ export const USAGE_TYPES = [{ label: 'Logs 30-day retention (MB)', value: 'logs_retention_30d_mb_in_period' },] as const+export const USAGE_ONLY_TYPES = [+ { label: 'PostHog Desktop token credits', value: 'posthog_code_token_credits_used_in_period' },+ { label: 'Sandbox compute credits', value: 'sandbox_compute_credits_used_in_period' },+ { label: 'Sandbox compute CPU millicore-seconds', value: 'sandbox_compute_cpu_millicore_seconds_in_period' },+ { label: 'Sandbox compute memory MiB-seconds', value: 'sandbox_compute_memory_mib_seconds_in_period' },+] as const++export const USAGE_TYPES = [...SPEND_TYPES, ...USAGE_ONLY_TYPES] as const+export type UsageTypeOption = (typeof USAGE_TYPES)[number]export type UsageTypeValue = UsageTypeOption['value']