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): show which replay scanners watch an experiment (#87348)

Kim Svatos Dugandec0044bc87f
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 14cf8ad0d6a5..9410739d3363 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -6352,6 +6352,10 @@ snapshots:
hash: v1.k794b7964.a38909c8222409c5fa2174c283833ab419c75a0ed5420da095a9aded11bf6532.5EK4l32txmbHcS11UWiwesynVVHf7FKe98dPAeWsjkw
scenes-app-experiments--experiment-frequentist-two-variants--light:
hash: v1.k794b7964.ec64583fd2debf87822296f1c9fc10e73c1c6b7e31fe55f0ca974d3920f8bd14.Ch64gBgjo0wR0Ypvkhap6047UPjXBaWSQCNoKDOiNHc
+ scenes-app-experiments--experiment-replay-scanner-backlink--dark:
+ hash: v1.k794b7964.e04ec522e5f690078c89c21f4e160d067f13c755e65988852d89dbc624e4c74b.DbWktEPnIBX15xGlIGLocMuFHo7CzbH-yVTgowQMnck
+ scenes-app-experiments--experiment-replay-scanner-backlink--light:
+ hash: v1.k794b7964.c6573bba587cbabd798e942c29bd722fea308624f4cffda71303fb2b110dd7e0.j-wHlxQDewiAsZ_lDoIuGozhNEb_FEGu0tT0I_UXkMY
scenes-app-experiments--experiment-stopped-with-conclusion--dark:
hash: v1.k794b7964.e347bbe9e217d7cbd915b09b362a9d995285c1f6492229235ce3dcef74e49f30.5xV99CaEDXp-xFACHoS4M9vQ6zFGOjestb-iW79F5Q4
scenes-app-experiments--experiment-stopped-with-conclusion--light:
diff --git a/frontend/src/scenes/experiments/ExperimentView/ExperimentReplayTab.tsx b/frontend/src/scenes/experiments/ExperimentView/ExperimentReplayTab.tsx
index bd78b55baab1..15c4eb5726d2 100644
--- a/frontend/src/scenes/experiments/ExperimentView/ExperimentReplayTab.tsx
+++ b/frontend/src/scenes/experiments/ExperimentView/ExperimentReplayTab.tsx
@@ -3,7 +3,7 @@ import { combineUrl } from 'kea-router'
import { Fragment } from 'react'
import { IconChevronDown, IconInfo } from '@posthog/icons'
-import { LemonBanner, LemonSegmentedButton } from '@posthog/lemon-ui'
+import { LemonBanner, LemonCard, LemonSegmentedButton, LemonSkeleton, LemonTag } from '@posthog/lemon-ui'
import {
DropdownMenu,
DropdownMenuCheckboxItem,
@@ -17,6 +17,7 @@ import {
import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
import { LemonButton } from 'lib/lemon-ui/LemonButton'
+import { Link } from 'lib/lemon-ui/Link'
import { Tooltip } from 'lib/lemon-ui/Tooltip'
import { pluralize } from 'lib/utils/strings'
import { SessionRecordingsPlaylist } from 'scenes/session-recordings/playlist/SessionRecordingsPlaylist'
@@ -26,6 +27,7 @@ import { urls } from 'scenes/urls'
import { Experiment } from '~/types'
import { experimentScannerParams } from 'products/replay_vision/frontend/replay_scanners/experimentTargeting'
+import { scannerTypeLabel } from 'products/replay_vision/frontend/replay_scanners/types'
import { SummarizeSessionReplaysButton } from '../components/SummarizeSessionReplaysButton'
import { isLaunched } from '../experimentStatus'
@@ -35,6 +37,7 @@ import {
ExperimentReplayMetricFilterMode,
ExperimentReplayMetricOption,
ExperimentSessionBucket,
+ LinkedScanner,
experimentReplayTabLogic,
} from './experimentReplayTabLogic'
import { VariantTag } from './VariantTag'
@@ -171,6 +174,60 @@ const METRIC_FILTER_MODE_OPTIONS: { value: ExperimentReplayMetricFilterMode; lab
},
]
+/** Placeholder for the watching-scanners card while the lookup is in flight, so the tab doesn't
+ * flash the cross-sell banner before the card resolves. */
+function LinkedScannersSkeletonCard(): JSX.Element {
+ return (
+ <LemonCard hoverEffect={false} className="mb-2 p-3" data-attr="experiment-recordings-linked-scanners-loading">
+ <LemonSkeleton className="h-5 w-64 mb-2" />
+ <LemonSkeleton className="h-4 w-full" repeat={2} />
+ </LemonCard>
+ )
+}
+
+/** The scanners already watching this experiment, one row each, with a link and a monthly count. */
+function LinkedScannersCard({
+ scanners,
+ addAnotherUrl,
+ onAddAnother,
+}: {
+ scanners: LinkedScanner[]
+ addAnotherUrl: string
+ onAddAnother: () => void
+}): JSX.Element {
+ return (
+ <LemonCard hoverEffect={false} className="mb-2 p-3" data-attr="experiment-recordings-linked-scanners">
+ <div className="flex items-center justify-between gap-2 mb-2">
+ <span className="font-semibold">Scanners watching this experiment</span>
+ <LemonButton
+ type="secondary"
+ size="small"
+ to={addAnotherUrl}
+ onClick={() => onAddAnother()}
+ data-attr="experiment-recordings-scanner-add-another"
+ >
+ Add another
+ </LemonButton>
+ </div>
+ <div className="flex flex-col gap-1">
+ {scanners.map((scanner) => (
+ <div key={scanner.id} className="flex items-center justify-between gap-2">
+ <span className="flex items-center gap-2 min-w-0">
+ <Link to={urls.replayVision(scanner.id)} className="truncate">
+ {scanner.name}
+ </Link>
+ <LemonTag type="muted">{scannerTypeLabel(scanner.scannerType)}</LemonTag>
+ </span>
+ <span className="text-muted shrink-0">
+ {pluralize(scanner.observationsThisMonth, 'observation')} this month
+ </span>
+ </div>
+ ))}
+ </div>
+ </LemonCard>
+ )
+}
+
export function ExperimentReplayTab({ experiment }: { experiment: Experiment }): JSX.Element {
const logic = experimentReplayTabLogic({ experiment })
const {
@@ -184,6 +241,8 @@ export function ExperimentReplayTab({ experiment }: { experiment: Experiment }):
sessionBucketLoading,
sessionBucketError,
sessionBucketRequest,
+ linkedScanners,
+ linkedScannersLoading,
} = useValues(logic)
const {
setSelectedVariantKey,
@@ -247,22 +306,31 @@ export function ExperimentReplayTab({ experiment }: { experiment: Experiment }):
return (
<div data-attr="experiment-recordings-tab">
- {scannerCrossSellEnabled && (
- <LemonBanner
- type="info"
- className="mb-2"
- dismissKey="experiment-replay-vision-scanner-cross-sell"
- action={{
- children: 'Set up a scanner',
- to: scannerSetupUrl,
- onClick: () => scannerCrossSellClicked(),
- 'data-attr': 'experiment-recordings-scanner-cross-sell',
- }}
- >
- Replay vision can watch new recordings from this experiment for you. Scanners check each session and
- report what they find.
- </LemonBanner>
- )}
+ {scannerCrossSellEnabled &&
+ (linkedScannersLoading ? (
+ <LinkedScannersSkeletonCard />
+ ) : linkedScanners.length > 0 ? (
+ <LinkedScannersCard
+ scanners={linkedScanners}
+ addAnotherUrl={scannerSetupUrl}
+ onAddAnother={scannerCrossSellClicked}
+ />
+ ) : (
+ <LemonBanner
+ type="info"
+ className="mb-2"
+ dismissKey="experiment-replay-vision-scanner-cross-sell"
+ action={{
+ children: 'Set up a scanner',
+ to: scannerSetupUrl,
+ onClick: () => scannerCrossSellClicked(),
+ 'data-attr': 'experiment-recordings-scanner-cross-sell',
+ }}
+ >
+ Replay vision can watch new recordings from this experiment for you. Scanners check each session
+ and report what they find.
+ </LemonBanner>
+ ))}
<div className="mb-2 flex flex-wrap gap-2">
<LemonSegmentedButton
size="small"
diff --git a/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.test.ts b/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.test.ts
index 440e3ed1a417..361a1daf07aa 100644
--- a/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.test.ts
+++ b/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.test.ts
@@ -15,6 +15,7 @@ import {
experimentsSessionContextsCreate,
experimentsSessionEventDeltasCreate,
} from 'products/experiments/frontend/generated/api'
+import { visionScannersList } from 'products/replay_vision/frontend/generated/api'
import { FUNNEL_DATA_WAREHOUSE_COMPLETION_REASON, FUNNEL_SERVER_SIDE_COMPLETION_REASON } from '../utils'
import { RETENTION_UNLINKABLE_REASON, viewRecordingsLinkabilityLogic } from '../viewRecordingsLinkabilityLogic'
@@ -30,6 +31,10 @@ jest.mock('products/experiments/frontend/generated/api', () => ({
experimentsSessionEventDeltasCreate: jest.fn(),
}))
+jest.mock('products/replay_vision/frontend/generated/api', () => ({
+ visionScannersList: jest.fn().mockResolvedValue({ results: [] }),
+}))
+
const BUCKET_RESPONSE = {
session_ids: ['bucket-1', 'bucket-2'],
truncated: false,
@@ -141,6 +146,8 @@ describe('experimentReplayTabLogic', () => {
;(experimentsSessionBucketsCreate as jest.Mock).mockResolvedValue(BUCKET_RESPONSE)
;(experimentsSessionEventDeltasCreate as jest.Mock).mockClear()
;(experimentsSessionEventDeltasCreate as jest.Mock).mockResolvedValue(DELTA_RESPONSE)
+ ;(visionScannersList as jest.Mock).mockClear()
+ ;(visionScannersList as jest.Mock).mockResolvedValue({ results: [] })
seenTogetherSpy = jest.spyOn(api.propertyDefinitions, 'seenTogether')
seenTogetherSpy.mockResolvedValue(ALL_LINKABLE)
logic = experimentReplayTabLogic({ experiment: EXPERIMENT })
@@ -925,4 +932,72 @@ describe('experimentReplayTabLogic', () => {
})
}).toMatchValues({ selectedWatchCard: null })
})
+
+ it('loads the scanners watching this experiment, scoped by experiment_id', async () => {
+ // Guards the back-link on the Recordings tab: it must query the scanners endpoint with this
+ // experiment's id (dropping the filter would list every scanner in the project) and surface
+ // the name, type, and monthly observation count each row shows.
+ logic.unmount()
+ featureFlagLogic.actions.setFeatureFlags([], { [FEATURE_FLAGS.VISION_ENTRYPOINT_EXPERIMENTS]: true })
+ ;(visionScannersList as jest.Mock).mockResolvedValue({
+ results: [
+ { id: 's1', name: 'Checkout confusion', scanner_type: 'classifier', observations_this_month: 50 },
+ { id: 's2', name: 'Rage clicks', scanner_type: 'summarizer', observations_this_month: 3 },
+ ],
+ })
+ const withScanners = experimentReplayTabLogic({ experiment: EXPERIMENT })
+ withScanners.mount()
+
+ await expectLogic(withScanners)
+ .toFinishAllListeners()
+ .toMatchValues({
+ linkedScanners: [
+ { id: 's1', name: 'Checkout confusion', scannerType: 'classifier', observationsThisMonth: 50 },
+ { id: 's2', name: 'Rage clicks', scannerType: 'summarizer', observationsThisMonth: 3 },
+ ],
+ })
+ expect(visionScannersList).toHaveBeenCalledWith(expect.any(String), { experiment_id: '42' })
+ withScanners.unmount()
+ })
+
+ it('does not query scanners when the vision entry-point flag is off', async () => {
+ // The card only renders behind the flag, so the lookup must not fire for the many users who
+ // open the Recordings tab without it. The default test flags leave the flag off.
+ logic.unmount()
+ ;(visionScannersList as jest.Mock).mockClear()
+ const withoutFlag = experimentReplayTabLogic({ experiment: EXPERIMENT })
+ withoutFlag.mount()
+
+ await expectLogic(withoutFlag).toFinishAllListeners()
+ expect(visionScannersList).not.toHaveBeenCalled()
+ withoutFlag.unmount()
+ })
+
+ it('marks the scanners lookup loading while in flight, so the tab shows a skeleton not the banner', async () => {
+ // The skeleton branch keys off linkedScannersLoading. Without the loading flag, the tab would
+ // flash the cross-sell banner (linkedScanners is [] until the fetch resolves) before the card.
+ logic.unmount()
+ featureFlagLogic.actions.setFeatureFlags([], { [FEATURE_FLAGS.VISION_ENTRYPOINT_EXPERIMENTS]: true })
+ let resolve: (value: unknown) => void = () => {}
+ ;(visionScannersList as jest.Mock).mockReturnValue(new Promise((r) => (resolve = r)))
+ const loadingLogic = experimentReplayTabLogic({ experiment: EXPERIMENT })
+ loadingLogic.mount()
+
+ await expectLogic(loadingLogic).toMatchValues({ linkedScannersLoading: true })
+ resolve({ results: [] })
+ await expectLogic(loadingLogic).toFinishAllListeners().toMatchValues({ linkedScannersLoading: false })
+ loadingLogic.unmount()
+ })
+
+ it('degrades to no back-link when the scanner lookup fails', async () => {
+ // The tab must render even if the lookup errors, so the loader swallows to an empty list.
+ logic.unmount()
+ featureFlagLogic.actions.setFeatureFlags([], { [FEATURE_FLAGS.VISION_ENTRYPOINT_EXPERIMENTS]: true })
+ ;(visionScannersList as jest.Mock).mockRejectedValue(new Error('boom'))
+ const withError = experimentReplayTabLogic({ experiment: EXPERIMENT })
+ withError.mount()
+
+ await expectLogic(withError).toFinishAllListeners().toMatchValues({ linkedScanners: [] })
+ withError.unmount()
+ })
})
diff --git a/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.ts b/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.ts
index 86b9d2b51f2a..14180bac2936 100644
--- a/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.ts
+++ b/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.ts
@@ -60,6 +60,8 @@ import type {
ExperimentSessionEventDeltaResponseApi,
ExperimentWatchCardApi,
} from 'products/experiments/frontend/generated/api.schemas'
+import { visionScannersList } from 'products/replay_vision/frontend/generated/api'
+import type { ScannerTypeEnumApi } from 'products/replay_vision/frontend/generated/api.schemas'
import type { ExperimentIdType } from '../../../types'
import type { ExperimentSavedMetric } from '../experimentLogic'
@@ -81,6 +83,14 @@ export interface ExperimentReplayTabLogicProps {
experiment: Experiment
}
+/** A scanner already watching this experiment, for the back-link on the Recordings tab. */
+export interface LinkedScanner {
+ id: string
+ name: string
+ scannerType: ScannerTypeEnumApi
+ observationsThisMonth: number
+}
+
/** One experiment metric offered in the recordings tab's "Metric events" dropdown. */
export interface ExperimentReplayMetricOption {
uuid: string
@@ -171,6 +181,8 @@ export interface experimentReplayTabLogicValues {
bucketSessionIds: string[] | undefined
effectiveMetricUuids: string[]
effectiveVariantKey: string | null
+ linkedScanners: LinkedScanner[]
+ linkedScannersLoading: boolean
loadedRecordings: ExperimentReplayRecording[]
loadedRecordingsById: Map<string, ExperimentReplayRecording>
metricFilterMode: ExperimentReplayMetricFilterMode
@@ -264,6 +276,31 @@ export interface experimentReplayTabLogicActions {
payload?: any
seenTogetherMap: Record<string, boolean>
} // viewRecordingsLinkabilityLogic
+ loadLinkedScanners: (_?: unknown) => unknown
+ loadLinkedScannersFailure: (
+ error: string,
+ errorObject?: any
+ ) => {
+ error: string
+ errorObject?: any
+ }
+ loadLinkedScannersSuccess: (
+ linkedScanners: {
+ id: string
+ name: string
+ observationsThisMonth: number
+ scannerType: ScannerTypeEnumApi
+ }[],
+ payload?: unknown
+ ) => {
+ linkedScanners: {
+ id: string
+ name: string
+ observationsThisMonth: number
+ scannerType: ScannerTypeEnumApi
+ }[]
+ payload?: unknown
+ }
loadSessionBucket: (_?: unknown) => unknown
loadSessionBucketFailure: (
error: string,
@@ -510,6 +547,30 @@ export const experimentReplayTabLogic = kea<experimentReplayTabLogicType>([
},
},
],
+ linkedScanners: [
+ [] as LinkedScanner[],
+ {
+ // The scanners already watching this experiment. The `experiment_id` filter is gated
+ // on the caller's experiment access server-side, so an unreadable experiment resolves
+ // to an empty list. Fail-soft to []: the tab must render even if the lookup fails.
+ loadLinkedScanners: async (_: unknown = null, breakpoint) => {
+ try {
+ const response = await visionScannersList(String(values.currentProjectId), {
+ experiment_id: String(props.experiment.id),
+ })
+ breakpoint()
+ return response.results.map((scanner) => ({
+ id: scanner.id,
+ name: scanner.name,
+ scannerType: scanner.scanner_type,
+ observationsThisMonth: scanner.observations_this_month,
+ }))
+ } catch {
+ return []
+ }
+ },
+ },
+ ],
})),
reducers({
// null = "All" (every exposed session, regardless of variant). Persisted (keyed per
@@ -1047,6 +1108,11 @@ export const experimentReplayTabLogic = kea<experimentReplayTabLogicType>([
})),
afterMount(({ values, actions }) => {
actions.setDefaultTab(SessionRecordingSidebarTab.OVERVIEW)
+ // Only the vision entry point renders the watching-scanners card, so don't spend the lookup
+ // for everyone else who opens this tab without the flag.
+ if (values.featureFlags[FEATURE_FLAGS.VISION_ENTRYPOINT_EXPERIMENTS]) {
+ actions.loadLinkedScanners()
+ }
// The mode persists, so a tab reopened in a bucket needs its session set again.
if (values.sessionBucketRequest) {
diff --git a/frontend/src/scenes/experiments/stories/ExperimentReplayScannerBacklink.stories.tsx b/frontend/src/scenes/experiments/stories/ExperimentReplayScannerBacklink.stories.tsx
new file mode 100644
index 000000000000..fe9c6db6bf3b
--- /dev/null
+++ b/frontend/src/scenes/experiments/stories/ExperimentReplayScannerBacklink.stories.tsx
@@ -0,0 +1,63 @@
+import { Meta, StoryObj } from '@storybook/react'
+
+import { FEATURE_FLAGS } from 'lib/constants'
+import { makeDelay } from 'lib/utils/async'
+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'
+
+// A launched experiment with two replay vision scanners already watching it, so the Recordings
+// tab shows the back-link banner listing them instead of the cross-sell prompt.
+const meta: Meta = {
+ component: App,
+ title: 'Scenes-App/Experiments',
+ parameters: {
+ layout: 'fullscreen',
+ viewMode: 'story',
+ mockDate: '2025-06-01',
+ pageUrl: urls.experiment(EXPERIMENT_WITH_FUNNEL_METRIC.id) + '?tab=recordings',
+ featureFlags: [FEATURE_FLAGS.EXPERIMENT_RECORDINGS_TAB, FEATURE_FLAGS.VISION_ENTRYPOINT_EXPERIMENTS],
+ testOptions: { waitForSelector: '[data-attr="experiment-recordings-tab"]' },
+ },
+ decorators: [
+ mswDecorator({
+ get: {
+ [`/api/projects/:team_id/experiments/${EXPERIMENT_WITH_FUNNEL_METRIC.id}/`]:
+ EXPERIMENT_WITH_FUNNEL_METRIC,
+ '/api/projects/:team_id/experiment_holdouts': [],
+ '/api/projects/:team_id/experiment_saved_metrics/': [],
+ [`/api/projects/:team_id/feature_flags/${EXPERIMENT_WITH_FUNNEL_METRIC.feature_flag.id}/`]: {},
+ [`/api/projects/:team_id/feature_flags/${EXPERIMENT_WITH_FUNNEL_METRIC.feature_flag.id}/status/`]: {},
+ '/api/environments/:team_id/default_release_conditions/': [],
+ // The back-link's data: the scanners watching this experiment.
+ '/api/projects/:team_id/vision/scanners/': {
+ count: 2,
+ results: [
+ {
+ id: '0192aaaa-0000-7000-8000-000000000001',
+ name: 'Checkout confusion',
+ scanner_type: 'classifier',
+ observations_this_month: 128,
+ },
+ {
+ id: '0192bbbb-0000-7000-8000-000000000002',
+ name: 'Signup drop-off',
+ scanner_type: 'summarizer',
+ observations_this_month: 12,
+ },
+ ],
+ },
+ },
+ post: {
+ '/api/environments/:team_id/query/:kind': [200, { results: [] }],
+ },
+ }),
+ ],
+}
+export default meta
+
+type Story = StoryObj<{}>
+
+export const ExperimentReplayScannerBacklink: Story = { play: makeDelay(700) }