: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
feat(experiments): collapse long conclusion comments (#104397)
Juraj Majerik009dca5288b9
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex fe473dbde226..35b9d1457640 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -8392,6 +8392,10 @@ snapshots:hash: v1.k794b7964.3ac8e414429f924fc3def7d2208ac0beed9216521f2ffd06ca76ce75c2e57183.LwPKIQIMSb8WaQ5fDINLCxUtNV2z7WqIR0NcAp0Htw0scenes-app-experiments--experiment-stopped-with-conclusion--light:hash: v1.k794b7964.69fc0dfee79900b9fac203354b723622fa5799fc558b51472469e1c6a41ed7c5.k5g3uAXB81S1THaQCr-WvL40EL2eF86yLXwRbmLORno+ scenes-app-experiments--experiment-stopped-with-long-conclusion--dark:+ hash: v1.k794b7964.d9f67f619d391610a3730ebcc5ceefa8d8fdffde043f7eae9e8f56e1011bddfd.8YTbc5VRYqwQF1eEYApQPjB_7gdfUw2R8ERdQ6YQigc+ scenes-app-experiments--experiment-stopped-with-long-conclusion--light:+ hash: v1.k794b7964.2277c2dd0bd7e72257fc416e388f07c57494b6926f52674fd8ec1267df33805a.X_4SyykFZ8y4MJflo8pGDOs1iHRjAxnHOe2RYPUp2Ooscenes-app-experiments--experiment-watch-shelf-no-recordings--dark:hash: v1.k794b7964.bb5665d2af43df90803e28b9b6e4a1fc6dcfefd250a5d205956d6f5d53ec9dd1.Nc8TAC5gk9jVejy1uNyXDQLDxcH7RrM9AwCocsNthHgscenes-app-experiments--experiment-watch-shelf-no-recordings--light:diff --git a/frontend/src/scenes/experiments/ExperimentView/ConclusionComment.tsx b/frontend/src/scenes/experiments/ExperimentView/ConclusionComment.tsxnew file mode 100644index 000000000000..83c83362849c--- /dev/null+++ b/frontend/src/scenes/experiments/ExperimentView/ConclusionComment.tsx@@ -0,0 +1,53 @@+import clsx from 'clsx'+import { useLayoutEffect, useRef, useState } from 'react'++import { LemonButton } from '@posthog/lemon-ui'++export function ConclusionComment({ comment }: { comment: string }): JSX.Element {+ const [isExpanded, setIsExpanded] = useState(false)+ const [isOverflowing, setIsOverflowing] = useState(false)+ const textRef = useRef<HTMLParagraphElement>(null)++ useLayoutEffect(() => {+ if (isExpanded) {+ return+ }+ const element = textRef.current+ if (!element) {+ return+ }+ const checkOverflow = (): void => setIsOverflowing(element.scrollHeight > element.clientHeight + 1)+ checkOverflow()+ const observer = new ResizeObserver(checkOverflow)+ observer.observe(element)+ return () => observer.disconnect()+ }, [comment, isExpanded])++ return (+ <>+ <p+ ref={textRef}+ id="experiment-conclusion-comment-text"+ className={clsx(+ 'metric-cell font-normal m-0 mt-1 leading-relaxed whitespace-pre-wrap break-words',+ !isExpanded && 'max-h-36 overflow-hidden'+ )}+ >+ {comment}+ </p>+ {(isOverflowing || isExpanded) && (+ <LemonButton+ className="mt-1"+ size="xsmall"+ type="tertiary"+ data-attr="experiment-conclusion-toggle"+ aria-expanded={isExpanded}+ aria-controls="experiment-conclusion-comment-text"+ onClick={() => setIsExpanded(!isExpanded)}+ >+ {isExpanded ? 'Show less' : 'Show more'}+ </LemonButton>+ )}+ </>+ )+}diff --git a/frontend/src/scenes/experiments/ExperimentView/Info.tsx b/frontend/src/scenes/experiments/ExperimentView/Info.tsxindex 8f4a7b0c5783..4ace9676144d 100644--- a/frontend/src/scenes/experiments/ExperimentView/Info.tsx+++ b/frontend/src/scenes/experiments/ExperimentView/Info.tsx@@ -17,6 +17,7 @@ import { getExperimentStatus, isExperimentPaused } from 'products/experiments/frimport { experimentLogic } from '../experimentLogic'import { modalsLogic } from '../modalsLogic'+import { ConclusionComment } from './ConclusionComment'import { ExperimentDuration } from './ExperimentDuration'import { ExperimentReloadActionContainer } from './ExperimentReloadActionContainer'import { flagCleanupTaskLogic } from './flagCleanupTaskLogic'@@ -251,9 +252,7 @@ export function Info(): JSX.Element {{CONCLUSION_DISPLAY_CONFIG[experiment.conclusion]?.title || experiment.conclusion}</span></div>- <p className="metric-cell font-normal m-0 mt-1 leading-relaxed whitespace-pre-wrap break-words">- {experiment.conclusion_comment}- </p>+ <ConclusionComment comment={experiment.conclusion_comment} /></LemonCard>)}</>diff --git a/frontend/src/scenes/experiments/stories/ExperimentStoppedWithLongConclusion.stories.tsx b/frontend/src/scenes/experiments/stories/ExperimentStoppedWithLongConclusion.stories.tsxnew file mode 100644index 000000000000..d82027fae7d0--- /dev/null+++ b/frontend/src/scenes/experiments/stories/ExperimentStoppedWithLongConclusion.stories.tsx@@ -0,0 +1,81 @@+import { Meta, StoryObj } from '@storybook/react'++import { App } from 'scenes/App'+import { urls } from 'scenes/urls'++import { mswDecorator } from '~/mocks/browser'+import EXPERIMENT_WITH_FUNNEL_METRIC from '~/mocks/fixtures/api/experiments/experiment_with_funnel_metric.json'+import EXPOSURE_QUERY_RESULT from '~/mocks/fixtures/api/experiments/exposure_query_result.json'+import FUNNELS_METRIC_RESULT from '~/mocks/fixtures/api/experiments/funnel_metric_result.json'+import { NodeKind } from '~/queries/schema/schema-general'++const LONG_CONCLUSION_COMMENT = [+ 'We shipped the test variant on qualitative feedback rather than on a measured lift.',+ 'The primary metric moved by a small amount that never reached significance, and the secondary metrics disagreed with each other about the direction of the effect.',+ 'The signup metric favored the variant while the activation metric favored control, which points to sampling noise rather than a real effect.',+ 'The test reached its planned sample size, but that sample size only resolves large relative effects, and copy changes of this kind rarely move the metric that much.',+ 'Resolving the observed gap would need several months of traffic at current volumes, which is longer than the team is willing to wait for a headline change.',+ 'For the next test we plan to use a metric closer to the surface being changed, run fewer variants so each one gets more traffic, and vary the page structure rather than the wording alone.',+ 'We also plan to set the horizon up front and stick to it, since the current test was monitored daily under a fixed-horizon configuration.',+ 'The exposure counts were balanced across variants and the sample ratio check passed, so the assignment mechanism itself is not in question.',+ 'A small share of users saw more than one variant, which is expected with anonymous bucketing on a logged-out page and biases the result toward null.',+ 'The number of secondary metrics also inflated the false positive risk, since dozens of comparisons at the default threshold are expected to produce a few significant results by chance alone.',+ 'Future tests on this surface should cut the secondary metric list down to the few that can plausibly move, and treat the rest as debugging context rather than decision inputs.',+ 'The flag was left at its final rollout state, the release conditions were preserved, and no cleanup was performed as part of ending the experiment.',+ 'Overall the test produced a useful negative result: it rules out large effects from wording changes alone and sharpens the design of the next iteration.',+].join(' ')++const EXPERIMENT_STOPPED_WITH_LONG_CONCLUSION = {+ ...EXPERIMENT_WITH_FUNNEL_METRIC,+ end_date: '2025-01-20T14:39:00Z',+ conclusion: 'stopped_early',+ conclusion_comment: LONG_CONCLUSION_COMMENT,+}++const meta: Meta = {+ component: App,+ title: 'Scenes-App/Experiments',+ parameters: {+ layout: 'fullscreen',+ viewMode: 'story',+ mockDate: '2025-01-27',+ pageUrl: urls.experiment(EXPERIMENT_STOPPED_WITH_LONG_CONCLUSION.id),+ testOptions: {+ // The funnel chart only renders once the metric result AND the exposure query have+ // both resolved. The loader wait covers the metric table alone, so wait for the chart+ // itself to avoid snapshotting before it appears.+ waitForSelector: '[data-attr="experiment-funnel-chart"]',+ },+ },+ decorators: [+ mswDecorator({+ get: {+ [`/api/projects/:team_id/experiments/${EXPERIMENT_STOPPED_WITH_LONG_CONCLUSION.id}/`]:+ EXPERIMENT_STOPPED_WITH_LONG_CONCLUSION,+ [`/api/projects/:team_id/experiment_holdouts`]: [],+ [`/api/projects/:team_id/experiment_saved_metrics/`]: [],+ [`/api/projects/:team_id/feature_flags/${EXPERIMENT_STOPPED_WITH_LONG_CONCLUSION.feature_flag.id}/`]:+ {},+ [`/api/projects/:team_id/feature_flags/${EXPERIMENT_STOPPED_WITH_LONG_CONCLUSION.feature_flag.id}/status/`]:+ {},+ [`/api/environments/:team_id/default_release_conditions/`]: [],+ },+ post: {+ '/api/environments/:team_id/query/:kind': async ({ request }) => {+ const body = (await request.json()) as Record<string, any>++ if (body.query.kind === NodeKind.ExperimentExposureQuery) {+ return [200, EXPOSURE_QUERY_RESULT]+ }++ return [200, FUNNELS_METRIC_RESULT]+ },+ },+ }),+ ],+}+export default meta++type Story = StoryObj<{}>++export const ExperimentStoppedWithLongConclusion: Story = {}