: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): extend startup billing limit cap to replay vision (#75078)
Arno Hillen9a2545d04f77
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 0a2039417507..6ac06b649774 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -7463,17 +7463,17 @@ snapshots:scenes-other-billing-product--billing-product-platform-addons-trial-used--light:hash: v1.k794b7964.a3610366ad2be64f9b6ff77176950ce1ff726937f39b0270c50bff9f0c3b9c55.83KQE3ww4YX5WW-n9BfxNXj4nF3BAEnJJtBETXTJjFIscenes-other-billing-product--billing-product-post-hog-code-limit--dark:- hash: v1.k794b7964.72b7cc6af966832979cfaa05e80101916cea119086e2efcb2ca203612cc6f5e5.hlEQZYCfx5UZi1nqmU0aQy8SlsDypG9euIdzGXYQF6I+ hash: v1.k794b7964.4b78251fa8d74756faed932bcc0db1d6120f10f10c2f6f53e84139e3df90dfc2.5GyBIHNQlAaglevfZegED1lzraMYJiewb9GR1qoO4lAscenes-other-billing-product--billing-product-post-hog-code-limit--light:- hash: v1.k794b7964.306708a3a4016583fa6a1469629a154713d6344f3df7873518a0bbc7ca697837.w54jEkGxfulwkuLeHqWR_foRLzvSikRlg3gB7rx-KPc+ hash: v1.k794b7964.e39ff099e48a04384066a8c5fce5dc850834117f4cb2981df6a245ac7816c566.Gw2BU8FIvRbJ1VZwWBIALqqXUhtpLUKok-YvLam1XvUscenes-other-billing-product--billing-product-post-hog-code-limit-editing--dark:- hash: v1.k794b7964.c6b8093fd29c173e56d0768d2e05b469ad199b62c817333f09e5a9d6d3a78960.J1TyH_H1kZH99IcXYSbbTvHyIw2zsCPoHO8jjuVWXpw+ hash: v1.k794b7964.075d4f1b6f311cc86ba4723b97f287d339bf14506e409d8f426bb64a9aed4ab3.zx3TCE0tQiG-3ONoWMzSY7WjUzH5OLwMBY1ZiKFLITUscenes-other-billing-product--billing-product-post-hog-code-limit-editing--light:- hash: v1.k794b7964.25e30eec15df65f1c599163ecfe18faf9386663bafa8b5b593a762873441f447.KbyAiGy9gSuNGLrbH2ZuNfOPC9OxNIXozHqQusk3RMU+ hash: v1.k794b7964.1ba1f1cd2fe6561b9e2fc3edce2e90fc59c7c9bfdf0fb46a341943b9338064c5.vqVPO7rln80u1FU8FYpCn20fie7C9BKUsdQYPnx_jdsscenes-other-billing-product--billing-product-post-hog-code-limit-next-period-capped--dark:- hash: v1.k794b7964.4a6d1557af5e90408397a07312429512db04b4158d8b5dc2eb9bf6d6d1ff65e7.4RfNh-7nWb2--TFJEvQ0hH2J7z-AELSsHIvFg3Tea4I+ hash: v1.k794b7964.d2fc2f0a856541d1b4bd33d35831934cad422820d867b8f57094c2296b3e9bdd.o1Y2O6vAeDxHR8h7hqYgHMNO8KtHjDNBTgHedAGSK2Qscenes-other-billing-product--billing-product-post-hog-code-limit-next-period-capped--light:- hash: v1.k794b7964.97841a5168d91bebe5b54c32d1e1c25f0830218d6717112900484691e829329b.VPVdnvFdRu8lgMP3U9HRq43l2KiRMDk2S7xVvjhNxlQ+ hash: v1.k794b7964.c4d25478cf2ad6a462de88fea90bd8d550b8c54af8ff512b55eb634845c2dce6.8NNi9mZi_IMQDxFruR31Pl6PD4jhmHJysUQDeQg3GfQscenes-other-billing-product--billing-product-temporarily-free--dark:hash: v1.k794b7964.17457ea2e809235689317d9e0feb224c18f8d5a81c8adf04b314e4d0c7b6f7d4.l_BpJhV7_FHvsDrKy34afdUPZvjK2sjH2OizL4u6SnIscenes-other-billing-product--billing-product-temporarily-free--light:diff --git a/frontend/src/scenes/billing/BillingProduct.stories.tsx b/frontend/src/scenes/billing/BillingProduct.stories.tsxindex 2c592b899318..a4f2adda7500 100644--- a/frontend/src/scenes/billing/BillingProduct.stories.tsx+++ b/frontend/src/scenes/billing/BillingProduct.stories.tsx@@ -8,7 +8,7 @@ import { makeBillingWithPlatformAddons } from '~/mocks/fixtures/_billing_platforimport preflightJson from '~/mocks/fixtures/_preflight.json'import { BillingProductV2Type, BillingType, StartupProgramLabel } from '~/types'-import { POSTHOG_CODE_BILLING_LIMIT_MAX, POSTHOG_CODE_USAGE_PRODUCT_KEY } from './billingLimitConfig'+import { POSTHOG_CODE_USAGE_PRODUCT_KEY, STARTUP_PROGRAM_BILLING_LIMIT_MAX } from './billingLimitConfig'import { BillingProduct } from './BillingProduct'const meta: Meta = {@@ -58,9 +58,9 @@ const makePostHogCodeUsageBilling = ({docs_url: 'https://posthog.com/docs/posthog-code',subscribed: true,type: POSTHOG_CODE_USAGE_PRODUCT_KEY,- current_amount_usd: currentLimitUsd > POSTHOG_CODE_BILLING_LIMIT_MAX ? '3750.00' : '25.00',- projected_amount_usd: currentLimitUsd > POSTHOG_CODE_BILLING_LIMIT_MAX ? '4100.00' : '75.00',- projected_amount_usd_with_limit: currentLimitUsd > POSTHOG_CODE_BILLING_LIMIT_MAX ? '3750.00' : '75.00',+ current_amount_usd: currentLimitUsd > STARTUP_PROGRAM_BILLING_LIMIT_MAX ? '3750.00' : '25.00',+ projected_amount_usd: currentLimitUsd > STARTUP_PROGRAM_BILLING_LIMIT_MAX ? '4100.00' : '75.00',+ projected_amount_usd_with_limit: currentLimitUsd > STARTUP_PROGRAM_BILLING_LIMIT_MAX ? '3750.00' : '75.00',plans: sourceProduct.plans.map((plan) => ({...plan,initial_billing_limit: 50,diff --git a/frontend/src/scenes/billing/billingLimitConfig.test.ts b/frontend/src/scenes/billing/billingLimitConfig.test.tsnew file mode 100644index 000000000000..8516ed7bfd3a--- /dev/null+++ b/frontend/src/scenes/billing/billingLimitConfig.test.ts@@ -0,0 +1,62 @@+import { BillingProductV2Type, BillingType, StartupProgramLabel } from '~/types'++import {+ BillingLimitConfig,+ getBillingLimitConfig,+ MAX_BILLING_LIMIT,+ STARTUP_PROGRAM_BILLING_LIMIT_MAX,+} from './billingLimitConfig'++describe('getBillingLimitConfig', () => {+ const getConfig = (+ productType: string,+ startupProgramLabel: StartupProgramLabel | null,+ limits: { customLimitUsd?: number | null; billingLimitNextPeriod?: number | null } = {}+ ): BillingLimitConfig =>+ getBillingLimitConfig({+ billing: { startup_program_label: startupProgramLabel } as BillingType,+ product: { type: productType } as BillingProductV2Type,+ customLimitUsd: limits.customLimitUsd ?? null,+ billingLimitNextPeriod: limits.billingLimitNextPeriod ?? null,+ })++ it.each(['posthog_code_usage', 'replay_vision'])(+ 'caps %s for startup program customers and explains why',+ (productType) => {+ const config = getConfig(productType, StartupProgramLabel.YC)+ expect(config.max).toBe(STARTUP_PROGRAM_BILLING_LIMIT_MAX)+ expect(config.removalDisabledReason).toBeTruthy()+ expect(config.help).toContain('startup program')+ expect(config.maxExceededError).toContain('startup program')+ }+ )++ it.each(['posthog_code_usage', 'replay_vision', 'product_analytics'])(+ 'does not cap %s without startup program enrollment',+ (productType) => {+ const config = getConfig(productType, null)+ expect(config.max).toBe(MAX_BILLING_LIMIT)+ expect(config.removalDisabledReason).toBeNull()+ expect(config.help).toBeNull()+ }+ )++ it.each([+ [3750, 2000, true],+ [3750, 5000, false],+ [null, 2000, false],+ ])(+ 'with current limit %p and next period limit %p, above-cap notice shown: %p',+ (customLimitUsd, billingLimitNextPeriod, noticeShown) => {+ const config = getConfig('replay_vision', StartupProgramLabel.YC, {+ customLimitUsd,+ billingLimitNextPeriod,+ })+ if (noticeShown) {+ expect(config.currentAboveMaxNotice).toContain('next period')+ } else {+ expect(config.currentAboveMaxNotice).toBeNull()+ }+ }+ )+})diff --git a/frontend/src/scenes/billing/billingLimitConfig.ts b/frontend/src/scenes/billing/billingLimitConfig.tsindex 4701ca7ebdce..5c8cd3a67554 100644--- a/frontend/src/scenes/billing/billingLimitConfig.ts+++ b/frontend/src/scenes/billing/billingLimitConfig.ts@@ -1,9 +1,10 @@import { BillingProductV2AddonType, BillingProductV2Type, BillingType } from '~/types'-const MAX_BILLING_LIMIT: number = 50000+export const MAX_BILLING_LIMIT: number = 50000export const POSTHOG_CODE_USAGE_PRODUCT_KEY = 'posthog_code_usage'-export const POSTHOG_CODE_BILLING_LIMIT_MAX: number = 3000+export const REPLAY_VISION_PRODUCT_KEY = 'replay_vision'+export const STARTUP_PROGRAM_BILLING_LIMIT_MAX: number = 3000export type BillingLimitConfig = {max: number@@ -30,26 +31,35 @@ const DEFAULT_BILLING_LIMIT_CONFIG: BillingLimitConfig = {type BillingLimitConfigResolver = (context: BillingLimitConfigContext) => Partial<BillingLimitConfig> | null-const BILLING_LIMIT_CONFIG_BY_PRODUCT: Record<string, BillingLimitConfigResolver> = {- [POSTHOG_CODE_USAGE_PRODUCT_KEY]: ({ billing, customLimitUsd, billingLimitNextPeriod }) => {+// Mirrors the caps the billing service enforces for startup-program customers, so the form+// rejects out-of-range limits before the API does. The billing API product names are too+// verbose for copy (e.g. "PostHog Code (usage-based)").+const startupProgramCapResolver = (productName: string): BillingLimitConfigResolver => {+ return ({ billing, customLimitUsd, billingLimitNextPeriod }) => {if (!billing?.startup_program_label) {return null}+ const cap = STARTUP_PROGRAM_BILLING_LIMIT_MAXreturn {- max: POSTHOG_CODE_BILLING_LIMIT_MAX,- help: 'Code billing limits can be set from $0 to $3,000 per month.',- removalDisabledReason: "Code billing limits can't be removed. Set the limit to $0 instead.",- maxExceededError: "Code billing limits can't exceed $3,000 per month.",+ max: cap,+ help: `While your organization is in the startup program, ${productName} billing limits can be set from $0 to $${cap.toLocaleString()} per month.`,+ removalDisabledReason: `While your organization is in the startup program, ${productName} billing limits can't be removed. Set the limit to $0 instead.`,+ maxExceededError: `While your organization is in the startup program, ${productName} billing limits can't exceed $${cap.toLocaleString()} per month.`,currentAboveMaxNotice:customLimitUsd !== null &&- customLimitUsd > POSTHOG_CODE_BILLING_LIMIT_MAX &&+ customLimitUsd > cap &&billingLimitNextPeriod !== null &&- billingLimitNextPeriod <= POSTHOG_CODE_BILLING_LIMIT_MAX- ? `Current usage is already above the Code billing limit cap, so this period's limit stays at $${customLimitUsd.toLocaleString()}. The $${billingLimitNextPeriod.toLocaleString()} limit starts next period.`+ billingLimitNextPeriod <= cap+ ? `Current usage is already above the startup program cap, so this period's limit stays at $${customLimitUsd.toLocaleString()}. The $${billingLimitNextPeriod.toLocaleString()} limit starts next period.`: null,}- },+ }+}++const BILLING_LIMIT_CONFIG_BY_PRODUCT: Record<string, BillingLimitConfigResolver> = {+ [POSTHOG_CODE_USAGE_PRODUCT_KEY]: startupProgramCapResolver('Code'),+ [REPLAY_VISION_PRODUCT_KEY]: startupProgramCapResolver('Replay vision'),}export const getBillingLimitConfig = (context: BillingLimitConfigContext): BillingLimitConfig => {