: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(replay-vision): show each variant while it waits for observations (#112839)
Kim Svatos Dugan2c0f46a2c98c
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 4d146ff5c5aa..584bdee65062 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -12899,13 +12899,17 @@ snapshots:scenes-app-replay-vision--experiment-variants-narrow--light:hash: v1.k794b7964.d9b0d4963eec714e16f057dfce9da13967974d4f900a882c4514c0f0c4053300.cGii9EDM-C2IiXcOO7y6aWPa4ey12Fe-DopaDhYsnMsscenes-app-replay-vision--experiment-variants-no-scout--dark:- hash: v1.k794b7964.a2043e06f871b55bb7eac56ce3ed2aa40decfeef870b556e669c4ce9cd3e498f.zzQwT1srKV5UWr86OsGcTjd5MIeCD37Ev6dTw1Te1-Y+ hash: v1.k794b7964.a8f0a51439fee34a91831b134240afc0d9839254d83c8fea9757f1b6c7c12a36.DX9DFGPNfnL6HGYWKpcHKP8TTYuLTpP4QWhhKUhiF0Uscenes-app-replay-vision--experiment-variants-no-scout--light:- hash: v1.k794b7964.9cb9742e367806b211fd126e3107c16fcd94308ce294a7d18b0accd5192c787f.j8RY_0ieCIyQWiTz1HjFEysl1gglkbRMgvymaB_kfUw+ hash: v1.k794b7964.5a89953d1d09a9ecefa4138a8bdb3e1a39944849b6280eec875391963d2ab0d4.AGZHAbYj7jJB7zQutEqrFxOntxz5fyOlnDeVKCI76mIscenes-app-replay-vision--experiment-variants-three-variants--dark:hash: v1.k794b7964.3a46d1be73932a767101335f2aa8962256f0209e7d4f20ac040e5d37e3f1e757.4XaHTLpO3eNIe6PbsJU89RNYNIPpel0Hx3OxP0k7lpcscenes-app-replay-vision--experiment-variants-three-variants--light:hash: v1.k794b7964.ba095eb635c4246983dbbc471b0973fbd042f9daad6a970f4d66d78bb6dc020d.UxdaUdzmSBJrAOH1g5VQmT1HOxLt6b8cvMaSdx2CSZc+ scenes-app-replay-vision--experiment-variants-waiting-for-observations--dark:+ hash: v1.k794b7964.0056b7d379418048419e1af4fe26b3dedb57db977d907a994c35dfbb961c85c6.LZbOuzh4Jc8rJ_fNBfvGocKs0Cx7bOqjXlQ8F_XFJa8+ scenes-app-replay-vision--experiment-variants-waiting-for-observations--light:+ hash: v1.k794b7964.a1555dab4c0006028e8c240451c56c6aed5e31c8a8e68c893e3d6a07b562bba6.VYeYPsjZ_p0Rt4cbZzF7lbxjxurMjLXff9kJRsy49gUscenes-app-replay-vision--home-watch-feed--dark:hash: v1.k794b7964.4e49c04cab295c8244570e27b42dd6d08712914dfb46c071e8d58cf97e05ca22.j0LdxNaQxcSLZggc0YaC6ZMGaRSWCAHeIz8Pu4EN9e0scenes-app-replay-vision--home-watch-feed--light:diff --git a/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.stories.tsx b/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.stories.tsxindex 8a9e29463f4e..8d01022c6a59 100644--- a/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.stories.tsx+++ b/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.stories.tsx@@ -2156,6 +2156,33 @@ export const ExperimentVariantsFirstRunPending: StoryObj = {],}+// Before the first observation: each variant shows where its themes and observations will go.+export const ExperimentVariantsWaitingForObservations: StoryObj = {+ parameters: {+ pageUrl: urls.replayVision(experimentScanner.id),+ featureFlags: { [FEATURE_FLAGS.VISION_EXPERIMENT_SCANNER]: true },+ },+ decorators: [+ variantsDecorator(+ withoutAnalysis(+ variantsReadout({+ analysis: { ...readyAnalysis, recorded_at: null },+ window: { total_observations: 0, first_observation_at: null, last_observation_at: null },+ unattributed_count: 0,+ variants: variantsReadout().variants.map((variant) => ({+ ...variant,+ observations: 0,+ distinct_people: 0,+ median_session_duration_s: null,+ sampling_rate: null,+ latest_observations: [],+ })),+ })+ )+ ),+ ],+}+export const ExperimentVariantsThreeVariants: StoryObj = {parameters: {pageUrl: urls.replayVision(experimentScanner.id),diff --git a/products/replay_vision/frontend/replay_scanners/components/ScannerObservationsTable.tsx b/products/replay_vision/frontend/replay_scanners/components/ScannerObservationsTable.tsxindex 9abd0977c160..3f3254804ca1 100644--- a/products/replay_vision/frontend/replay_scanners/components/ScannerObservationsTable.tsx+++ b/products/replay_vision/frontend/replay_scanners/components/ScannerObservationsTable.tsx@@ -2,12 +2,22 @@ import { useActions, useValues } from 'kea'import { useEffect } from 'react'import { IconCopy, IconEye, IconPlay, IconRefresh, IconSearch, IconX } from '@posthog/icons'-import { LemonButton, LemonInput, LemonTable, LemonTag, LemonTagType, Link, Tooltip } from '@posthog/lemon-ui'+import {+ LemonButton,+ LemonInput,+ LemonSelect,+ LemonTable,+ LemonTag,+ LemonTagType,+ Link,+ Tooltip,+} from '@posthog/lemon-ui'import { DateFilter } from 'lib/components/DateFilter/DateFilter'import { CUSTOM_OPTION_KEY } from 'lib/components/DateFilter/types'import { TZLabel } from 'lib/components/TZLabel'import { LemonTableColumns } from 'lib/lemon-ui/LemonTable'+import { getExperimentVariants } from 'scenes/experiments/utils'import { urls } from 'scenes/urls'import { DateMappingOption } from '~/types'@@ -32,7 +42,7 @@ import {ObservationVerdictValue,replayScannerLogic,} from '../replayScannerLogic'-import { UNATTRIBUTED_VARIANT } from '../scannerVariantsLogic'+import { UNATTRIBUTED_VARIANT, variantFilterOptions } from '../scannerVariantsLogic'import { OBSERVATION_TRIGGER_TAG, unsuccessfulScanReason } from '../types'import { ObservationRowResult } from './ObservationRowResult'@@ -108,6 +118,7 @@ export function ScannerObservationsTable({ scannerId }: { scannerId: string }):observationDateTo,observationBackfillFilter,observationVariantFilter,+ experimentContext,hasActiveObservationFilters,observationDetailLinkParams,availableTags,@@ -411,22 +422,44 @@ export function ScannerObservationsTable({ scannerId }: { scannerId: string }):Backfill {shortBackfillId(observationBackfillFilter)}</LemonButton>)}- {observationVariantFilter && (- // Arrives from the Variants tab, so like the backfill filter it only clears.- <LemonButton- type="secondary"+ {scannerType === 'experiment' ? (+ <LemonSelectsize="small"- sideAction={{- icon: <IconX />,- onClick: () => setObservationVariantFilter(null),- tooltip: 'Clear variant filter',- }}+ dropdownMatchSelectWidth={false}+ value={observationVariantFilter}+ onChange={(value) => setObservationVariantFilter(value)}+ options={variantFilterOptions(+ scanner?.scanner_type === 'experiment' &&+ scanner.scanner_config.variants?.length+ ? scanner.scanner_config.variants+ : getExperimentVariants(experimentContext?.experiment).map(+ (variant) => variant.key+ ),+ observationVariantFilter+ )}+ renderButtonContent={(leaf) =>+ leaf?.value == null ? 'All variants' : `Variant: ${leaf.label}`+ }data-attr="vision-observations-variant-filter"- >- {observationVariantFilter === UNATTRIBUTED_VARIANT- ? 'No variant'- : `Variant: ${observationVariantFilter}`}- </LemonButton>+ />+ ) : (+ observationVariantFilter && (+ // Arrives from the Variants tab, so like the backfill filter it only clears.+ <LemonButton+ type="secondary"+ size="small"+ sideAction={{+ icon: <IconX />,+ onClick: () => setObservationVariantFilter(null),+ tooltip: 'Clear variant filter',+ }}+ data-attr="vision-observations-variant-filter"+ >+ {observationVariantFilter === UNATTRIBUTED_VARIANT+ ? 'No variant'+ : `Variant: ${observationVariantFilter}`}+ </LemonButton>+ ))}<LemonButtontype="tertiary"diff --git a/products/replay_vision/frontend/replay_scanners/components/variants/VariantCard.tsx b/products/replay_vision/frontend/replay_scanners/components/variants/VariantCard.tsxindex bc8c471c7046..412e8cf06b74 100644--- a/products/replay_vision/frontend/replay_scanners/components/variants/VariantCard.tsx+++ b/products/replay_vision/frontend/replay_scanners/components/variants/VariantCard.tsx@@ -1,3 +1,4 @@+import { IconClock } from '@posthog/icons'import { LemonCard } from '@posthog/lemon-ui'import { Link } from 'lib/lemon-ui/Link'@@ -15,6 +16,8 @@ export interface VariantCardProps {color: string/** Whether the scanner samples variants evenly, which makes counts follow sampling, not traffic. */balanced: boolean+ /** Shown in the Themes section while no variant analysis scout runs, so the section says how to fill it. */+ themesHint: string | nullobservationsUrl: stringonOpenObservations: () => void}@@ -24,27 +27,43 @@ export function VariantCard({variant,color,balanced,+ themesHint,observationsUrl,onOpenObservations,}: VariantCardProps): JSX.Element {- const stats = [- pluralize(variant.observations, 'observation'),- pluralize(variant.distinct_people, 'person', 'people'),- variant.median_session_duration_s != null- ? `median session ${humanFriendlyDuration(variant.median_session_duration_s)}`- : null,- ].filter(Boolean)+ const waiting = variant.observations === 0+ const stats = waiting+ ? [pluralize(0, 'observation')]+ : [+ pluralize(variant.observations, 'observation'),+ pluralize(variant.distinct_people, 'person', 'people'),+ variant.median_session_duration_s != null+ ? `median session ${humanFriendlyDuration(variant.median_session_duration_s)}`+ : null,+ ].filter(Boolean)+ const header = (+ <div className="flex flex-wrap items-center justify-between gap-x-3 gap-y-1 border-b px-4 py-3">+ <span className="flex min-w-0 items-center gap-2">+ {/* The color comes from the variant's series index, so it can't be a Tailwind class. */}+ <span className="inline-block size-2.5 shrink-0 rounded-sm" style={{ backgroundColor: color }} />+ <span className="truncate font-semibold">{variant.key}</span>+ </span>+ <span className="text-xs text-muted">{stats.join(' · ')}</span>+ </div>+ )++ if (waiting) {+ return (+ <LemonCard hoverEffect={false} className="p-0 flex flex-col" data-attr="vision-variant-card">+ {header}+ <WaitingForObservations themesHint={themesHint} />+ </LemonCard>+ )+ }return (<LemonCard hoverEffect={false} className="p-0 flex flex-col" data-attr="vision-variant-card">- <div className="flex flex-wrap items-center justify-between gap-x-3 gap-y-1 border-b px-4 py-3">- <span className="flex min-w-0 items-center gap-2">- {/* The color comes from the variant's series index, so it can't be a Tailwind class. */}- <span className="inline-block size-2.5 shrink-0 rounded-sm" style={{ backgroundColor: color }} />- <span className="truncate font-semibold">{variant.key}</span>- </span>- <span className="text-xs text-muted">{stats.join(' · ')}</span>- </div>+ {header}{variant.sampling_rate != null && (<div className="px-4 pt-3 text-xs text-muted">@@ -62,6 +81,13 @@ export function VariantCard({</div>)}+ {themesHint && !variant.digest?.length && (+ <div className="px-4 pt-3 space-y-1.5">+ <div className="text-xs font-semibold uppercase text-muted">Themes</div>+ <p className="m-0 text-sm text-muted">{themesHint}</p>+ </div>+ )}+{variant.digest && variant.digest.length > 0 && (<div className="px-4 pt-3 space-y-1.5"><div className="text-xs font-semibold uppercase text-muted">Themes</div>@@ -122,3 +148,42 @@ export function VariantCard({</LemonCard>)}++/** The variant's themes and latest observations, laid out empty until the scanner has some. */+function WaitingForObservations({ themesHint }: { themesHint: string | null }): JSX.Element {+ const placeholderLine = 'h-2.5 rounded bg-surface-secondary'+ return (+ <div className="flex flex-col gap-4 p-4" data-attr="vision-variant-waiting">+ <div className="rounded border border-dashed p-3 text-center text-sm text-muted">+ <div className="flex items-center justify-center gap-1.5 font-semibold text-default">+ <IconClock className="text-muted" />+ Waiting for observations+ </div>+ <div>Summaries of exposed sessions in this variant show here as they arrive.</div>+ </div>+ <div className="space-y-2">+ <div className="text-xs font-semibold uppercase text-muted">Themes</div>+ {themesHint ? (+ <p className="m-0 text-sm text-muted">{themesHint}</p>+ ) : (+ <>+ <div className={`${placeholderLine} w-3/4`} />+ <div className={`${placeholderLine} w-3/5`} />+ </>+ )}+ </div>+ <div className="space-y-3">+ <div className="text-xs font-semibold uppercase text-muted">Latest observations</div>+ {['w-1/2', 'w-2/5'].map((titleWidth) => (+ <div key={titleWidth} className="flex items-start gap-2.5">+ <div className="h-10 w-16 shrink-0 rounded bg-surface-secondary" />+ <div className="flex-1 space-y-2 pt-1">+ <div className={`${placeholderLine} ${titleWidth}`} />+ <div className={`${placeholderLine} w-4/5`} />+ </div>+ </div>+ ))}+ </div>+ </div>+ )+}diff --git a/products/replay_vision/frontend/replay_scanners/components/variants/VariantsTab.tsx b/products/replay_vision/frontend/replay_scanners/components/variants/VariantsTab.tsxindex 8a3254ed9ecc..d1a697f24776 100644--- a/products/replay_vision/frontend/replay_scanners/components/variants/VariantsTab.tsx+++ b/products/replay_vision/frontend/replay_scanners/components/variants/VariantsTab.tsx@@ -56,6 +56,13 @@ export function VariantsTab({ scannerId }: VariantsTabProps): JSX.Element {const existingScout = variantAnalysisScout(scoutConfigsForScanner)const comparisonState = variantComparisonState(readout.analysis, !!existingScout)const balanced = scanner?.scanner_type !== 'experiment' || scanner.scanner_config.balance_variants !== false+ // Themes come from the variant analysis scout, so without a running one each card says how to get them.+ const themesHint =+ comparisonState === 'no_scout'+ ? 'Set up variant analysis above to see themes here.'+ : readout.analysis?.scout_enabled === false || existingScout?.enabled === false+ ? 'Variant analysis is paused. Turn it on in the scout settings above to see themes here.'+ : nullreturn (<div className="@container flex flex-col gap-4" data-attr="vision-variants-tab">@@ -70,7 +77,9 @@ export function VariantsTab({ scannerId }: VariantsTabProps): JSX.Element {}}onOpenScout={existingScout ? () => openScoutSettings(existingScout.skill_name) : undefined}/>- {readout.window.total_observations === 0 ? (+ {/* Each watched variant gets a card from the start; the readout lists none only when the+ experiment can't be read, for example after it was deleted. */}+ {readout.variants.length === 0 ? (<LemonCard hoverEffect={false} className="p-4 text-sm text-muted">No observations yet. The scanner summarizes sessions of exposed people as they arrive, and eachvariant shows here once it has some.@@ -89,6 +98,7 @@ export function VariantsTab({ scannerId }: VariantsTabProps): JSX.Element {variant={variant}color={variantColors[variant.key]}balanced={balanced}+ themesHint={themesHint}observationsUrl={variantObservationsUrl(scannerId, variant.key)}onOpenObservations={() => variantObservationsOpened(variant.key)}/>diff --git a/products/replay_vision/frontend/replay_scanners/scannerVariantsLogic.test.ts b/products/replay_vision/frontend/replay_scanners/scannerVariantsLogic.test.tsindex f790d81d92d8..38f131773446 100644--- a/products/replay_vision/frontend/replay_scanners/scannerVariantsLogic.test.ts+++ b/products/replay_vision/frontend/replay_scanners/scannerVariantsLogic.test.ts@@ -9,6 +9,7 @@ import {UNATTRIBUTED_VARIANT,scannerVariantsLogic,variantComparisonState,+ variantFilterOptions,variantObservationsUrl,} from './scannerVariantsLogic'@@ -54,6 +55,17 @@ describe('scannerVariantsLogic', () => {expect(params.get('status')).toBe(expectedStatus)})+ // A link or an old URL can name a variant the experiment no longer lists, and the always-on filter+ // must still show it as selected instead of an empty dropdown.+ it.each([+ ['every variant', null, [null, 'control', 'test', UNATTRIBUTED_VARIANT]],+ ['a listed variant', 'test', [null, 'control', 'test', UNATTRIBUTED_VARIANT]],+ ['a variant not in the list', 'old-arm', [null, 'control', 'test', 'old-arm', UNATTRIBUTED_VARIANT]],+ ['no variant', UNATTRIBUTED_VARIANT, [null, 'control', 'test', UNATTRIBUTED_VARIANT]],+ ])('offers %s in the variant filter', (_name, current, expected) => {+ expect(variantFilterOptions(['control', 'test'], current).map((option) => option.value)).toEqual(expected)+ })+it('reports one tab view per mount, not one per reload', async () => {useMocks({ get: { '/api/projects/:team/vision/scanners/:id/variants/': () => [200, readout] } })initKeaTests()diff --git a/products/replay_vision/frontend/replay_scanners/scannerVariantsLogic.ts b/products/replay_vision/frontend/replay_scanners/scannerVariantsLogic.tsindex f040de96ccb6..9caf499eed52 100644--- a/products/replay_vision/frontend/replay_scanners/scannerVariantsLogic.ts+++ b/products/replay_vision/frontend/replay_scanners/scannerVariantsLogic.ts@@ -50,6 +50,25 @@ export function variantObservationsUrl(scannerId: string, variantKey: string): s}).url}+/**+ * The Observations tab's variant filter choices: every variant, each watched variant, and observations+ * with no variant. A key from the URL that is not in the list stays selectable, so the filter keeps showing it.+ */+export function variantFilterOptions(+ variantKeys: string[],+ current: string | null+): { value: string | null; label: string }[] {+ const keys =+ current && current !== UNATTRIBUTED_VARIANT && !variantKeys.includes(current)+ ? [...variantKeys, current]+ : variantKeys+ return [+ { value: null, label: 'All variants' },+ ...keys.map((key) => ({ value: key, label: key })),+ { value: UNATTRIBUTED_VARIANT, label: 'No variant' },+ ]+}+export interface ScannerVariantsLogicProps {scannerId: string}