: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
fix(experiments): hide AI analysis tab for drafts and metric-less experiments (#72552)
Juraj Majerik05d6a581b363
diff --git a/frontend/src/scenes/experiments/ExperimentView/ExperimentView.tsx b/frontend/src/scenes/experiments/ExperimentView/ExperimentView.tsxindex 75f7ad3a8de4..154c043be258 100644--- a/frontend/src/scenes/experiments/ExperimentView/ExperimentView.tsx+++ b/frontend/src/scenes/experiments/ExperimentView/ExperimentView.tsx@@ -1,7 +1,7 @@import { useActions, useValues } from 'kea'import { IconSparkles } from '@posthog/icons'-import { LemonTabs } from '@posthog/lemon-ui'+import { LemonTab, LemonTabs } from '@posthog/lemon-ui'import { ActivityLog } from 'lib/components/ActivityLog/ActivityLog'import { FEATURE_FLAGS } from 'lib/constants'@@ -130,8 +130,16 @@ const VariantsTab = (): JSX.Element => {}export function ExperimentView(): JSX.Element {- const { experimentLoading, experimentId, experiment, isExperimentDraft, exposureCriteria, showDebugPanel } =- useValues(experimentLogic)+ const {+ experimentLoading,+ experimentId,+ experiment,+ isExperimentDraft,+ isExperimentLaunched,+ orderedPrimaryMetricsWithResults,+ exposureCriteria,+ showDebugPanel,+ } = useValues(experimentLogic)const { featureFlags } = useValues(featureFlagLogic)const {setExperiment,@@ -154,6 +162,71 @@ export function ExperimentView(): JSX.Element {return <LegacyExperimentView />}+ const tabs: LemonTab<string>[] = [+ {+ key: 'settings',+ label: 'Settings',+ content: <SettingsTab />,+ },+ {+ key: 'metrics',+ label: 'Metrics',+ content: <MetricsTab />,+ },+ // Both AI analysis actions require a launched experiment with primary metrics+ ...(isExperimentLaunched && orderedPrimaryMetricsWithResults.length > 0+ ? [+ {+ key: 'ai_analysis',+ label: (+ <div className="flex items-center gap-1">+ <IconSparkles />+ <span>AI analysis</span>+ </div>+ ),+ content: <AiAnalysisTab />,+ },+ ]+ : []),+ ...(featureFlags[FEATURE_FLAGS.EXPERIMENT_RECORDINGS_TAB]+ ? [+ {+ key: 'recordings',+ label: 'Recordings',+ content: <ExperimentReplayTab experiment={experiment} />,+ },+ ]+ : []),+ ...(!isExperimentDraft+ ? [+ {+ key: 'code',+ label: 'Code',+ content: <CodeTab />,+ },+ ]+ : []),+ {+ key: 'variants',+ label: 'Variants',+ content: <VariantsTab />,+ },+ {+ key: 'history',+ label: 'History',+ content: <ActivityLog scope={ActivityScope.EXPERIMENT} id={experimentId} />,+ },+ ...(experiment.feature_flag+ ? [+ {+ key: 'feedback',+ label: 'User feedback',+ content: <ExperimentFeedbackTab experiment={experiment} />,+ },+ ]+ : []),+ ]+return (<SceneContent><PageHeaderCustom />@@ -179,68 +252,11 @@ export function ExperimentView(): JSX.Element {<Info /><ExperimentHeader /><LemonTabs- activeKey={activeTabKey}+ // Fall back to the default tab if the active one is conditionally hidden+ activeKey={tabs.some((tab) => tab.key === activeTabKey) ? activeTabKey : 'metrics'}onChange={(key) => setActiveTabKey(key)}sceneInset- tabs={[- {- key: 'settings',- label: 'Settings',- content: <SettingsTab />,- },- {- key: 'metrics',- label: 'Metrics',- content: <MetricsTab />,- },- {- key: 'ai_analysis',- label: (- <div className="flex items-center gap-1">- <IconSparkles />- <span>AI analysis</span>- </div>- ),- content: <AiAnalysisTab />,- },- ...(featureFlags[FEATURE_FLAGS.EXPERIMENT_RECORDINGS_TAB]- ? [- {- key: 'recordings',- label: 'Recordings',- content: <ExperimentReplayTab experiment={experiment} />,- },- ]- : []),- ...(!isExperimentDraft- ? [- {- key: 'code',- label: 'Code',- content: <CodeTab />,- },- ]- : []),- {- key: 'variants',- label: 'Variants',- content: <VariantsTab />,- },- {- key: 'history',- label: 'History',- content: <ActivityLog scope={ActivityScope.EXPERIMENT} id={experimentId} />,- },- ...(experiment.feature_flag- ? [- {- key: 'feedback',- label: 'User feedback',- content: <ExperimentFeedbackTab experiment={experiment} />,- },- ]- : []),- ]}+ tabs={tabs}/>{/* Modern experiment modals */}