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(onboarding): use correct unit for plan card data retention (#62338)

Abhischek7da9984ec792
diff --git a/frontend/src/scenes/onboarding/billing/PlanCards.test.ts b/frontend/src/scenes/onboarding/billing/PlanCards.test.ts
new file mode 100644
index 000000000000..315b21c2b661
--- /dev/null
+++ b/frontend/src/scenes/onboarding/billing/PlanCards.test.ts
@@ -0,0 +1,31 @@
+import { BillingFeatureType } from '~/types'
+
+import { formatDataRetentionFeature } from './PlanCards'
+
+describe('formatDataRetentionFeature', () => {
+ const makeFeature = (limit?: number | null, unit?: string | null): BillingFeatureType =>
+ ({ key: 'session_replay_data_retention', name: 'Data retention', limit, unit }) as BillingFeatureType
+
+ // pluralize() joins the count and unit with a non-breaking space (U+00A0); normalize it for readable assertions.
+ const normalize = (value: string | null): string | null =>
+ value ? value.split(String.fromCharCode(160)).join(' ') : null
+
+ it.each([
+ // Analytics retention is supplied in years; session replay in months. Both must read naturally.
+ [7, 'years', '7 years data retention'],
+ [1, 'year', '1 year data retention'],
+ [3, 'months', '3 months data retention'],
+ [1, 'month', '1 month data retention'],
+ [90, 'days', '90 days data retention'],
+ ])('formats limit %s with unit "%s" as "%s"', (limit, unit, expected) => {
+ expect(normalize(formatDataRetentionFeature(makeFeature(limit, unit)))).toBe(expected)
+ })
+
+ it.each([
+ ['feature is undefined', undefined],
+ ['limit is missing', makeFeature(undefined, 'years')],
+ ['unit is missing', makeFeature(7, undefined)],
+ ])('returns null when %s', (_, feature) => {
+ expect(formatDataRetentionFeature(feature as BillingFeatureType | undefined)).toBe(null)
+ })
+})
diff --git a/frontend/src/scenes/onboarding/billing/PlanCards.tsx b/frontend/src/scenes/onboarding/billing/PlanCards.tsx
index d5c759ca478b..3ffd95cc6877 100644
--- a/frontend/src/scenes/onboarding/billing/PlanCards.tsx
+++ b/frontend/src/scenes/onboarding/billing/PlanCards.tsx
@@ -15,7 +15,7 @@ import { billingLogic } from 'scenes/billing/billingLogic'
import { billingProductLogic } from 'scenes/billing/billingProductLogic'
import { paymentEntryLogic } from 'scenes/billing/paymentEntryLogic'
-import { type BillingProductV2Type, OnboardingStepKey } from '~/types'
+import { type BillingFeatureType, type BillingProductV2Type, OnboardingStepKey } from '~/types'
import { onboardingLogic } from '../onboardingLogic'
import { FreeTierLimits } from './FreeTierLimits'
@@ -51,6 +51,16 @@ type PlanCardProps = {
hogPosition?: 'top-right' | 'top-left'
}
+// Retention differs per product: analytics is measured in years, session replay in months. Billing
+// supplies the unit ('year(s)' | 'month(s)' | 'day(s)'), so format from it rather than assuming years.
+export function formatDataRetentionFeature(feature?: BillingFeatureType): string | null {
+ if (!feature?.limit || !feature.unit) {
+ return null
+ }
+ const singularUnit = feature.unit.replace(/s$/, '')
+ return `${pluralize(feature.limit, singularUnit)} data retention`
+}
+
export const PlanCard: React.FC<PlanCardProps> = ({ planData, product, highlight, hogPosition = 'top-right' }) => {
const { billing } = useValues(billingLogic)
const { billingProductLoading } = useValues(billingProductLogic({ product }))
@@ -69,6 +79,7 @@ export const PlanCard: React.FC<PlanCardProps> = ({ planData, product, highlight
(feature) => feature.key === `${product.type}_data_retention`
)
const projectLimitFeature = platformPlan?.features.find((feature) => feature.key === 'organizations_projects')
+ const dataRetentionLabel = formatDataRetentionFeature(dataRetentionFeature)
const features = [
...(projectLimitFeature?.limit
@@ -79,9 +90,7 @@ export const PlanCard: React.FC<PlanCardProps> = ({ planData, product, highlight
},
]
: []),
- ...(dataRetentionFeature?.limit
- ? [{ name: `${dataRetentionFeature.limit}-year data retention`, available: true }]
- : []),
+ ...(dataRetentionLabel ? [{ name: dataRetentionLabel, available: true }] : []),
...planData.features,
]