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): use the experiment scanner cross-sell on experiment surfaces (#114113)

Kim Svatos Dugan7da3450ad4cc
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 81821f79e5ec..5bec6ef61381 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -10279,9 +10279,13 @@ snapshots:
scenes-app-experiments--experiment-recordings-unavailable-group-aggregated--light:
hash: v1.k794b7964.c6b197ae1b260f15f33fdc2251eff7246956772fccfceb286b6cda0c9ed5de81.y9y06Hk4JXU2-aap9VGPbLhBgdGo2bJm19XxKxFxVds
scenes-app-experiments--experiment-replay-scanner-backlink--dark:
- hash: v1.k794b7964.cd6862ecf47a68f070f2f333c3f607cdeb2b3f7ffc0738f95cf8bb8b1f7f6f76.kehuIJHFlk8zkZ2Ls3DtOZ0sNZeaca_9tySnCIN8Hd4
+ hash: v1.k794b7964.603df175d65bbc316afb4c5aa282bc1e43b8039fd7986d74b675757d58432165.Q60imiL0l-iEweDOLGPiHVz0y5ijN5CCT7YTt6wB7RY
scenes-app-experiments--experiment-replay-scanner-backlink--light:
- hash: v1.k794b7964.9419bc808495f0a343293f26a06605e933f2a47bbaf698294fae2ac4cf477c65.FMInh_LM8Ux5fopKYeVHs4jfyfl01C-89G1jww94VdE
+ hash: v1.k794b7964.a03f6fa37e562b4f76aa217cde6d1a3beeb4f7901b7e43f2ec39b6b641f3e057.UkQwbkCiYNckbgIjCmflkV_e6LQSdxzt1kCRuNiBgS4
+ scenes-app-experiments--experiment-replay-scanner-cross-sell--dark:
+ hash: v1.k794b7964.a66ab60f8c727562db838357019f31be4f69555bbbb7ffe8177e7ed895e99de7.Pvf493SVaLyoichqyvrzbRjljXs-yDITdg5Y1k_bvGo
+ scenes-app-experiments--experiment-replay-scanner-cross-sell--light:
+ hash: v1.k794b7964.963fbd1cb61f4cd6add9b2629c55c6be72847f7b72e049fe52317929c8dc7448.OthNei7lbh162i0nXZEsHXppCKRouEoMjipxd7P-HdE
scenes-app-experiments--experiment-results-row-recording-links-funnel--dark:
hash: v1.k794b7964.f5d679ed87f8fe92f1982b94fc7bada993551c994d8f1b45c7df55499eb51040.JK2tItvyzYgTOayd3lwMqU5PHlaJ30gu8JKGL4D9mGw
scenes-app-experiments--experiment-results-row-recording-links-funnel--light:
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx
index cd2e40a02e71..7bd08c813e99 100644
--- a/frontend/src/lib/constants.tsx
+++ b/frontend/src/lib/constants.tsx
@@ -591,7 +591,6 @@ export const FEATURE_FLAGS = {
UNIFIED_APM_PRODUCT: 'unified-apm-product', // owner: #team-apm (@jonmcwest, @frankh), gates the shared APM product backing logs, tracing, and metrics
UX_HIDE_PROJECT_NOTICE: 'ux-hide-project-notice', // owner: #team-platform-ux, hides the project notice banner across all scenes
UX_REMOVE_SIDEPANEL: 'ux-remove-sidepanel', // owner: #team-surveys
- VISION_ENTRYPOINT_EXPERIMENTS: 'vision-entrypoint-experiments', // owner: #team-replay, cross-sell entry points from experiments
VISION_ENTRYPOINT_REPLAY_FILTERS: 'vision-entrypoint-replay-filters', // owner: #team-replay, cross-sell entry point from the replay filters panel
VISION_EXPERIMENT_SCANNER: 'experiment-scanner', // owner: #team-replay, experiment scanners overall: the type in the scanner editor, creating one from experiments, and the variants tab
VISION_GOAL_FLOW_V2: 'vision-goal-flow-v2', // owner: #team-replay multivariate=control,test — gate on === 'test'; a truthy check turns on for control too
diff --git a/frontend/src/scenes/experiments/ExperimentForm/createExperimentLogic.test.ts b/frontend/src/scenes/experiments/ExperimentForm/createExperimentLogic.test.ts
index 19583db97be9..7e6feeb0b795 100644
--- a/frontend/src/scenes/experiments/ExperimentForm/createExperimentLogic.test.ts
+++ b/frontend/src/scenes/experiments/ExperimentForm/createExperimentLogic.test.ts
@@ -208,7 +208,7 @@ describe('createExperimentLogic', () => {
})
)
expect(lemonToast.success).toHaveBeenCalledWith(
- 'Experiment created. The Replay Vision scanner turns on when you launch the experiment.',
+ 'Experiment created. The experiment scanner turns on when you launch the experiment.',
expect.objectContaining({
button: expect.objectContaining({ label: 'View scanner' }),
})
@@ -220,6 +220,9 @@ describe('createExperimentLogic', () => {
name: 'a generic failure is reported to error tracking',
response: [500, { detail: 'Scanner unavailable' }] as [number, Record<string, unknown>],
shouldCapture: true,
+ experimentScanners: false,
+ message: "Experiment created, but the Replay Vision scanner wasn't.",
+ retry: { label: 'Set up scanner', url: '/replay-vision/new/template' },
},
{
// Missing org AI consent is user-correctable config, not a defect: keep it out of error
@@ -227,33 +230,55 @@ describe('createExperimentLogic', () => {
name: 'a missing AI consent 400 is not reported to error tracking',
response: [400, { code: 'ai_data_processing_not_approved' }] as [number, Record<string, unknown>],
shouldCapture: false,
+ experimentScanners: false,
+ message: "Experiment created, but the Replay Vision scanner wasn't.",
+ retry: { label: 'Set up scanner', url: '/replay-vision/new/template' },
},
- ])('keeps the created experiment when scanner creation fails: $name', async ({ response, shouldCapture }) => {
- const captureExceptionSpy = jest.spyOn(posthog, 'captureException').mockImplementation(() => undefined)
- scannerCreateSpy.mockResolvedValueOnce(response)
- await expectLogic(logic, () => {
- logic.actions.setCreateReplayVisionScanner(true)
- logic.actions.setExperiment({
- ...NEW_EXPERIMENT,
- name: 'Test Experiment',
- description: 'Test hypothesis',
- feature_flag_key: 'test-experiment',
+ {
+ // The retry must reopen the experiment scanner wizard on this experiment, not the generic
+ // template list, or the person starts over without the experiment.
+ name: 'with experiment scanners the retry opens the experiment scanner wizard',
+ response: [500, { detail: 'Scanner unavailable' }] as [number, Record<string, unknown>],
+ shouldCapture: true,
+ experimentScanners: true,
+ message: "Experiment created, but the experiment scanner wasn't.",
+ retry: { label: 'Set up experiment scanner', url: '/replay-vision/new/template?experiment=123' },
+ },
+ ])(
+ 'keeps the created experiment when scanner creation fails: $name',
+ async ({ response, shouldCapture, experimentScanners, message, retry }) => {
+ featureFlagLogic.actions.setFeatureFlags([], {
+ [FEATURE_FLAGS.VISION_EXPERIMENT_SCANNER]: experimentScanners,
})
- logic.actions.saveExperiment()
- })
- .toDispatchActions(['saveExperiment', 'createExperimentSuccess', 'saveExperimentSuccess'])
- .toFinishAllListeners()
-
- expect(routerPushSpy).toHaveBeenCalledWith('/experiments/123')
- expect(lemonToast.error).toHaveBeenCalledWith(
- "Experiment created, but the Replay Vision scanner wasn't.",
- expect.objectContaining({
- button: expect.objectContaining({ label: 'Set up scanner' }),
+ const captureExceptionSpy = jest.spyOn(posthog, 'captureException').mockImplementation(() => undefined)
+ scannerCreateSpy.mockResolvedValueOnce(response)
+ await expectLogic(logic, () => {
+ logic.actions.setCreateReplayVisionScanner(true)
+ logic.actions.setExperiment({
+ ...NEW_EXPERIMENT,
+ name: 'Test Experiment',
+ description: 'Test hypothesis',
+ feature_flag_key: 'test-experiment',
+ })
+ logic.actions.saveExperiment()
})
- )
- expect(captureExceptionSpy).toHaveBeenCalledTimes(shouldCapture ? 1 : 0)
- captureExceptionSpy.mockRestore()
- })
+ .toDispatchActions(['saveExperiment', 'createExperimentSuccess', 'saveExperimentSuccess'])
+ .toFinishAllListeners()
+
+ expect(routerPushSpy).toHaveBeenCalledWith('/experiments/123')
+ expect(lemonToast.error).toHaveBeenCalledWith(
+ message,
+ expect.objectContaining({
+ button: expect.objectContaining({ label: retry.label }),
+ })
+ )
+ const [, { button }] = (lemonToast.error as jest.Mock).mock.calls.at(-1)
+ button.action()
+ expect(routerPushSpy).toHaveBeenLastCalledWith(retry.url)
+ expect(captureExceptionSpy).toHaveBeenCalledTimes(shouldCapture ? 1 : 0)
+ captureExceptionSpy.mockRestore()
+ }
+ )
it('refreshes tree items for experiment and feature flag after creation', async () => {
await expectLogic(logic, () => {
diff --git a/frontend/src/scenes/experiments/ExperimentForm/createExperimentLogic.ts b/frontend/src/scenes/experiments/ExperimentForm/createExperimentLogic.ts
index 5c25386ff978..5d49b8db21b4 100644
--- a/frontend/src/scenes/experiments/ExperimentForm/createExperimentLogic.ts
+++ b/frontend/src/scenes/experiments/ExperimentForm/createExperimentLogic.ts
@@ -1,5 +1,5 @@
import { MakeLogicType, actions, connect, events, kea, key, listeners, path, props, reducers, selectors } from 'kea'
-import { router } from 'kea-router'
+import { combineUrl, router } from 'kea-router'
import posthog from 'posthog-js'
import { ApiError } from 'lib/api-error'
@@ -31,6 +31,7 @@ import type {
ExperimentTypeEnumApi,
} from 'products/experiments/frontend/generated/api.schemas'
import { visionScannersCreate } from 'products/replay_vision/frontend/generated/api'
+import { experimentScannerParams } from 'products/replay_vision/frontend/replay_scanners/experimentTargeting'
import type { ProductCrossSellProperties, ProductIntentProperties } from '../../../lib/utils/product-intents'
import type { ExperimentMetricUnion } from '../../../queries/schema/schema-general'
@@ -536,16 +537,35 @@ export const createExperimentLogic = kea<createExperimentLogicType>([
}
if (replayScannerCreationFailed) {
- lemonToast.error("Experiment created, but the Replay Vision scanner wasn't.", {
- button: {
- label: 'Set up scanner',
- action: () => router.actions.push(urls.replayVisionTemplates()),
- },
- })
+ lemonToast.error(
+ experimentScanners
+ ? "Experiment created, but the experiment scanner wasn't."
+ : "Experiment created, but the Replay Vision scanner wasn't.",
+ {
+ button: experimentScanners
+ ? {
+ label: 'Set up experiment scanner',
+ action: () =>
+ router.actions.push(
+ combineUrl(
+ urls.replayVisionScannerTemplate('new'),
+ experimentScannerParams({
+ experimentId: response.id as number,
+ variantKey: null,
+ })
+ ).url
+ ),
+ }
+ : {
+ label: 'Set up scanner',
+ action: () => router.actions.push(urls.replayVisionTemplates()),
+ },
+ }
+ )
} else if (replayScannerId) {
lemonToast.success(
experimentScanners
- ? 'Experiment created. The Replay Vision scanner turns on when you launch the experiment.'
+ ? 'Experiment created. The experiment scanner turns on when you launch the experiment.'
: 'Experiment created. The Replay Vision scanner is off until you turn it on.',
{
button: {
diff --git a/frontend/src/scenes/experiments/ExperimentView/ExperimentReplayTab.tsx b/frontend/src/scenes/experiments/ExperimentView/ExperimentReplayTab.tsx
index f880f8eedf3f..ea0e7d233948 100644
--- a/frontend/src/scenes/experiments/ExperimentView/ExperimentReplayTab.tsx
+++ b/frontend/src/scenes/experiments/ExperimentView/ExperimentReplayTab.tsx
@@ -1,9 +1,8 @@
import { useActions, useValues } from 'kea'
-import { combineUrl } from 'kea-router'
import { Fragment } from 'react'
import { IconChevronDown, IconInfo } from '@posthog/icons'
-import { LemonBanner, LemonCard, LemonSegmentedButton, LemonSkeleton, LemonTag } from '@posthog/lemon-ui'
+import { LemonBanner, LemonSegmentedButton, LemonSkeleton } from '@posthog/lemon-ui'
import {
DropdownMenu,
DropdownMenuCheckboxItem,
@@ -18,18 +17,13 @@ import {
import { dayjs } from 'lib/dayjs'
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'
import { sessionRecordingsPlaylistLogic } from 'scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic'
-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 { NOT_A_FUNNEL_REASON } from '../utils'
import { ExperimentBehaviorComparison, ExperimentBehaviorComparisonToggle } from './ExperimentBehaviorComparison'
import { EXPERIMENT_RECORDING_MODE_OPTIONS, METRIC_UNSELECTABLE_COPY } from './experimentRecordingModes'
@@ -39,9 +33,9 @@ import {
ExperimentRecordingsListUnavailableReason,
ExperimentReplayMetricOption,
ExperimentSessionBucket,
- LinkedScanner,
experimentReplayTabLogic,
} from './experimentReplayTabLogic'
+import { ExperimentScannerEntryPoint } from './ExperimentScannerEntryPoint'
import { VariantTag } from './VariantTag'
// LemonSegmentedButton values must be strings; the logic stores null for "All". '$' is not an
@@ -49,10 +43,6 @@ import { VariantTag } from './VariantTag'
// variant — a variant literally named "all" just renders as its own option after the built-in "All".
const ALL_VARIANTS = '$all'
-// Unchanged from the earlier cross-sell wording, so a dismissal there still holds. Someone who
-// turned down scanners for this experiment did not ask to be told again in purple.
-const SCANNER_CROSS_SELL_DISMISS_KEY = 'experiment-replay-vision-scanner-cross-sell'
-
// The 'all_exposed' caption carries the part that isn't guessable: exposure is resolved per
// person, matching who the analysis counts, so sessions appear even when the exposure event fired
// server-side or in an earlier session.
@@ -216,61 +206,6 @@ function MetricOptionLabel({ option }: { option: ExperimentReplayMetricOption })
)
}
-/** 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>
- {scanner.startsAtLaunch && <LemonTag type="highlight">Starts at launch</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 {
@@ -290,8 +225,6 @@ export function ExperimentReplayTab({ experiment }: { experiment: Experiment }):
sessionBucketLoading,
sessionBucketError,
sessionBucketRequest,
- linkedScanners,
- linkedScannersLoading,
listUnavailableReason,
listLoadError,
} = useValues(logic)
@@ -306,9 +239,8 @@ export function ExperimentReplayTab({ experiment }: { experiment: Experiment }):
recordingsLoadFailed,
retryListLoad,
recordingOpened,
- scannerCrossSellClicked,
} = useActions(logic)
- const scannerCrossSellEnabled = useFeatureFlag('VISION_ENTRYPOINT_EXPERIMENTS')
+ const experimentScannerEnabled = useFeatureFlag('VISION_EXPERIMENT_SCANNER')
// Which in-session copy applies, from the evidence kind the availability check resolved.
const inSessionCopy =
IN_SESSION_COPY[inSessionExposure ? (inSessionExposure.uses_stamped_fallback ? 'stamped' : 'event') : 'unknown']
@@ -373,40 +305,11 @@ export function ExperimentReplayTab({ experiment }: { experiment: Experiment }):
(metricFilterMode === 'fired_all' || metricFilterMode === 'funnel_completed') &&
effectiveMetricUuids.length > 0
- const scannerSetupUrl = combineUrl(
- urls.replayVisionScannerTemplate('new'),
- experimentScannerParams({
- experimentId: experiment.id as number,
- variantKey: effectiveVariantKey,
- })
- ).url
-
return (
<div data-attr="experiment-recordings-tab">
- {scannerCrossSellEnabled &&
- (linkedScannersLoading ? (
- <LinkedScannersSkeletonCard />
- ) : linkedScanners.length > 0 ? (
- <LinkedScannersCard
- scanners={linkedScanners}
- addAnotherUrl={scannerSetupUrl}
- onAddAnother={scannerCrossSellClicked}
- />
- ) : (
- <LemonBanner
- type="ai"
- className="mb-2"
- dismissKey={SCANNER_CROSS_SELL_DISMISS_KEY}
- action={{
- children: 'Set up scanner for this experiment',
- to: scannerSetupUrl,
- onClick: () => scannerCrossSellClicked(),
- 'data-attr': 'experiment-recordings-scanner-cross-sell',
- }}
- >
- Replay vision is here. Scanners watch your recordings for you and surface what matters.
- </LemonBanner>
- ))}
+ {experimentScannerEnabled && (
+ <ExperimentScannerEntryPoint experiment={experiment} variantKey={effectiveVariantKey} />
+ )}
<div className="mb-2 flex flex-wrap gap-2">
<LemonSegmentedButton
size="small"
diff --git a/frontend/src/scenes/experiments/ExperimentView/ExperimentScannerEntryPoint.tsx b/frontend/src/scenes/experiments/ExperimentView/ExperimentScannerEntryPoint.tsx
new file mode 100644
index 000000000000..b59f8c8beba5
--- /dev/null
+++ b/frontend/src/scenes/experiments/ExperimentView/ExperimentScannerEntryPoint.tsx
@@ -0,0 +1,212 @@
+import { useActions, useValues } from 'kea'
+import { combineUrl } from 'kea-router'
+
+import { IconArrowRight, IconSparkles, IconX } from '@posthog/icons'
+import { LemonCard, LemonSkeleton, LemonTag } from '@posthog/lemon-ui'
+
+import { LemonButton } from 'lib/lemon-ui/LemonButton'
+import { Link } from 'lib/lemon-ui/Link'
+import { pluralize } from 'lib/utils/strings'
+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 { LinkedScanner, experimentReplayTabLogic } from './experimentReplayTabLogic'
+import { VariantTag } from './VariantTag'
+
+/** Where an experiment scanner's own results are: its Variants tab. Other types open on their default tab. */
+function scannerUrl(scanner: LinkedScanner): string {
+ return scanner.scannerType === 'experiment'
+ ? combineUrl(urls.replayVision(scanner.id), { tab: 'variants' }).url
+ : urls.replayVision(scanner.id)
+}
+
+/** Holds the card's place while the lookup is in flight, so the tab doesn't flash the set-up card first. */
+function ScannerEntryPointSkeleton(): JSX.Element {
+ return (
+ <LemonCard hoverEffect={false} className="mb-2 p-3" data-attr="experiment-recordings-linked-scanners-loading">
+ <LemonSkeleton className="mb-2 h-5 w-64" />
+ <LemonSkeleton className="h-4 w-full" repeat={2} />
+ </LemonCard>
+ )
+}
+
+/** The scanners already watching this experiment, each with a link to its results. */
+function LinkedScannersCard({
+ scanners,
+ addUrl,
+ onAdd,
+ onOpen,
+}: {
+ scanners: LinkedScanner[]
+ addUrl: string
+ onAdd: () => void
+ onOpen: (scanner: LinkedScanner) => void
+}): JSX.Element {
+ return (
+ <LemonCard hoverEffect={false} className="mb-2 p-0" data-attr="experiment-recordings-linked-scanners">
+ <div className="flex flex-wrap items-center justify-between gap-2 border-b px-3 py-2">
+ <span className="flex items-center gap-2 font-semibold">
+ <IconSparkles className="text-ai" />
+ Replay vision scanners on this experiment
+ </span>
+ <LemonButton
+ type="secondary"
+ size="small"
+ to={addUrl}
+ onClick={() => onAdd()}
+ data-attr="experiment-recordings-scanner-add-another"
+ >
+ Add scanner
+ </LemonButton>
+ </div>
+ <ul className="m-0 list-none divide-y p-0">
+ {scanners.map((scanner) => (
+ <li key={scanner.id} className="flex flex-wrap items-center justify-between gap-2 px-3 py-2">
+ <span className="flex min-w-0 items-center gap-2">
+ <Link
+ to={scannerUrl(scanner)}
+ onClick={() => onOpen(scanner)}
+ className="truncate font-medium"
+ >
+ {scanner.name}
+ </Link>
+ <LemonTag type="muted">{scannerTypeLabel(scanner.scannerType)}</LemonTag>
+ {scanner.startsAtLaunch && <LemonTag type="highlight">Starts at launch</LemonTag>}
+ </span>
+ <span className="flex shrink-0 items-center gap-3">
+ <span className="text-xs text-muted">
+ {pluralize(scanner.observationsThisMonth, 'observation')} this month
+ </span>
+ {scanner.scannerType === 'experiment' && (
+ <LemonButton
+ type="tertiary"
+ size="xsmall"
+ sideIcon={<IconArrowRight />}
+ to={scannerUrl(scanner)}
+ onClick={() => onOpen(scanner)}
+ data-attr="experiment-recordings-scanner-compare-variants"
+ >
+ Compare variants
+ </LemonButton>
+ )}
+ </span>
+ </li>
+ ))}
+ </ul>
+ </LemonCard>
+ )
+}
+
+/** Offers an experiment scanner on an experiment that has none yet. A dismissal hides it on every experiment. */
+function ScannerSetUpCard({
+ variantKeys,
+ setUpUrl,
+ onSetUp,
+ onDismiss,
+}: {
+ variantKeys: string[]
+ setUpUrl: string
+ onSetUp: () => void
+ onDismiss: () => void
+}): JSX.Element {
+ return (
+ <LemonCard
+ hoverEffect={false}
+ className="@container relative mb-2 p-4"
+ data-attr="experiment-recordings-scanner-cross-sell-card"
+ >
+ <LemonButton
+ className="absolute top-2 right-2"
+ size="xsmall"
+ icon={<IconX />}
+ onClick={() => onDismiss()}
+ tooltip="Hide this suggestion"
+ aria-label="Dismiss"
+ data-attr="experiment-recordings-scanner-cross-sell-dismiss"
+ />
+ <div className="flex flex-col gap-3 pr-8 @2xl:flex-row @2xl:items-center @2xl:justify-between">
+ <div className="min-w-0 space-y-1">
+ <h3 className="m-0 flex items-center gap-2 text-base font-semibold">
+ <IconSparkles className="text-ai" />
+ Compare what users do in each variant
+ </h3>
+ <p className="m-0 text-sm text-secondary">
+ An experiment scanner uses Replay vision to summarize the recordings of exposed users, then
+ shows each variant side by side. Use it next to your metrics to see how people use what you
+ changed.
+ </p>
+ {variantKeys.length > 0 && (
+ <div className="flex flex-wrap items-center gap-1 pt-1 text-xs text-muted">
+ <span>Watches</span>
+ {variantKeys.map((key) => (
+ <VariantTag key={key} variantKey={key} />
+ ))}
+ </div>
+ )}
+ </div>
+ <div className="flex shrink-0 flex-col items-start gap-1 @2xl:items-end">
+ <LemonButton
+ type="primary"
+ to={setUpUrl}
+ onClick={() => onSetUp()}
+ data-attr="experiment-recordings-scanner-cross-sell"
+ >
+ Set up experiment scanner
+ </LemonButton>
+ <span className="text-xs text-muted">Each summarized session uses Replay vision credits.</span>
+ </div>
+ </div>
+ </LemonCard>
+ )
+}
+
+/**
+ * Replay vision's entry point on an experiment's Recordings tab: the scanners already watching the
+ * experiment, or an offer to set one up. Rendered only behind the experiment scanner flag.
+ */
+export function ExperimentScannerEntryPoint({
+ experiment,
+ variantKey,
+}: {
+ experiment: Experiment
+ /** The variant the list is narrowed to, carried into the wizard so the scanner starts on it. */
+ variantKey: string | null
+}): JSX.Element | null {
+ const logic = experimentReplayTabLogic({ experiment })
+ const { linkedScanners, linkedScannersLoading, variantKeys, scannerSetUpDismissed } = useValues(logic)
+ const { scannerCrossSellClicked, dismissScannerSetUp, linkedScannerOpened } = useActions(logic)
+
+ const setUpUrl = combineUrl(
+ urls.replayVisionScannerTemplate('new'),
+ experimentScannerParams({ experimentId: experiment.id as number, variantKey })
+ ).url
+
+ if (linkedScannersLoading) {
+ return <ScannerEntryPointSkeleton />
+ }
+ if (linkedScanners.length > 0) {
+ return (
+ <LinkedScannersCard
+ scanners={linkedScanners}
+ addUrl={setUpUrl}
+ onAdd={scannerCrossSellClicked}
+ onOpen={(scanner) => linkedScannerOpened(scanner.scannerType)}
+ />
+ )
+ }
+ if (scannerSetUpDismissed) {
+ return null
+ }
+ return (
+ <ScannerSetUpCard
+ variantKeys={variantKeys}
+ setUpUrl={setUpUrl}
+ onSetUp={scannerCrossSellClicked}
+ onDismiss={dismissScannerSetUp}
+ />
+ )
+}
diff --git a/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.test.ts b/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.test.ts
index a40e770bcf42..e86e10cb520d 100644
--- a/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.test.ts
+++ b/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.test.ts
@@ -2170,7 +2170,7 @@ describe('experimentReplayTabLogic', () => {
// 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 })
+ featureFlagLogic.actions.setFeatureFlags([], { [FEATURE_FLAGS.VISION_EXPERIMENT_SCANNER]: true })
;(visionScannersList as jest.Mock).mockResolvedValue({
results: [
{
@@ -2197,6 +2197,7 @@ describe('experimentReplayTabLogic', () => {
},
],
})
+ const captureSpy = jest.spyOn(posthog, 'capture').mockReturnValue(undefined as any)
const withScanners = experimentReplayTabLogic({ experiment: EXPERIMENT })
withScanners.mount()
@@ -2229,10 +2230,17 @@ describe('experimentReplayTabLogic', () => {
],
})
expect(visionScannersList).toHaveBeenCalledWith(expect.any(String), { experiment_id: '42' })
+ // The adoption funnel reads which entry point was shown from this event.
+ expect(captureSpy).toHaveBeenCalledWith('experiment recordings scanner entry point shown', {
+ experiment_id: 42,
+ state: 'scanners_listed',
+ scanner_count: 3,
+ })
+ captureSpy.mockRestore()
withScanners.unmount()
})
- it('does not query scanners when the vision entry-point flag is off', async () => {
+ it('does not query scanners when the experiment scanner 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()
@@ -2249,7 +2257,7 @@ describe('experimentReplayTabLogic', () => {
// 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 })
+ featureFlagLogic.actions.setFeatureFlags([], { [FEATURE_FLAGS.VISION_EXPERIMENT_SCANNER]: true })
let resolve: (value: unknown) => void = () => {}
;(visionScannersList as jest.Mock).mockReturnValue(new Promise((r) => (resolve = r)))
const loadingLogic = experimentReplayTabLogic({ experiment: EXPERIMENT })
@@ -2264,12 +2272,19 @@ describe('experimentReplayTabLogic', () => {
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 })
+ featureFlagLogic.actions.setFeatureFlags([], { [FEATURE_FLAGS.VISION_EXPERIMENT_SCANNER]: true })
;(visionScannersList as jest.Mock).mockRejectedValue(new Error('boom'))
+ const captureSpy = jest.spyOn(posthog, 'capture').mockReturnValue(undefined as any)
const withError = experimentReplayTabLogic({ experiment: EXPERIMENT })
withError.mount()
await expectLogic(withError).toFinishAllListeners().toMatchValues({ linkedScanners: [] })
+ // With no scanners the tab offers the set-up card, and the shown event must say so.
+ expect(captureSpy).toHaveBeenCalledWith(
+ 'experiment recordings scanner entry point shown',
+ expect.objectContaining({ state: 'set_up_offered', scanner_count: 0 })
+ )
+ captureSpy.mockRestore()
withError.unmount()
})
})
diff --git a/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.ts b/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.ts
index d817ce441667..fa813e3a7d2b 100644
--- a/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.ts
+++ b/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.ts
@@ -20,6 +20,7 @@ import posthog from 'posthog-js'
import { FEATURE_FLAGS } from 'lib/constants'
import { dayjs } from 'lib/dayjs'
+import { lemonBannerLogic } from 'lib/lemon-ui/LemonBanner/lemonBannerLogic'
import { FeatureFlagsSet, featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { groupBy } from 'lib/utils/arrays'
import {
@@ -111,6 +112,10 @@ function reportExperimentRecordingsTabViewed(
})
}
+// Unchanged from the earlier cross-sell, so a dismissal there still holds. Someone who turned down
+// scanners for an experiment did not ask to be told again.
+const SCANNER_SET_UP_DISMISS_KEY = 'experiment-replay-vision-scanner-cross-sell'
+
export interface ExperimentReplayTabLogicProps {
experiment: Experiment
}
@@ -395,6 +400,7 @@ function metricDisplayOrder(experiment: Experiment): (a: { uuid: string }, b: {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface experimentReplayTabLogicValues {
featureFlags: FeatureFlagsSet // featureFlagLogic
+ scannerSetUpDismissed: boolean // lemonBannerLogic
hideViewedRecordings: HideViewedRecordingsOptions // playerSettingsLogic
currentProjectId: number | string // teamLogic
currentTeam: TeamPublicType | TeamType | null // teamLogic
@@ -544,6 +550,9 @@ export interface experimentReplayTabLogicActions {
context: ExperimentWatchHighlightContext
experimentId: ExperimentIdType
} // eventUsageLogic
+ dismissScannerSetUp: () => {
+ value: true
+ } // lemonBannerLogic
setDefaultTab: (tab: SessionRecordingSidebarTab) => {
tab: SessionRecordingSidebarTab
} // playerSidebarLogic
@@ -564,6 +573,9 @@ export interface experimentReplayTabLogicActions {
applyDeepLink: (link: ExperimentRecordingsDeepLink) => {
link: ExperimentRecordingsDeepLink
}
+ linkedScannerOpened: (scannerType: ScannerTypeEnumApi) => {
+ scannerType: ScannerTypeEnumApi
+ }
listEmptyActionClicked: (action: ExperimentRecordingsEmptyAction) => {
action: ExperimentRecordingsEmptyAction
}
@@ -883,12 +895,16 @@ export const experimentReplayTabLogic = kea<experimentReplayTabLogicType>([
// Read for the report only. The playlist sends the setting to the endpoint itself, so
// the tab must not apply it a second time.
['hideViewedRecordings'],
+ lemonBannerLogic({ dismissKey: SCANNER_SET_UP_DISMISS_KEY }),
+ ['isDismissed as scannerSetUpDismissed'],
],
// Mounts the sidebar singleton for this tab's lifetime, so the default below outlives the
// player remounting as the viewer moves between recordings in the playlist.
actions: [
playerSidebarLogic,
['setDefaultTab'],
+ lemonBannerLogic({ dismissKey: SCANNER_SET_UP_DISMISS_KEY }),
+ ['dismiss as dismissScannerSetUp'],
// The health of a tab view is only known once the linkability check resolves, so the
// view is reported off these rather than from `afterMount`.
viewRecordingsLinkabilityLogic({ experiment: props.experiment }),
@@ -938,6 +954,7 @@ export const experimentReplayTabLogic = kea<experimentReplayTabLogicType>([
prefetchSessionContexts: (sessionIds: string[]) => ({ sessionIds }),
reportTabViewed: true,
scannerCrossSellClicked: true,
+ linkedScannerOpened: (scannerType: ScannerTypeEnumApi) => ({ scannerType }),
}),
loaders(({ values, props, actions }) => ({
sessionBucket: [
@@ -2202,7 +2219,38 @@ export const experimentReplayTabLogic = kea<experimentReplayTabLogicType>([
cache.reportedTabView = true
reportExperimentRecordingsTabViewed(props.experiment.id, values.tabViewContext)
},
+ // Once per tab visit: which Replay vision entry point the visitor saw, so a dismissal or a
+ // click can be read against how often each one was shown.
+ loadLinkedScannersSuccess: ({ linkedScanners }) => {
+ if (cache.scannerEntryPointReported) {
+ return
+ }
+ cache.scannerEntryPointReported = true
+ posthog.capture('experiment recordings scanner entry point shown', {
+ experiment_id: props.experiment.id,
+ state:
+ linkedScanners.length > 0
+ ? 'scanners_listed'
+ : values.scannerSetUpDismissed
+ ? 'set_up_dismissed'
+ : 'set_up_offered',
+ scanner_count: linkedScanners.length,
+ })
+ },
+ dismissScannerSetUp: () => {
+ posthog.capture('experiment recordings scanner set up dismissed', { experiment_id: props.experiment.id })
+ },
+ linkedScannerOpened: ({ scannerType }) => {
+ posthog.capture('experiment recordings scanner opened', {
+ experiment_id: props.experiment.id,
+ scanner_type: scannerType,
+ })
+ },
scannerCrossSellClicked: () => {
+ posthog.capture('experiment recordings scanner set up clicked', {
+ experiment_id: props.experiment.id,
+ has_scanners: values.linkedScanners.length > 0,
+ })
void addProductIntentForCrossSell({
from: ProductKey.EXPERIMENTS,
to: ProductKey.REPLAY_VISION,
@@ -2290,9 +2338,9 @@ export const experimentReplayTabLogic = kea<experimentReplayTabLogicType>([
// is disabled (not left to fail as a query error) when it can't, and the caption knows
// whether evidence is the stamped-property fallback. A Postgres-only read on the backend.
actions.loadInSessionExposure()
- // 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]) {
+ // Only the experiment scanner 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_EXPERIMENT_SCANNER]) {
actions.loadLinkedScanners()
}
diff --git a/frontend/src/scenes/experiments/ExperimentWizard/steps/AnalyticsStep.tsx b/frontend/src/scenes/experiments/ExperimentWizard/steps/AnalyticsStep.tsx
index af88936ed5c4..ab13ca7a86a1 100644
--- a/frontend/src/scenes/experiments/ExperimentWizard/steps/AnalyticsStep.tsx
+++ b/frontend/src/scenes/experiments/ExperimentWizard/steps/AnalyticsStep.tsx
@@ -1,7 +1,7 @@
import { useActions, useValues } from 'kea'
import { useState } from 'react'
-import { IconInfo } from '@posthog/icons'
+import { IconInfo, IconSparkles } from '@posthog/icons'
import { LemonButton, LemonCheckbox, Tooltip } from '@posthog/lemon-ui'
import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
@@ -124,10 +124,19 @@ function ReplayVisionScannerCheckbox(): JSX.Element {
data-attr="experiment-create-replay-vision-scanner"
label={
<div className="py-3">
- <div className="font-semibold">Watch participant behavior with Replay Vision</div>
+ <div className="flex items-center gap-2 font-semibold">
+ {experimentScanners ? (
+ <>
+ <IconSparkles className="text-ai" />
+ Compare what users do in each variant
+ </>
+ ) : (
+ 'Watch participant behavior with Replay Vision'
+ )}
+ </div>
<div className="mt-1 font-normal text-sm text-muted">
{experimentScanners
- ? 'Set up a scanner that summarizes what participants do in each variant after exposure. It turns on when you launch the experiment and stops when the experiment ends. Until launch, nothing is scanned and no credits are used, and you can adjust its prompt, filters, and sampling.'
+ ? 'Set up an experiment scanner. It uses Replay vision to summarize the recordings of exposed users and shows each variant side by side. It turns on when you launch the experiment and stops when the experiment ends. Until launch, nothing is scanned and no credits are used.'
: 'Set up a scanner that classifies what participants do after experiment exposure. It is created turned off, so nothing is scanned and no credits are used until you turn it on. You can adjust its prompt, filters, and sampling first. A scanner keeps running after the experiment ends, so turn it off when you are done.'}
</div>
{/* Per-session price only: a monthly projection needs the 30-day recording history the
diff --git a/frontend/src/scenes/experiments/stories/ExperimentReplayScannerBacklink.stories.tsx b/frontend/src/scenes/experiments/stories/ExperimentReplayScannerBacklink.stories.tsx
index d3c341231b3e..b5505463e9ae 100644
--- a/frontend/src/scenes/experiments/stories/ExperimentReplayScannerBacklink.stories.tsx
+++ b/frontend/src/scenes/experiments/stories/ExperimentReplayScannerBacklink.stories.tsx
@@ -8,8 +8,39 @@ 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 scanners = [
+ {
+ id: '0192aaaa-0000-7000-8000-000000000001',
+ name: 'experiment-funnel-metric (#15)',
+ scanner_type: 'experiment',
+ observations_this_month: 128,
+ },
+ {
+ id: '0192bbbb-0000-7000-8000-000000000002',
+ name: 'Signup drop-off',
+ scanner_type: 'summarizer',
+ observations_this_month: 12,
+ },
+]
+
+const recordingsTabMocks = (watching: typeof scanners): ReturnType<typeof mswDecorator> =>
+ 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/': [],
+ '/api/projects/:team_id/vision/scanners/': { count: watching.length, results: watching },
+ },
+ post: {
+ '/api/environments/:team_id/query/:kind': [200, { results: [] }],
+ },
+ })
+
+// A launched experiment's Recordings tab, where Replay vision offers an experiment scanner, or lists
+// the scanners already watching the experiment.
const meta: Meta = {
component: App,
title: 'Scenes-App/Experiments',
@@ -18,46 +49,20 @@ const meta: Meta = {
viewMode: 'story',
mockDate: '2025-06-01',
pageUrl: urls.experiment(EXPERIMENT_WITH_FUNNEL_METRIC.id) + '?tab=recordings',
- featureFlags: [FEATURE_FLAGS.VISION_ENTRYPOINT_EXPERIMENTS],
+ featureFlags: [FEATURE_FLAGS.VISION_EXPERIMENT_SCANNER],
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) }
+export const ExperimentReplayScannerBacklink: Story = {
+ decorators: [recordingsTabMocks(scanners)],
+ play: makeDelay(700),
+}
+
+export const ExperimentReplayScannerCrossSell: Story = {
+ decorators: [recordingsTabMocks([])],
+ play: makeDelay(700),
+}