: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 the experiment in an experiment scanner's filters (#112840)
Kim Svatos Dugan20c5d4b984c6
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 1bb1a0cc81c9..50181758d223 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -12902,6 +12902,10 @@ snapshots:hash: v1.k794b7964.5bc5dc77d7346163d92585657a949d38938bdbabf11a2a0341bc3a6b9c980c80.AL7y75QUTSwtUvG6XKJvD4CPhbEXC4TmNPkxG_57CQ4scenes-app-replay-vision--scanner-editor-triggers--light:hash: v1.k794b7964.1325a276c040c4fdec27fd9d75ecde45e08d343f4e76806a03819747f4c52973.6k8EbsIyUMKtWUuUvV-ElrJCGK5_-iSXLT4bi_fp3Gg+ scenes-app-replay-vision--scanner-editor-triggers-experiment--dark:+ hash: v1.k794b7964.f7fdb75ee7ffb08c6b9789370c08b88a689d8f407c952b2effd9d7ffde95d028.XXeZtWm_JlbZGIq9AxBDrutJnks_dHQLn06IEV81-QU+ scenes-app-replay-vision--scanner-editor-triggers-experiment--light:+ hash: v1.k794b7964.4c9b6d30e5bb460f6bd2d4fbc0dc6d159f09b463f17984f7c90c862148ad8035.C01RrFZ0PWHr4CxiMHObWY9k51ZmW5AvpbnGcpmgTzoscenes-app-replay-vision--scanner-observations--dark:hash: v1.k794b7964.a730efb9cf4a682d5618dd924bcc733bdb602478dc338e1511ab0eb1e5fc580a.HMSJ-jDOOMyzClRBvAXqP4EdZDWu_oNBrvObUQPQT3Ascenes-app-replay-vision--scanner-observations--light:diff --git a/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.stories.tsx b/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.stories.tsxindex c2692aea6a1f..ba840a7da9aa 100644--- a/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.stories.tsx+++ b/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.stories.tsx@@ -1807,6 +1807,16 @@ export const ScannerEditorTriggers: StoryObj = {parameters: { pageUrl: urls.replayVisionScannerTriggers(summarizerScanner.id) },}+// The experiment shows as the first condition of the filters, so a scanner with no filters of its own+// does not read as scanning every recording.+export const ScannerEditorTriggersExperiment: StoryObj = {+ parameters: {+ pageUrl: urls.replayVisionScannerTriggers(experimentScanner.id),+ featureFlags: { [FEATURE_FLAGS.VISION_EXPERIMENT_SCANNER]: true },+ },+ decorators: [variantsDecorator(variantsReadout())],+}+export const ScannerEditorBudget: StoryObj = {parameters: { pageUrl: urls.replayVisionScannerBudget(summarizerScanner.id) },}diff --git a/products/replay_vision/frontend/replay_scanners/components/ExperimentScopeFilter.tsx b/products/replay_vision/frontend/replay_scanners/components/ExperimentScopeFilter.tsxnew file mode 100644index 000000000000..2d602d753320--- /dev/null+++ b/products/replay_vision/frontend/replay_scanners/components/ExperimentScopeFilter.tsx@@ -0,0 +1,54 @@+import { useValues } from 'kea'++import { IconFlask } from '@posthog/icons'+import { LemonTag } from '@posthog/lemon-ui'++import { Link } from 'lib/lemon-ui/Link'+import { urls } from 'scenes/urls'++import { scannerExperimentScope, scopeVariantsLabel } from '../experimentTargeting'+import { replayScannerLogic } from '../replayScannerLogic'++export interface ExperimentScopeFilterProps {+ scannerId: string+}++/**+ * The experiment an experiment scanner watches, shown as the first condition of its recording filters.+ * The backend applies it at scan time, so it is not a filter the user can edit here.+ */+export function ExperimentScopeFilter({ scannerId }: ExperimentScopeFilterProps): JSX.Element | null {+ const { scanner, experimentContext } = useValues(replayScannerLogic({ id: scannerId }))+ const scope = scanner?.scanner_type === 'experiment' ? scannerExperimentScope(scanner) : null+ if (!scope) {+ return null+ }+ const experiment = experimentContext?.experiment.id === scope.experimentId ? experimentContext.experiment : null++ return (+ <div+ className="space-y-1.5 rounded border border-accent bg-accent-highlight-secondary p-3"+ data-attr="vision-experiment-scope-filter"+ >+ <div className="flex flex-wrap items-center gap-2">+ <IconFlask className="shrink-0 text-lg text-accent" />+ <span className="text-sm font-semibold">+ People exposed to{' '}+ {experiment ? (+ <Link to={urls.experiment(scope.experimentId)}>{experiment.name}</Link>+ ) : (+ 'this experiment'+ )}+ </span>+ <LemonTag type="highlight">{scopeVariantsLabel(scope, 'every variant')}</LemonTag>+ <LemonTag type="muted">Always applied</LemonTag>+ </div>+ <div className="text-xs text-muted">+ This includes every session they have after their first exposure until the experiment ends, even+ sessions that never reach the part of the product the experiment changes. To scan only sessions that+ visit a certain page or flow, add a filter below, for example{' '}+ <strong className="text-default">Visited page</strong>.+ </div>+ </div>+ )+}diff --git a/products/replay_vision/frontend/replay_scanners/components/ScannerTriggers.tsx b/products/replay_vision/frontend/replay_scanners/components/ScannerTriggers.tsxindex 450a522891b4..9a7e17fdfa7d 100644--- a/products/replay_vision/frontend/replay_scanners/components/ScannerTriggers.tsx+++ b/products/replay_vision/frontend/replay_scanners/components/ScannerTriggers.tsx@@ -32,7 +32,9 @@ import { RecordingsQuery } from '~/queries/schema/schema-general'import { PropertyFilterType, RecordingUniversalFilters, UniversalFiltersGroup } from '~/types'import { clampDurationFilter, durationFilterError, MAX_ACTIVE_LABEL } from '../durationBounds'+import { scannerExperimentScope } from '../experimentTargeting'import { replayScannerLogic } from '../replayScannerLogic'+import { ExperimentScopeFilter } from './ExperimentScopeFilter'// The wizard holds an unsaved draft, so sending someone to the settings scene to define their test// account filters drops them out of the flow they were told to fix. Configure them in place instead.@@ -117,35 +119,22 @@ function ScannerFilterGroup(): JSX.Element {)}-// The experiment population, which the backend derives from exposure data at scan time, so there is-// no filter in the card below to hand-edit. The experiment type picks it in its configuration step.-// Legacy targeting on other types is read-only: the API refuses a new target but accepts a clear.+// Legacy experiment targeting on other scanner types. The backend derives the population from+// exposure data at scan time, so there is no filter in the card below to hand-edit. It is read-only:+// the API refuses a new target but accepts a clear. The experiment type shows its experiment inside+// the filters card instead.function ExperimentTargeting({ scannerId }: { scannerId: string }): JSX.Element | null {const { scanner, experimentContext } = useValues(replayScannerLogic({ id: scannerId }))const { setExperimentVariant, detachExperimentContext } = useActions(replayScannerLogic({ id: scannerId }))// Until experiment scanners ship, legacy targeting keeps its variant picker.const experimentScanners = useFeatureFlag('VISION_EXPERIMENT_SCANNER')- if (!experimentContext || !scanner) {+ if (!experimentContext || !scanner || scanner.scanner_type === 'experiment') {return null}const { experiment, variantKey } = experimentContextconst experimentLink = <Link to={urls.experiment(experiment.id)}>{experiment.name}</Link>- if (scanner.scanner_type === 'experiment') {- const variants = scanner.scanner_config.variants- return (- <LemonCard hoverEffect={false} className="p-3 space-y-1" data-attr="vision-experiment-targeting">- <LemonLabel>Experiment</LemonLabel>- <div className="text-xs text-muted">- This scanner watches sessions of people exposed to {experimentLink}- {variants?.length ? <span> in {variants.join(', ')}</span> : null}. Filters you add here narrow it- further.- </div>- </LemonCard>- )- }-if (!experimentScanners) {// A null value targets every variant; each experiment variant is a single-select option.const variantOptions: { value: string | null; label: string }[] = [@@ -222,6 +211,9 @@ export function ScannerTriggers({ scannerId }: { scannerId: string }): JSX.Elemeif (!scanner) {return <div className="text-muted">Loading…</div>}+ // The experiment already limits the scan to exposed people, so a scanner without filters of its own+ // does not scan every recording.+ const experimentScoped = scannerExperimentScope(scanner) !== nullreturn (<div className="space-y-6">@@ -266,6 +258,7 @@ export function ScannerTriggers({ scannerId }: { scannerId: string }): JSX.ElemeonConfigure={openTestAccountFilterSettings}/></div>+ <ExperimentScopeFilter scannerId={scannerId} />{/* -ml-2 cancels AndOrFilterSelect's built-in prefix indent so "Match" left-aligns with the rest. */}<div className="-ml-2"><AndOrFilterSelect@@ -296,6 +289,7 @@ export function ScannerTriggers({ scannerId }: { scannerId: string }): JSX.Eleme</span></LemonBanner>) : (+ !experimentScoped &&groupHasNoFilters(universal.filter_group) && (<LemonBanner type="warning"><span className="text-xs">