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.

feat(experiments): exclude variant from experiment. (#59998)

Rodrigo Ilorobe00882499fc
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx
index 9848391142f2..ceaafcef600f 100644
--- a/frontend/src/lib/constants.tsx
+++ b/frontend/src/lib/constants.tsx
@@ -289,6 +289,7 @@ export const FEATURE_FLAGS = {
EXPERIMENT_FUNNEL_DWH_SUPPORT: 'experiment-funnel-dwh-support', // owner: @rodrigoi #team-experiments
EXPERIMENT_SESSION_REPLAYS_SKILL: 'experiment-session-replays-skill', // owner: @rodrigoi #team-experiments
EXPERIMENTS_DW_AA_TEST: 'experiments-dw-aa-test', // owner: @rodrigoi #team-experiments
+ EXPERIMENTS_EXCLUDED_VARIANTS: 'experiments-excluded-variants', // owner: @rodrigoi #team-experiments
EXPERIMENTS_LLM_PROMPTS: 'experiments-llm-prompts', // owner: @jurajmajerik #team-experiments
EXPERIMENTS_SHOW_SQL: 'experiments-show-sql', // owner: @jurajmajerik #team-experiments
EXPERIMENTS_SYNC_QUERIES: 'experiments-sync-queries', // owner: @andehen #team-experiments
diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.json
index 286e8fe5123f..f5b3f99fbcda 100644
--- a/frontend/src/queries/schema.json
+++ b/frontend/src/queries/schema.json
@@ -18661,7 +18661,7 @@
"type": "array"
},
"id": {
- "type": ["number", "null"]
+ "type": "integer"
},
"name": {
"type": "string"
@@ -19041,6 +19041,13 @@
"ExperimentParameters": {
"additionalProperties": false,
"properties": {
+ "excluded_variants": {
+ "description": "Variant keys to exclude from metric result calculations. Excluded variants are still served to users but omitted from statistical analysis.",
+ "items": {
+ "type": "string"
+ },
+ "type": "array"
+ },
"feature_flag_variants": {
"description": "Experiment variants. If specified, must include a variant with key 'control' (lowercase). Defaults to a 50/50 control/test split when omitted. Minimum 2, maximum 20.",
"items": {
diff --git a/frontend/src/queries/schema/schema-general.ts b/frontend/src/queries/schema/schema-general.ts
index 31d58536367b..a357ca55b725 100644
--- a/frontend/src/queries/schema/schema-general.ts
+++ b/frontend/src/queries/schema/schema-general.ts
@@ -3670,6 +3670,8 @@ export interface ExperimentParameters {
minimum_detectable_effect?: number
/** Overall rollout percentage (0-100). Controls what fraction of all users enter the experiment. Users outside the rollout never see any variant and are excluded from analysis. Default: 100. */
rollout_percentage?: number
+ /** Variant keys to exclude from metric result calculations. Excluded variants are still served to users but omitted from statistical analysis. */
+ excluded_variants?: string[]
}
/** Slim exposure config for experiment API payloads. */
diff --git a/frontend/src/scenes/experiments/ExperimentView/DistributionTable.tsx b/frontend/src/scenes/experiments/ExperimentView/DistributionTable.tsx
index 3e57f65cf1e8..3968b808a427 100644
--- a/frontend/src/scenes/experiments/ExperimentView/DistributionTable.tsx
+++ b/frontend/src/scenes/experiments/ExperimentView/DistributionTable.tsx
@@ -1,29 +1,31 @@
import { useActions, useValues } from 'kea'
import { useEffect, useState } from 'react'
-import { IconFlag } from '@posthog/icons'
+import { IconFlag, IconLock } from '@posthog/icons'
import {
LemonBanner,
LemonButton,
LemonDialog,
LemonModal,
+ LemonSwitch,
LemonTable,
LemonTableColumns,
+ LemonTag,
Link,
} from '@posthog/lemon-ui'
-import { AuthorizedUrlList } from 'lib/components/AuthorizedUrlList/AuthorizedUrlList'
-import { AuthorizedUrlListType } from 'lib/components/AuthorizedUrlList/authorizedUrlListLogic'
-import { IconOpenInApp } from 'lib/lemon-ui/icons'
-
-import { MultivariateFlagVariant } from '~/types'
-
+import { AuthorizedUrlList } from '~/lib/components/AuthorizedUrlList/AuthorizedUrlList'
+import { AuthorizedUrlListType } from '~/lib/components/AuthorizedUrlList/authorizedUrlListLogic'
+import { useFeatureFlag } from '~/lib/hooks/useFeatureFlag'
+import { IconOpenInApp } from '~/lib/lemon-ui/icons'
import {
useVariantDistributionValidation,
VariantDistributionEditor,
-} from '../ExperimentForm/VariantDistributionEditor'
-import { experimentLogic } from '../experimentLogic'
-import { modalsLogic } from '../modalsLogic'
+} from '~/scenes/experiments/ExperimentForm/VariantDistributionEditor'
+import { experimentLogic } from '~/scenes/experiments/experimentLogic'
+import { modalsLogic } from '~/scenes/experiments/modalsLogic'
+import { MultivariateFlagVariant } from '~/types'
+
import { HoldoutSelector } from './HoldoutSelector'
import { VariantScreenshot } from './VariantScreenshot'
import { VariantTag } from './VariantTag'
@@ -106,8 +108,25 @@ export function DistributionModal(): JSX.Element {
export function DistributionTable(): JSX.Element {
const { openDistributionModal } = useActions(modalsLogic)
- const { experiment } = useValues(experimentLogic)
- const { reportExperimentReleaseConditionsViewed } = useActions(experimentLogic)
+ const { experiment, excludedVariants, experimentUpdateLoading } = useValues(experimentLogic)
+ const { reportExperimentReleaseConditionsViewed, setVariantExcluded } = useActions(experimentLogic)
+
+ const excludedVariantsEnabled = useFeatureFlag('EXPERIMENTS_EXCLUDED_VARIANTS')
+
+ /**
+ * This is future-proofing to match the experiment query runner backend, that uses
+ * the baseline variant key to determine the baseline variant.
+ */
+ const baselineKey = experiment.stats_config?.baseline_variant_key || 'control'
+ const variants = experiment.feature_flag?.filters.multivariate?.variants || []
+
+ /**
+ * We use this check to disable the toggle if there's only one test variant left.
+ * - not the baseline variant
+ * - not excluded
+ */
+ const hasOnlyOneTestVariant =
+ variants.filter(({ key }) => key !== baselineKey && !excludedVariants.includes(key)).length <= 1
const onSelectElement = (variant: string): void => {
LemonDialog.open({
@@ -146,6 +165,55 @@ export function DistributionTable(): JSX.Element {
return <div>{`${item.rollout_percentage}%`}</div>
},
},
+ ...(excludedVariantsEnabled
+ ? [
+ {
+ className,
+ key: 'analysis',
+ title: 'Analysis',
+ render: function Analysis(_, { key }): JSX.Element {
+ /**
+ * bail early for holdouts
+ */
+ if (key === `holdout-${experiment.holdout?.id}`) {
+ return <span className="text-muted">-</span>
+ }
+ /**
+ * bail early for baseline variant
+ */
+ if (key === baselineKey) {
+ return (
+ <LemonTag type="muted" icon={<IconLock />}>
+ Baseline
+ </LemonTag>
+ )
+ }
+ const excluded = excludedVariants.includes(key)
+ /**
+ * we disable the toggle if:
+ * - the variant is not excluded: we have to allow re-including it
+ * - there's only one variant left when we remove the baseline
+ */
+ const disableToggle = !excluded && hasOnlyOneTestVariant
+ return (
+ <div className="flex items-center gap-2">
+ <LemonSwitch
+ checked={!excluded}
+ onChange={(checked) => setVariantExcluded(key, !checked)}
+ disabledReason={
+ disableToggle
+ ? 'At least one test variant must remain in analysis'
+ : undefined
+ }
+ loading={experimentUpdateLoading}
+ />
+ {excluded && <LemonTag type="warning">Excluded</LemonTag>}
+ </div>
+ )
+ },
+ } as LemonTableColumns<MultivariateFlagVariant>[number],
+ ]
+ : []),
{
className: className,
key: 'variant_screenshot',
@@ -235,13 +303,24 @@ export function DistributionTable(): JSX.Element {
variants are modified to show their relative rollout percentage.
</LemonBanner>
)}
+ {excludedVariants.length > 0 && hasOnlyOneTestVariant && (
+ <LemonBanner type="warning" className="mb-4">
+ At least one test variant must remain in analysis. Re-include a variant to exclude others.
+ </LemonBanner>
+ )}
<LemonTable
loading={false}
columns={columns}
dataSource={tableData}
- rowClassName={(item) =>
- item.key === `holdout-${experiment.holdout?.id}` ? 'dark:bg-fill-primary bg-mid' : ''
- }
+ rowClassName={(item) => {
+ if (item.key === `holdout-${experiment.holdout?.id}`) {
+ return 'dark:bg-fill-primary bg-mid'
+ }
+ if (excludedVariants.includes(item.key)) {
+ return 'bg-fill-tertiary'
+ }
+ return ''
+ }}
/>
</div>
)
diff --git a/frontend/src/scenes/experiments/ExperimentView/Exposures.tsx b/frontend/src/scenes/experiments/ExperimentView/Exposures.tsx
index 50016a10d6a9..98dc48aeef82 100644
--- a/frontend/src/scenes/experiments/ExperimentView/Exposures.tsx
+++ b/frontend/src/scenes/experiments/ExperimentView/Exposures.tsx
@@ -2,12 +2,12 @@ import { useActions, useValues } from 'kea'
import { useCallback, useState } from 'react'
import { IconCheckCircle, IconCorrelationAnalysis, IconInfo, IconPencil, IconWarning } from '@posthog/icons'
-import { LemonButton, LemonCollapse, LemonTable, Spinner, Tooltip } from '@posthog/lemon-ui'
+import { LemonButton, LemonCollapse, LemonTable, LemonTag, Spinner, Tooltip } from '@posthog/lemon-ui'
import { getSeriesBackgroundColor, getSeriesColor } from 'lib/colors'
import { dayjs } from 'lib/dayjs'
import { useChart } from 'lib/hooks/useChart'
-import { humanFriendlyLargeNumber, humanFriendlyNumber } from 'lib/utils'
+import { humanFriendlyLargeNumber, humanFriendlyNumber, pluralize } from 'lib/utils'
import {
ExperimentExposureCriteria,
@@ -230,7 +230,8 @@ function getExposureCriteriaLabel(exposureCriteria: ExperimentExposureCriteria |
}
export function Exposures(): JSX.Element {
- const { exposures, exposuresLoading, exposureCriteria, isExperimentDraft } = useValues(experimentLogic)
+ const { exposures, exposuresLoading, exposureCriteria, isExperimentDraft, experiment, excludedVariants } =
+ useValues(experimentLogic)
const { openExposureCriteriaModal } = useActions(exposureCriteriaModalLogic)
const colors = useChartColors()
@@ -319,6 +320,26 @@ export function Exposures(): JSX.Element {
<IconWarning className="text-warning text-lg" />
</Tooltip>
)}
+ {excludedVariants.length > 0 && (
+ <Tooltip
+ title={`Excluded from analysis: ${excludedVariants.join(', ')}. Manage on the Variants tab.`}
+ >
+ <span className="text-secondary text-xs">
+ {pluralize(
+ excludedVariants.length,
+ 'variant excluded',
+ 'variants excluded'
+ )}
+ </span>
+ </Tooltip>
+ )}
+ {experiment.holdout && (
+ <Tooltip title="Users held out of this experiment and not included in analysis.">
+ <LemonTag type="option" className="ml-2">
+ {experiment.holdout.name}
+ </LemonTag>
+ </Tooltip>
+ )}
</>
)}
</div>
@@ -386,9 +407,24 @@ export function Exposures(): JSX.Element {
<div>
<h3 className="card-secondary">Total exposures</h3>
<LemonTable
+ rowClassName={(series) =>
+ series.isExcluded || series.isHoldout ? 'opacity-60' : ''
+ }
dataSource={[
//This includes EXPERIMENT_VARIANT_MULTIPLE
...(exposures?.timeseries || []),
+ ...excludedVariants.map((variant) => ({
+ variant,
+ isExcluded: true,
+ })),
+ ...(experiment.holdout
+ ? [
+ {
+ variant: `holdout-${experiment.holdout_id}`,
+ isHoldout: true,
+ },
+ ]
+ : []),
{ variant: '__total__', isTotal: true },
]}
columns={[
@@ -425,30 +461,51 @@ export function Exposures(): JSX.Element {
{
title: 'Exposures',
key: 'exposures',
- render: function Exposures(_, series) {
- if (series.isTotal) {
+ render: function Exposures(
+ _,
+ { variant, isTotal, isExcluded, isHoldout }
+ ) {
+ if (isTotal) {
return (
<span className="font-semibold">
{humanFriendlyNumber(totalExposures)}
</span>
)
}
- return humanFriendlyNumber(
- exposures?.total_exposures[series.variant]
- )
+ if (isExcluded || isHoldout) {
+ return <span className="text-secondary">—</span>
+ }
+ return humanFriendlyNumber(exposures?.total_exposures[variant])
},
},
{
title: '%',
key: 'percentage',
- render: function Percentage(_, series) {
- if (series.isTotal) {
+ render: function Percentage(
+ _,
+ { variant, isTotal, isExcluded, isHoldout }
+ ) {
+ if (isTotal) {
return (
<span className="font-semibold">
{totalExposures > 0 ? '100.0%' : '-%'}
</span>
)
}
+ if (isExcluded) {
+ return (
+ <span className="text-secondary italic">
+ Excluded from analysis
+ </span>
+ )
+ }
+ if (isHoldout) {
+ return (
+ <span className="text-secondary italic">
+ Reserved (holdout)
+ </span>
+ )
+ }
let total = 0
if (exposures?.total_exposures) {
for (const [_, value] of Object.entries(
@@ -462,8 +519,7 @@ export function Exposures(): JSX.Element {
{total ? (
<>
{(
- (exposures?.total_exposures[series.variant] /
- total) *
+ (exposures?.total_exposures[variant] / total) *
100
).toFixed(1)}
%
diff --git a/frontend/src/scenes/experiments/ExperimentView/VariantTag.tsx b/frontend/src/scenes/experiments/ExperimentView/VariantTag.tsx
index 018264c23adb..0898d1499714 100644
--- a/frontend/src/scenes/experiments/ExperimentView/VariantTag.tsx
+++ b/frontend/src/scenes/experiments/ExperimentView/VariantTag.tsx
@@ -3,9 +3,9 @@ import { useValues } from 'kea'
import { LemonTag, Tooltip } from '@posthog/lemon-ui'
-import { EXPERIMENT_VARIANT_MULTIPLE } from '../constants'
-import { experimentLogic } from '../experimentLogic'
-import { getVariantColor } from '../utils'
+import { EXPERIMENT_VARIANT_MULTIPLE } from '~/scenes/experiments/constants'
+import { experimentLogic } from '~/scenes/experiments/experimentLogic'
+import { getVariantColor } from '~/scenes/experiments/utils'
export function VariantTag({
variantKey,
@@ -30,16 +30,12 @@ export function VariantTag({
? getVariantColor(variantKey, experiment.feature_flag?.filters.multivariate?.variants)
: 'var(--text-muted)'
+ /**
+ * this is only used on the distribution table, to display the holdout name
+ */
if (experiment.holdout && variantKey === `holdout-${experiment.holdout_id}`) {
return (
<span className={clsx('flex items-center min-w-0', className)}>
- <div
- className="w-2 h-2 rounded-full shrink-0"
- // eslint-disable-next-line react/forbid-dom-props
- style={{
- backgroundColor: variantColor,
- }}
- />
<LemonTag type="option" className="ml-2">
{experiment.holdout.name}
</LemonTag>
diff --git a/frontend/src/scenes/experiments/MetricsView/new/MetricRowGroup.tsx b/frontend/src/scenes/experiments/MetricsView/new/MetricRowGroup.tsx
index 048976d1c9ab..52c05019cdfe 100644
--- a/frontend/src/scenes/experiments/MetricsView/new/MetricRowGroup.tsx
+++ b/frontend/src/scenes/experiments/MetricsView/new/MetricRowGroup.tsx
@@ -20,15 +20,13 @@ import {
NewExperimentQueryResponse,
} from '~/queries/schema/schema-general'
import { NodeKind } from '~/queries/schema/schema-general'
-import { Experiment, InsightType } from '~/types'
-
-import { experimentLogic } from '../../experimentLogic'
-import { isLaunched } from '../../experimentsLogic'
-import { useColumnWidthSync } from '../hooks/useColumnWidthSync'
-import { ChartEmptyState } from '../shared/ChartEmptyState'
-import { ChartLoadingState } from '../shared/ChartLoadingState'
-import { useChartColors } from '../shared/colors'
-import { MetricHeader } from '../shared/MetricHeader'
+import { experimentLogic } from '~/scenes/experiments/experimentLogic'
+import { isLaunched } from '~/scenes/experiments/experimentsLogic'
+import { useColumnWidthSync } from '~/scenes/experiments/MetricsView/hooks/useColumnWidthSync'
+import { ChartEmptyState } from '~/scenes/experiments/MetricsView/shared/ChartEmptyState'
+import { ChartLoadingState } from '~/scenes/experiments/MetricsView/shared/ChartLoadingState'
+import { useChartColors } from '~/scenes/experiments/MetricsView/shared/colors'
+import { MetricHeader } from '~/scenes/experiments/MetricsView/shared/MetricHeader'
import {
type ExperimentVariantResult,
formatChanceToWinForGoal,
@@ -42,7 +40,9 @@ import {
isDeltaPositive,
isSignificant,
isWinning,
-} from '../shared/utils'
+} from '~/scenes/experiments/MetricsView/shared/utils'
+import { Experiment, InsightType } from '~/types'
+
import { ChartCell } from './ChartCell'
import {
CELL_HEIGHT,
@@ -744,8 +744,7 @@ export function MetricRowGroup({
// At this point, we know result is defined, so we can safely access its properties
const baselineResult = result.baseline
const variantResults = result.variant_results || []
- const totalRows = 1 + variantResults.length
- const totalRowsHeightStyle = getScaledHeightStyle(totalRows)
+ const totalRowsHeightStyle = getScaledHeightStyle(variantResults.length + 1)
const ratioMetricLabel = (variant: ExperimentStatsBaseValidated, metric: ExperimentMetric): JSX.Element => {
return (
@@ -802,7 +801,7 @@ export function MetricRowGroup({
{/* Metric column - with rowspan */}
<td
className={`w-1/5 border-r p-3 align-top text-left relative overflow-hidden ${!isLastMetric ? 'border-b' : ''} ${isAlternatingRow ? 'bg-bg-table' : 'bg-bg-light'}`}
- rowSpan={totalRows}
+ rowSpan={variantResults.length + 1}
style={totalRowsHeightStyle}
>
<MetricHeader
@@ -865,7 +864,7 @@ export function MetricRowGroup({
className={`w-20 pt-3 align-top relative overflow-hidden ${
!isLastMetric ? 'border-b' : ''
} ${isAlternatingRow ? 'bg-bg-table' : 'bg-bg-light'}`}
- rowSpan={totalRows}
+ rowSpan={variantResults.length + 1}
style={totalRowsHeightStyle}
>
{showDetailsModal && (
diff --git a/frontend/src/scenes/experiments/experimentLogic.test.ts b/frontend/src/scenes/experiments/experimentLogic.test.ts
index 4d1c4315b69d..4ef25c957bce 100644
--- a/frontend/src/scenes/experiments/experimentLogic.test.ts
+++ b/frontend/src/scenes/experiments/experimentLogic.test.ts
@@ -1595,4 +1595,74 @@ describe('experimentLogic', () => {
expect(extractErrorDetailString(circular)).toBeNull()
})
})
+
+ describe('excluded variants', () => {
+ it('excludedVariants selector returns parameters.excluded_variants', async () => {
+ await expectLogic(logic, () => {
+ logic.actions.setExperiment({
+ ...experiment,
+ parameters: {
+ ...experiment.parameters,
+ excluded_variants: ['test-2'],
+ },
+ })
+ }).toMatchValues({
+ excludedVariants: ['test-2'],
+ })
+ })
+
+ it('excludedVariants defaults to [] when missing', async () => {
+ await expectLogic(logic, () => {
+ logic.actions.setExperiment({
+ ...experiment,
+ parameters: { ...experiment.parameters },
+ })
+ }).toMatchValues({
+ excludedVariants: [],
+ })
+ })
+
+ it('setVariantExcluded sends a PATCH with the merged exclusion list', async () => {
+ jest.spyOn(api, 'update')
+ api.update.mockClear()
+ const existingExperiment = {
+ ...experiment,
+ parameters: {
+ ...experiment.parameters,
+ excluded_variants: ['test-1'],
+ },
+ } as Experiment
+ api.update.mockResolvedValue(existingExperiment)
+
+ logic.actions.setExperiment(existingExperiment)
+
+ await expectLogic(logic, () => {
+ logic.actions.setVariantExcluded('test-2', true)
+ })
+ .toDispatchActions(['setVariantExcluded'])
+ .toFinishAllListeners()
+
+ const sentParams = (api.update.mock.calls[0][1] as Record<string, any>).parameters
+ expect(sentParams.excluded_variants).toEqual(expect.arrayContaining(['test-1', 'test-2']))
+ expect(sentParams.excluded_variants).toHaveLength(2)
+ })
+
+ it('setVariantExcluded(key, false) removes the key from the exclusion list', async () => {
+ await expectLogic(logic, () => {
+ logic.actions.setExperiment({
+ ...experiment,
+ parameters: {
+ ...experiment.parameters,
+ excluded_variants: ['test-1', 'test-2'],
+ },
+ })
+ }).toMatchValues({
+ excludedVariants: ['test-1', 'test-2'],
+ })
+
+ // Re-include test-2 — the new list (computed in the listener) must drop it.
+ const next = logic.values.excludedVariants.filter((k) => k !== 'test-2')
+ expect(next).toEqual(['test-1'])
+ })
+ })
})
diff --git a/frontend/src/scenes/experiments/experimentLogic.tsx b/frontend/src/scenes/experiments/experimentLogic.tsx
index 548ba5439a6a..d65a601cfd4d 100644
--- a/frontend/src/scenes/experiments/experimentLogic.tsx
+++ b/frontend/src/scenes/experiments/experimentLogic.tsx
@@ -801,6 +801,7 @@ export const experimentLogic = kea<experimentLogicType>([
setShowNotificationOffer: (show: boolean) => ({ show }),
setNotifyWhenResultsReady: (notify: boolean) => ({ notify }),
toggleDebugPanel: true,
+ setVariantExcluded: (variantKey: string, excluded: boolean) => ({ variantKey, excluded }),
}),
reducers({
showDebugPanel: [
@@ -2215,6 +2216,36 @@ export const experimentLogic = kea<experimentLogicType>([
actions.loadSecondaryMetricsResults(true)
}
},
+ setVariantExcluded: async ({ variantKey, excluded }, _breakpoint) => {
+ const current = values.excludedVariants
+ const next = excluded
+ ? Array.from(new Set([...current, variantKey]))
+ : current.filter((k: string) => k !== variantKey)
+
+ try {
+ await asyncActions.updateExperiment({
+ parameters: { ...values.experiment.parameters, excluded_variants: next },
+ })
+ lemonToast.success(
+ excluded
+ ? `Variant ${variantKey} excluded from analysis`
+ : `Variant ${variantKey} re-included in analysis`,
+ {
+ button: {
+ label: 'Undo',
+ action: () => actions.setVariantExcluded(variantKey, !excluded),
+ },
+ }
+ )
+ // Re-fetch metric and exposure results since the variant set changed.
+ actions.loadPrimaryMetricsResults(true)
+ actions.loadSecondaryMetricsResults(true)
+ actions.loadExposures(true)
+ } catch (error) {
+ lemonToast.error('Could not update variant exclusion. Please try again.')
+ throw error
+ }
+ },
setAutoRefresh: ({ enabled, interval }) => {
// Track when user toggles auto-refresh settings
actions.reportExperimentAutoRefreshToggled(values.experiment, enabled, interval)
@@ -2419,6 +2450,10 @@ export const experimentLogic = kea<experimentLogicType>([
return experiment?.parameters?.feature_flag_variants || []
},
],
+ excludedVariants: [
+ (s) => [s.experiment],
+ (experiment: Experiment): string[] => experiment?.parameters?.excluded_variants ?? [],
+ ],
experimentMathAggregationForTrends: [
(s) => [s.experiment],
(experiment) => (): PropertyMathType | CountPerActorMathType | undefined => {
diff --git a/frontend/src/types.ts b/frontend/src/types.ts
index 218c4dd466fb..ebde2a17a025 100644
--- a/frontend/src/types.ts
+++ b/frontend/src/types.ts
@@ -4567,6 +4567,7 @@ export enum ExperimentConclusion {
}
export interface ExperimentHoldoutType {
+ /** @asType integer */
id: number | null
name: string
description: string | null
@@ -4615,6 +4616,7 @@ export interface Experiment {
aggregation_group_type_index?: integer
variant_screenshot_media_ids?: Record<string, string[]>
rollout_percentage?: number
+ excluded_variants?: string[]
/** Present when the experiment was created from an LLM prompt via /create_from_prompt/. */
prompt_metadata?: {
name: string
@@ -4635,6 +4637,7 @@ export interface Experiment {
stats_config?: {
version?: number
method?: ExperimentStatsMethod
+ baseline_variant_key?: string
bayesian?: {
ci_level?: number
}
diff --git a/posthog/schema.py b/posthog/schema.py
index d03e494c24e0..be99e67f888c 100644
--- a/posthog/schema.py
+++ b/posthog/schema.py
@@ -7128,6 +7128,13 @@ class ExperimentParameters(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
+ excluded_variants: list[str] | None = Field(
+ default=None,
+ description=(
+ "Variant keys to exclude from metric result calculations. Excluded variants"
+ " are still served to users but omitted from statistical analysis."
+ ),
+ )
feature_flag_variants: list[ExperimentVariant] | None = Field(
default=None,
description=(
@@ -22611,7 +22618,7 @@ class ExperimentHoldoutType(BaseModel):
created_by: UserBasicType | None = None
description: str | None = None
filters: list[FeatureFlagGroupType]
- id: float | None = None
+ id: int
name: str
updated_at: str | None = None
diff --git a/products/experiments/frontend/generated/api.schemas.ts b/products/experiments/frontend/generated/api.schemas.ts
index 83a634ab4967..9c26f9f33465 100644
--- a/products/experiments/frontend/generated/api.schemas.ts
+++ b/products/experiments/frontend/generated/api.schemas.ts
@@ -179,6 +179,8 @@ export interface ExperimentVariantApi {
}
export interface ExperimentParametersApi {
+ /** Variant keys to exclude from metric result calculations. Excluded variants are still served to users but omitted from statistical analysis. */
+ excluded_variants?: string[] | null
/** Experiment variants. If specified, must include a variant with key 'control' (lowercase). Defaults to a 50/50 control/test split when omitted. Minimum 2, maximum 20. */
feature_flag_variants?: ExperimentVariantApi[] | null
/** Minimum detectable effect as a percentage. Lower values need more users but catch smaller changes. Suggest 20–30% for most experiments. */
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index ae955959fce4..acb03b5ca5d9 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -16343,6 +16343,8 @@ export namespace Schemas {
}
export interface ExperimentParameters {
+ /** Variant keys to exclude from metric result calculations. Excluded variants are still served to users but omitted from statistical analysis. */
+ excluded_variants?: string[] | null;
/** Experiment variants. If specified, must include a variant with key 'control' (lowercase). Defaults to a 50/50 control/test split when omitted. Minimum 2, maximum 20. */
feature_flag_variants?: ExperimentVariant[] | null;
/** Minimum detectable effect as a percentage. Lower values need more users but catch smaller changes. Suggest 20–30% for most experiments. */
@@ -16590,7 +16592,7 @@ export namespace Schemas {
created_by?: UserBasicType | null;
description?: string | null;
filters: FeatureFlagGroupType[];
- id?: number | null;
+ id: number;
name: string;
updated_at?: string | null;
}
diff --git a/services/mcp/src/generated/experiments/api.ts b/services/mcp/src/generated/experiments/api.ts
index ea32bb0f850c..48b898b9ce79 100644
--- a/services/mcp/src/generated/experiments/api.ts
+++ b/services/mcp/src/generated/experiments/api.ts
@@ -159,6 +159,7 @@ export const experimentsCreateBodyNameMax = 400
export const experimentsCreateBodyDescriptionMax = 3000
+export const experimentsCreateBodyParametersOneExcludedVariantsDefault = null
export const experimentsCreateBodyParametersOneFeatureFlagVariantsOneItemNameDefault = null
export const experimentsCreateBodyParametersOneFeatureFlagVariantsOneItemRolloutPercentageDefault = null
export const experimentsCreateBodyParametersOneFeatureFlagVariantsOneItemSplitPercentDefault = null
@@ -415,6 +416,12 @@ export const ExperimentsCreateBody = /* @__PURE__ */ zod
parameters: zod
.union([
zod.object({
+ excluded_variants: zod
+ .union([zod.array(zod.string()), zod.null()])
+ .default(experimentsCreateBodyParametersOneExcludedVariantsDefault)
+ .describe(
+ 'Variant keys to exclude from metric result calculations. Excluded variants are still served to users but omitted from statistical analysis.'
+ ),
feature_flag_variants: zod
.union([
zod.array(
@@ -2846,6 +2853,7 @@ export const experimentsPartialUpdateBodyNameMax = 400
export const experimentsPartialUpdateBodyDescriptionMax = 3000
+export const experimentsPartialUpdateBodyParametersOneExcludedVariantsDefault = null
export const experimentsPartialUpdateBodyParametersOneFeatureFlagVariantsOneItemNameDefault = null
export const experimentsPartialUpdateBodyParametersOneFeatureFlagVariantsOneItemRolloutPercentageDefault = null
export const experimentsPartialUpdateBodyParametersOneFeatureFlagVariantsOneItemSplitPercentDefault = null
@@ -3104,6 +3112,12 @@ export const ExperimentsPartialUpdateBody = /* @__PURE__ */ zod
parameters: zod
.union([
zod.object({
+ excluded_variants: zod
+ .union([zod.array(zod.string()), zod.null()])
+ .default(experimentsPartialUpdateBodyParametersOneExcludedVariantsDefault)
+ .describe(
+ 'Variant keys to exclude from metric result calculations. Excluded variants are still served to users but omitted from statistical analysis.'
+ ),
feature_flag_variants: zod
.union([
zod.array(
@@ -5616,6 +5630,7 @@ export const experimentsDuplicateCreateBodyNameMax = 400
export const experimentsDuplicateCreateBodyDescriptionMax = 3000
+export const experimentsDuplicateCreateBodyParametersOneExcludedVariantsDefault = null
export const experimentsDuplicateCreateBodyParametersOneFeatureFlagVariantsOneItemNameDefault = null
export const experimentsDuplicateCreateBodyParametersOneFeatureFlagVariantsOneItemRolloutPercentageDefault = null
export const experimentsDuplicateCreateBodyParametersOneFeatureFlagVariantsOneItemSplitPercentDefault = null
@@ -5876,6 +5891,12 @@ export const ExperimentsDuplicateCreateBody = /* @__PURE__ */ zod
parameters: zod
.union([
zod.object({
+ excluded_variants: zod
+ .union([zod.array(zod.string()), zod.null()])
+ .default(experimentsDuplicateCreateBodyParametersOneExcludedVariantsDefault)
+ .describe(
+ 'Variant keys to exclude from metric result calculations. Excluded variants are still served to users but omitted from statistical analysis.'
+ ),
feature_flag_variants: zod
.union([
zod.array(
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/common/experiment-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/common/experiment-create.json
index c65663b2ba03..aba80621d19d 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/common/experiment-create.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/common/experiment-create.json
@@ -199,6 +199,21 @@
"anyOf": [
{
"properties": {
+ "excluded_variants": {
+ "anyOf": [
+ {
+ "items": {
+ "type": "string"
+ },
+ "type": "array"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Variant keys to exclude from metric result calculations. Excluded variants are still served to users but omitted from statistical analysis."
+ },
"feature_flag_variants": {
"anyOf": [
{
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/common/experiment-duplicate.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/common/experiment-duplicate.json
index 42253d7dffb9..f69405926162 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/common/experiment-duplicate.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/common/experiment-duplicate.json
@@ -3692,6 +3692,21 @@
"anyOf": [
{
"properties": {
+ "excluded_variants": {
+ "anyOf": [
+ {
+ "items": {
+ "type": "string"
+ },
+ "type": "array"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Variant keys to exclude from metric result calculations. Excluded variants are still served to users but omitted from statistical analysis."
+ },
"feature_flag_variants": {
"anyOf": [
{
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/common/experiment-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/common/experiment-update.json
index 6adadd336724..029a9103f8c3 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/common/experiment-update.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/common/experiment-update.json
@@ -3503,6 +3503,21 @@
"anyOf": [
{
"properties": {
+ "excluded_variants": {
+ "anyOf": [
+ {
+ "items": {
+ "type": "string"
+ },
+ "type": "array"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "Variant keys to exclude from metric result calculations. Excluded variants are still served to users but omitted from statistical analysis."
+ },
"feature_flag_variants": {
"anyOf": [
{