: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
// Leaf module: the toolbar imports these helpers, so they must not live in
// experimentsLogic (whose kea graph reaches the app's scene manifest).
import { Experiment, ExperimentStatus } from '~/types'
export type ExperimentStatusInput = Pick<Experiment, 'status' | 'start_date' | 'end_date'> | null | undefined
export function getExperimentStatus(experiment: ExperimentStatusInput): ExperimentStatus {
if (!experiment) {
return ExperimentStatus.Draft
}
if (experiment.status) {
return experiment.status
}
// Fallback for stale fixtures and older mocked data without API-supplied status.
if (experiment.end_date) {
return ExperimentStatus.Stopped
}
if (experiment.start_date) {
return ExperimentStatus.Running
}
return ExperimentStatus.Draft
}
export function isExperimentPaused(experiment: ExperimentStatusInput): boolean {
return getExperimentStatus(experiment) === ExperimentStatus.Paused
}
export function isExperimentExposureFrozen(experiment: ExperimentStatusInput): boolean {
return getExperimentStatus(experiment) === ExperimentStatus.ExposureFrozen
}
export function isLaunched(experiment: ExperimentStatusInput): boolean {
return getExperimentStatus(experiment) !== ExperimentStatus.Draft
}
export function hasEnded(experiment: ExperimentStatusInput): boolean {
return getExperimentStatus(experiment) === ExperimentStatus.Stopped
}