: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): surface billing activity in the activity log UI (#70652)
Yasenf5bc731c76d0
diff --git a/ee/hogai/tools/read_data/tool.py b/ee/hogai/tools/read_data/tool.pyindex 6e8bb44357e6..bb0aec49cfbe 100644--- a/ee/hogai/tools/read_data/tool.py+++ b/ee/hogai/tools/read_data/tool.py@@ -193,7 +193,7 @@ class ReadActivityLog(BaseModel):default=None,description=("Filter by resource scope. Available scopes: "- "Action, AlertConfiguration, Annotation, BatchExport, BatchImport, Cohort, Comment, "+ "Action, AlertConfiguration, Annotation, BatchExport, BatchImport, Billing, Cohort, Comment, ""Dashboard, DataManagement, EarlyAccessFeature, EventDefinition, Experiment, ""ExternalDataSchema, ExternalDataSource, FeatureFlag, HogFlow, HogFunction, ""Insight, Notebook, Organization, OrganizationDomain, OrganizationMembership, "diff --git a/frontend/src/lib/components/ActivityLog/describers.tsx b/frontend/src/lib/components/ActivityLog/describers.tsxindex bbdc6fad51b2..5699e9abdfe6 100644--- a/frontend/src/lib/components/ActivityLog/describers.tsx+++ b/frontend/src/lib/components/ActivityLog/describers.tsx@@ -6,6 +6,7 @@ import { ActivityLogItem, Describer, defaultDescriber } from 'lib/components/Actimport { actionActivityDescriber } from 'scenes/actions/actionActivityDescriber'import { annotationActivityDescriber } from 'scenes/annotations/activityDescriptions'import { userActivityDescriber } from 'scenes/authentication/shared/activityDescriptions'+import { billingActivityDescriber } from 'scenes/billing/activityDescriptions'import { cohortActivityDescriber } from 'scenes/cohorts/activityDescriptions'import { dashboardActivityDescriber } from 'scenes/dashboard/dashboardActivityDescriber'import { dataManagementActivityDescriber } from 'scenes/data-management/dataManagementDescribers'@@ -56,6 +57,8 @@ export const describerFor = (logItem?: ActivityLogItem): Describer | undefined =return batchExportActivityDescribercase ActivityScope.BATCH_IMPORT:return batchImportActivityDescriber+ case ActivityScope.BILLING:+ return billingActivityDescribercase ActivityScope.EXPORTED_ASSET:return exportedAssetActivityDescribercase ActivityScope.DASHBOARD:diff --git a/frontend/src/scenes/billing/activityDescriptions.test.tsx b/frontend/src/scenes/billing/activityDescriptions.test.tsxnew file mode 100644index 000000000000..c4c15fb48437--- /dev/null+++ b/frontend/src/scenes/billing/activityDescriptions.test.tsx@@ -0,0 +1,109 @@+import { render } from '@testing-library/react'++import { ActivityChange, ActivityLogDetail, ActivityLogItem } from 'lib/components/ActivityLog/humanizeActivity'++import { initKeaTests } from '~/test/init'+import { ActivityScope } from '~/types'++import { billingActivityDescriber } from './activityDescriptions'++function makeDetail(name: string | null, changes: ActivityChange[] = []): ActivityLogDetail {+ return { merge: null, trigger: null, name, changes }+}++function makeLogItem(overrides: Partial<ActivityLogItem> & { detail: ActivityLogItem['detail'] }): ActivityLogItem {+ return {+ user: { first_name: 'Max', last_name: 'Hog', email: '[email protected]' },+ activity: 'updated',+ created_at: '2026-03-01T00:00:00Z',+ scope: ActivityScope.BILLING,+ item_id: 'abc-123',+ ...overrides,+ }+}++function change(+ action: ActivityChange['action'],+ field: string,+ before: ActivityChange['before'] = null,+ after: ActivityChange['after'] = null+): ActivityChange {+ return { type: ActivityScope.BILLING, action, field, before, after }+}++function describeText(logItem: ActivityLogItem, asNotification?: boolean): string {+ const { description } = billingActivityDescriber(logItem, asNotification)+ if (!description) {+ return ''+ }+ const { container } = render(<>{description}</>)+ return container.textContent ?? ''+}++describe('billing activity descriptions', () => {+ beforeEach(() => {+ // The describer returns JSX containing a <Link> that relies on kea-router+ initKeaTests()+ })++ it('maps a known action name to its verb phrase', () => {+ const text = describeText(makeLogItem({ detail: makeDetail('Billing products activated') }))+ expect(text).toBe('Max Hog added products in billing')+ })++ it('renders both the American name and the British alias as "canceled a trial"', () => {+ expect(describeText(makeLogItem({ detail: makeDetail('Billing trial canceled') }))).toBe(+ 'Max Hog canceled a trial in billing'+ )+ expect(describeText(makeLogItem({ detail: makeDetail('Billing trial cancelled') }))).toBe(+ 'Max Hog canceled a trial in billing'+ )+ })++ it('falls back to a generic phrase for an unmapped action name', () => {+ const text = describeText(makeLogItem({ detail: makeDetail('Billing something new') }))+ expect(text).toBe('Max Hog updated billing in billing')+ })++ it('shows the after value for a created change', () => {+ const text = describeText(+ makeLogItem({ detail: makeDetail('Billing credits purchased', [change('created', 'credits', null, 5000)]) })+ )+ expect(text).toBe('Max Hog purchased credits in billing (credits: 5000)')+ })++ it('shows the before value for a deleted change', () => {+ const text = describeText(+ makeLogItem({+ detail: makeDetail('Billing next-period limit reset', [change('deleted', 'product_analytics', 100)]),+ })+ )+ expect(text).toBe('Max Hog reset a next-period spend limit in billing (product_analytics: 100)')+ })++ it('shows the before and after values for a changed field', () => {+ const text = describeText(+ makeLogItem({+ detail: makeDetail('Billing spend limits', [change('changed', 'product_analytics', 50, 100)]),+ })+ )+ expect(text).toBe('Max Hog updated the spend limits in billing (product_analytics from 50 to 100)')+ })++ it('lists field names when multiple fields change at once', () => {+ const text = describeText(+ makeLogItem({+ detail: makeDetail('Billing spend limits', [+ change('changed', 'product_analytics', 50, 100),+ change('changed', 'session_replay', 10, 20),+ ]),+ })+ )+ expect(text).toBe('Max Hog updated the spend limits in billing (product_analytics, session_replay)')+ })++ it('delegates non-updated activities to the default describer', () => {+ const text = describeText(makeLogItem({ activity: 'deleted', detail: makeDetail('Billing spend limits') }))+ expect(text).not.toContain('in billing')+ })+})diff --git a/frontend/src/scenes/billing/activityDescriptions.tsx b/frontend/src/scenes/billing/activityDescriptions.tsxnew file mode 100644index 000000000000..b6336d182d67--- /dev/null+++ b/frontend/src/scenes/billing/activityDescriptions.tsx@@ -0,0 +1,71 @@+import {+ ActivityChange,+ ActivityLogItem,+ defaultDescriber,+ HumanizedChange,+ userNameForLogItem,+} from 'lib/components/ActivityLog/humanizeActivity'+import { Link } from 'lib/lemon-ui/Link'+import { urls } from 'scenes/urls'++// The billing service sets detail.name; map it to a short verb phrase for the feed.+const BILLING_ACTIONS: Record<string, string> = {+ 'Billing spend limits': 'updated the spend limits',+ 'Billing next-period limit reset': 'reset a next-period spend limit',+ 'Billing products activated': 'added products',+ 'Billing products deactivated': 'removed products',+ 'Billing plan switched': 'switched plan',+ 'Billing trial activated': 'started a trial',+ 'Billing trial extended': 'extended a trial',+ 'Billing trial canceled': 'canceled a trial',+ // Alias kept so rows written before the billing service adopted American spelling still render.+ 'Billing trial cancelled': 'canceled a trial',+ 'Billing credits purchased': 'purchased credits',+}++const formatValue = (value: ActivityChange['before']): string =>+ value === null || value === undefined ? 'none' : `${value}`++const describeChange = (change: ActivityChange): string | null => {+ if (!change.field) {+ return null+ }+ switch (change.action) {+ case 'changed':+ return `${change.field} from ${formatValue(change.before)} to ${formatValue(change.after)}`+ case 'created':+ return `${change.field}: ${formatValue(change.after)}`+ case 'deleted':+ return `${change.field}: ${formatValue(change.before)}`+ default:+ return change.field+ }+}++const describeChanges = (changes: ActivityChange[]): string | null => {+ if (changes.length === 1) {+ return describeChange(changes[0])+ }+ const fields = changes.map((change) => change.field).filter((field): field is string => !!field)+ return fields.length ? fields.join(', ') : null+}++export function billingActivityDescriber(logItem: ActivityLogItem, asNotification?: boolean): HumanizedChange {+ // Every billing_activity row is written as an "updated" activity; fall back for anything else.+ if (logItem.activity !== 'updated') {+ return defaultDescriber(logItem, asNotification)+ }++ const action = BILLING_ACTIONS[logItem.detail.name || ''] || 'updated billing'+ const detail = describeChanges(logItem.detail.changes || [])++ return {+ description: (+ <>+ <strong className="ph-no-capture">{userNameForLogItem(logItem)}</strong> {action} in{' '}+ <Link to={urls.organizationBilling()}>billing</Link>+ {detail ? ` (${detail})` : ''}+ </>+ ),+ }+}diff --git a/frontend/src/types.ts b/frontend/src/types.tsindex 166cca568eaf..1ce9856228c2 100644--- a/frontend/src/types.ts+++ b/frontend/src/types.ts@@ -5889,6 +5889,7 @@ export enum ActivityScope {ANNOTATION = 'Annotation',BATCH_EXPORT = 'BatchExport',BATCH_IMPORT = 'BatchImport',+ BILLING = 'Billing',EXPORTED_ASSET = 'ExportedAsset',FEATURE_FLAG = 'FeatureFlag',PERSON = 'Person',diff --git a/posthog/models/activity_logging/activity_log.py b/posthog/models/activity_logging/activity_log.pyindex cdad75f41996..4cee628be7b9 100644--- a/posthog/models/activity_logging/activity_log.py+++ b/posthog/models/activity_logging/activity_log.py@@ -96,6 +96,7 @@ ActivityScope = Literal["StreamlitApp","Metric","TableCertification",+ "Billing",]ChangeAction = Literal["changed", "created", "deleted", "merged", "split", "exported", "revoked", "logged_in", "logged_out", "copied"diff --git a/products/platform_features/frontend/generated/api.schemas.ts b/products/platform_features/frontend/generated/api.schemas.tsindex 824ce8cb8e26..bf5c535ca959 100644--- a/products/platform_features/frontend/generated/api.schemas.ts+++ b/products/platform_features/frontend/generated/api.schemas.ts@@ -998,6 +998,7 @@ export type ActivityLogListParams = {* * `StreamlitApp` - StreamlitApp* * `Metric` - Metric* * `TableCertification` - TableCertification+ * * `Billing` - Billing* @minLength 1*/scope?: ActivityLogListScope@@ -1084,6 +1085,7 @@ export const ActivityLogListScope = {StreamlitApp: 'StreamlitApp',Metric: 'Metric',TableCertification: 'TableCertification',+ Billing: 'Billing',} as const/**@@ -1157,6 +1159,7 @@ export const ActivityLogListScope = {* * `StreamlitApp` - StreamlitApp* * `Metric` - Metric* * `TableCertification` - TableCertification+ * * `Billing` - Billing*/export type ActivityLogListScopesItem = (typeof ActivityLogListScopesItem)[keyof typeof ActivityLogListScopesItem]@@ -1231,6 +1234,7 @@ export const ActivityLogListScopesItem = {StreamlitApp: 'StreamlitApp',Metric: 'Metric',TableCertification: 'TableCertification',+ Billing: 'Billing',} as constexport type AdvancedActivityLogsListParams = {diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 0221ef16a8f3..be63a6be71ad 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -67504,6 +67504,7 @@ export namespace Schemas {* * `StreamlitApp` - StreamlitApp* * `Metric` - Metric* * `TableCertification` - TableCertification+ * * `Billing` - Billing* @minLength 1*/scope?: ActivityLogListScope;@@ -67591,6 +67592,7 @@ export namespace Schemas {StreamlitApp: 'StreamlitApp',Metric: 'Metric',TableCertification: 'TableCertification',+ Billing: 'Billing',} as const;/**@@ -67664,6 +67666,7 @@ export namespace Schemas {* * `StreamlitApp` - StreamlitApp* * `Metric` - Metric* * `TableCertification` - TableCertification+ * * `Billing` - Billing*/export type ActivityLogListScopesItem = typeof ActivityLogListScopesItem[keyof typeof ActivityLogListScopesItem];@@ -67739,6 +67742,7 @@ export namespace Schemas {StreamlitApp: 'StreamlitApp',Metric: 'Metric',TableCertification: 'TableCertification',+ Billing: 'Billing',} as const;export type AdvancedActivityLogsListParams = {