: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
import { Meta, StoryObj } from '@storybook/react'
import { within } from '@testing-library/dom'
import { FEATURE_FLAGS } from 'lib/constants'
import { makeDelay } from 'lib/utils/async'
import { App } from 'scenes/App'
import { urls } from 'scenes/urls'
import { mswDecorator } from '~/mocks/browser'
import EXPERIMENT_WITH_MEAN_METRIC from '~/mocks/fixtures/api/experiments/experiment_with_mean_metric.json'
import EXPOSURE_QUERY_RESULT from '~/mocks/fixtures/api/experiments/exposure_query_result.json'
import MEAN_METRIC_RESULT from '~/mocks/fixtures/api/experiments/mean_metric_result.json'
import { NodeKind } from '~/queries/schema/schema-general'
import { recalculationMocks, resultsByMetricType } from './recalculationMocks'
const EXPERIMENT_HEALTH = {
findings: [
{
code: 'flag_off_while_running',
subcode: 'running_but_no_rollout',
severity: 'warning',
title: 'The experiment is running, but no new users are being exposed',
detail: 'The linked feature flag has a 0% rollout, so no new users are being exposed. Users exposed earlier are still included in the results. End the experiment with a conclusion, or increase the rollout percentage to expose users.',
evidence: {},
actions: ['open_feature_flag'],
diagnostic_ref: 'A5',
},
],
checks: [
{ key: 'flag_state', name: "Flag state that doesn't match the experiment", status: 'finding', reason: null },
{ key: 'flag_history', name: 'Unreadable flag history', status: 'passed', reason: null },
{ key: 'split_changed_mid_run', name: 'Variant split changes since launch', status: 'passed', reason: null },
{
key: 'flag_variants_mismatch',
name: 'Flag variants not set up',
status: 'passed',
reason: null,
},
{ key: 'no_metric', name: 'Metrics not set up', status: 'passed', reason: null },
],
}
const EXPOSURES_WITH_BIAS_RISK = {
...EXPOSURE_QUERY_RESULT,
sample_ratio_mismatch: { expected: { control: 1000, 'test-1': 1000, 'test-2': 1000 }, p_value: 0.0001 },
bias_risk: { multiple_variant_percentage: 4.2 },
health_findings: [
{
code: 'srm',
subcode: null,
severity: 'warning',
title: 'Users are not split across variants as configured',
detail: "The distribution of users across variants doesn't match your configured rollout percentages (p < 0.001). This may indicate issues with randomization or data collection.",
evidence: { p_value: 0.0001 },
actions: [],
diagnostic_ref: 'A2',
},
{
code: 'bias_risk_multiple_excluded',
subcode: null,
severity: 'warning',
title: 'The uneven split may bias the results',
detail: '4.2% of users were exposed to multiple variants. With an uneven variant split and the Exclude handling, these users were dropped more often from the smaller variant, so its metrics can be biased. Use an even split and control exposure with the overall rollout, or switch the handling to First seen.',
evidence: { multiple_variant_percentage: 4.2 },
actions: ['adjust_distribution', 'use_first_seen_variant'],
diagnostic_ref: 'A1',
},
],
health_checks: [
{ key: 'srm', name: 'Split of users across variants', status: 'finding', reason: null },
{ key: 'bias_risk_multiple_excluded', name: 'Bias from an uneven split', status: 'finding', reason: null },
{ key: 'zero_exposures', name: 'Exposures not received since launch', status: 'passed', reason: null },
{ key: 'multiple_variants_share', name: 'Users exposed to multiple variants', status: 'passed', reason: null },
],
}
const RECALCULATION = recalculationMocks(
EXPERIMENT_WITH_MEAN_METRIC,
resultsByMetricType(EXPERIMENT_WITH_MEAN_METRIC, { mean: MEAN_METRIC_RESULT })
)
const meta: Meta = {
component: App,
title: 'Scenes-App/Experiments',
parameters: {
layout: 'fullscreen',
viewMode: 'story',
mockDate: '2025-01-27',
pageUrl: urls.experiment(EXPERIMENT_WITH_MEAN_METRIC.id),
featureFlags: [FEATURE_FLAGS.EXPERIMENT_HEALTH_FINDINGS],
},
decorators: [
mswDecorator({
get: {
...RECALCULATION.get,
[`/api/projects/:team_id/experiments/${EXPERIMENT_WITH_MEAN_METRIC.id}/`]: EXPERIMENT_WITH_MEAN_METRIC,
[`/api/projects/:team_id/experiments/${EXPERIMENT_WITH_MEAN_METRIC.id}/health/`]: EXPERIMENT_HEALTH,
[`/api/projects/:team_id/experiment_holdouts`]: [],
[`/api/projects/:team_id/experiment_saved_metrics/`]: [],
[`/api/projects/:team_id/feature_flags/${EXPERIMENT_WITH_MEAN_METRIC.feature_flag.id}/`]: {},
[`/api/projects/:team_id/feature_flags/${EXPERIMENT_WITH_MEAN_METRIC.feature_flag.id}/status/`]: {},
[`/api/environments/:team_id/default_release_conditions/`]: [],
},
post: {
...RECALCULATION.post,
// Exposures still load through experimentLogic; metric results come from the recalculation run.
'/api/environments/:team_id/query/:kind': async ({ request }) => {
const body = (await request.json()) as Record<string, any>
return body.query.kind === NodeKind.ExperimentExposureQuery
? [200, EXPOSURES_WITH_BIAS_RISK]
: [404]
},
},
}),
],
}
export default meta
type Story = StoryObj<{}>
// The metrics tab with issues: the chip and the health tab's count show them, and no warning banner renders.
export const ExperimentWithHealthFindings: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement)
await canvas.findByText('3 issues', {}, { timeout: 15000 })
await makeDelay(500)()
},
}