: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 { IconCursorClick } from '@posthog/icons'
import { LemonTag } from 'lib/lemon-ui/LemonTag'
import { humanFriendlyNumber } from 'lib/utils/numbers'
import { VariantTag } from 'scenes/experiments/ExperimentView/VariantTag'
import { ExperimentMetric } from '~/queries/schema/schema-general'
import {
type ExperimentVariantResult,
formatChanceToWinForGoal,
formatDeltaPercent,
formatIntervalPercent,
formatPValue,
getIntervalLabel,
isBayesianResult,
isSignificant,
isWinning,
} from '../shared/utils'
export const renderTooltipContent = (
variantResult: ExperimentVariantResult,
metric: ExperimentMetric,
baselineKey: string
): JSX.Element => {
const intervalPercent = formatIntervalPercent(variantResult)
const intervalLabel = getIntervalLabel(variantResult)
const significant = isSignificant(variantResult)
const winning = isWinning(variantResult, metric.goal)
const isBaseline = variantResult.key === baselineKey
return (
<div className="flex flex-col gap-1">
<div className="flex justify-between items-center">
<VariantTag variantKey={variantResult.key} />
{!isBaseline && (
<LemonTag type={!significant ? 'muted' : winning ? 'success' : 'danger'} size="medium">
{!significant ? 'Not significant' : winning ? 'Won' : 'Lost'}
</LemonTag>
)}
</div>
<div className="flex justify-between items-center">
<span className="text-muted-alt font-semibold">Total value:</span>
<span className="font-semibold">
{variantResult.sum != null ? humanFriendlyNumber(variantResult.sum) : '–'}
</span>
</div>
<div className="flex justify-between items-center">
<span className="text-muted-alt font-semibold">Exposures:</span>
<span className="font-semibold">
{variantResult.number_of_samples != null
? humanFriendlyNumber(variantResult.number_of_samples)
: '–'}
</span>
</div>
{isBayesianResult(variantResult) ? (
<>
<div className="flex justify-between items-center">
<span className="text-muted-alt font-semibold">Chance to win:</span>
<span className="font-semibold">{formatChanceToWinForGoal(variantResult, metric.goal)}</span>
</div>
</>
) : (
<div className="flex justify-between items-center">
<span className="text-muted-alt font-semibold">p-value:</span>
<span className="font-semibold">{formatPValue(variantResult.p_value)}</span>
</div>
)}
<div className="flex justify-between items-center">
<span className="text-muted-alt font-semibold">Delta:</span>
<span className="font-semibold">
{isBaseline ? (
<em className="text-muted-alt">Baseline</em>
) : (
<span className={winning === undefined ? undefined : winning ? 'text-success' : 'text-danger'}>
{formatDeltaPercent(variantResult)}
</span>
)}
</span>
</div>
<div className="flex justify-between items-center">
<span className="text-muted-alt font-semibold">{intervalLabel}:</span>
<span className="font-semibold">{intervalPercent}</span>
</div>
<div className="text-muted-alt text-xs mt-1 text-center flex items-center justify-center gap-1">
<IconCursorClick className="text-sm" />
Click to view timeseries
</div>
</div>
)
}