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.

877 B
Raw Blame
import { AvailableFeature, BillingFeatureType, BillingPlanType } from '~/types'

const MONTHS_PER_UNIT: Record<string, number> = { month: 1, months: 1, year: 12, years: 12 }

export function eventsRetentionMonths(features: BillingFeatureType[] | null | undefined): number | null {
    const feature = features?.find((feature) => feature.key === AvailableFeature.PRODUCT_ANALYTICS_DATA_RETENTION)
    const monthsPerUnit = feature?.unit ? MONTHS_PER_UNIT[feature.unit] : undefined
    return feature?.limit && monthsPerUnit ? feature.limit * monthsPerUnit : null
}

export function longestEventsRetentionMonths(plans: (BillingPlanType | null | undefined)[]): number | null {
    const months = plans
        .map((plan) => eventsRetentionMonths(plan?.features))
        .filter((value): value is number => value !== null)
    return months.length ? Math.max(...months) : null
}