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.

fix(replay-vision): open the experiment entry point on the experiment type (#118214)

Kim Svatos Dugan7c8883cc2286
diff --git a/frontend/src/scenes/experiments/ExperimentForm/createExperimentLogic.test.ts b/frontend/src/scenes/experiments/ExperimentForm/createExperimentLogic.test.ts
index e8fa4a2c476a..54751eb8b10f 100644
--- a/frontend/src/scenes/experiments/ExperimentForm/createExperimentLogic.test.ts
+++ b/frontend/src/scenes/experiments/ExperimentForm/createExperimentLogic.test.ts
@@ -252,7 +252,7 @@ describe('createExperimentLogic', () => {
button.action()
// The retry must reopen the experiment scanner wizard on this experiment, not the generic
// template list, or the person starts over without the experiment.
- expect(routerPushSpy).toHaveBeenLastCalledWith('/replay-vision/new/template?experiment=123')
+ expect(routerPushSpy).toHaveBeenLastCalledWith('/replay-vision/new/details?experiment=123')
expect(captureExceptionSpy).toHaveBeenCalledTimes(shouldCapture ? 1 : 0)
captureExceptionSpy.mockRestore()
})
diff --git a/frontend/src/scenes/experiments/ExperimentForm/createExperimentLogic.ts b/frontend/src/scenes/experiments/ExperimentForm/createExperimentLogic.ts
index c557eecb32db..fe17d6f0d124 100644
--- a/frontend/src/scenes/experiments/ExperimentForm/createExperimentLogic.ts
+++ b/frontend/src/scenes/experiments/ExperimentForm/createExperimentLogic.ts
@@ -539,7 +539,7 @@ export const createExperimentLogic = kea<createExperimentLogicType>([
action: () =>
router.actions.push(
combineUrl(
- urls.replayVisionScannerTemplate('new'),
+ urls.replayVisionScannerDetails('new'),
experimentScannerParams({
experimentId: response.id as number,
variantKey: null,
diff --git a/frontend/src/scenes/experiments/ExperimentView/ExperimentScannerEntryPoint.tsx b/frontend/src/scenes/experiments/ExperimentView/ExperimentScannerEntryPoint.tsx
index b59f8c8beba5..b07b8d29a010 100644
--- a/frontend/src/scenes/experiments/ExperimentView/ExperimentScannerEntryPoint.tsx
+++ b/frontend/src/scenes/experiments/ExperimentView/ExperimentScannerEntryPoint.tsx
@@ -180,8 +180,9 @@ export function ExperimentScannerEntryPoint({
const { linkedScanners, linkedScannersLoading, variantKeys, scannerSetUpDismissed } = useValues(logic)
const { scannerCrossSellClicked, dismissScannerSetUp, linkedScannerOpened } = useActions(logic)
+ // Straight into the wizard: the experiment fixes the type, so there is no template to pick.
const setUpUrl = combineUrl(
- urls.replayVisionScannerTemplate('new'),
+ urls.replayVisionScannerDetails('new'),
experimentScannerParams({ experimentId: experiment.id as number, variantKey })
).url
diff --git a/products/replay_vision/frontend/replay_scanners/ScannerEditorScene.tsx b/products/replay_vision/frontend/replay_scanners/ScannerEditorScene.tsx
index e557d75d1909..881a14a8e806 100644
--- a/products/replay_vision/frontend/replay_scanners/ScannerEditorScene.tsx
+++ b/products/replay_vision/frontend/replay_scanners/ScannerEditorScene.tsx
@@ -124,8 +124,14 @@ export function ScannerEditorSceneComponent(): JSX.Element {
const scannerLogic = replayScannerLogic({ id: scannerId })
useAttachedLogic(scannerLogic, scannerEditorSceneLogic)
- const { scanner, scannerLoading, isScannerSubmitting, stepErrors, linkedExperimentContext } =
- useValues(scannerLogic)
+ const {
+ scanner,
+ scannerLoading,
+ isScannerSubmitting,
+ stepErrors,
+ linkedExperimentContext,
+ lockedToExperimentScanner,
+ } = useValues(scannerLogic)
const { submitScanner } = useActions(scannerLogic)
// An experiment cross-sell entry point has already said what to watch and deep-linked the
@@ -189,9 +195,11 @@ export function ScannerEditorSceneComponent(): JSX.Element {
onStepClick={goToStep}
stepErrors={stepErrors}
disabledSteps={
- isNew
- ? undefined
- : { template: 'A saved scanner keeps the template it was created from' }
+ !isNew
+ ? { template: 'A saved scanner keeps the template it was created from' }
+ : lockedToExperimentScanner
+ ? { template: 'A scanner started from an experiment is an experiment scanner' }
+ : undefined
}
className="flex-wrap justify-center gap-y-1"
aria-label="Scanner editor progress"
@@ -363,10 +371,10 @@ function SelfDrivingOutcomesLine({ scannerId }: { scannerId: string }): JSX.Elem
function ConfigureStep(): JSX.Element {
const { scannerId } = useValues(scannerEditorSceneLogic)
- const { scanner, isNew, goalDraft } = useValues(replayScannerLogic({ id: scannerId }))
+ const { scanner, isNew, goalDraft, lockedToExperimentScanner } = useValues(replayScannerLogic({ id: scannerId }))
const { setScannerType } = useActions(replayScannerLogic({ id: scannerId }))
const { searchParams } = useValues(router)
- const isTypeSelectable = isNew && !searchParams.template
+ const isTypeSelectable = isNew && !searchParams.template && !lockedToExperimentScanner
const experimentScanners = useFeatureFlag('VISION_EXPERIMENT_SCANNER')
if (!scanner) {
@@ -502,7 +510,9 @@ function EditorFooter({
onAdvance: () => void
onSave: () => void
}): JSX.Element {
- const { scanner, durationValidationError, hasUnsavedChanges } = useValues(replayScannerLogic({ id: scannerId }))
+ const { scanner, durationValidationError, hasUnsavedChanges, lockedToExperimentScanner } = useValues(
+ replayScannerLogic({ id: scannerId })
+ )
const { searchParams } = useValues(router)
const { discardScannerDraft } = useActions(replayScannerLogic({ id: scannerId }))
const { dataProcessingAccepted, dataProcessingApprovalDisabledReason } = useValues(aiConsentLogic)
@@ -513,7 +523,7 @@ function EditorFooter({
const canApproveConsent = !dataProcessingApprovalDisabledReason
const stepIndex = SCANNER_EDITOR_STEPS.indexOf(step)
const previous = stepIndex > 0 ? SCANNER_EDITOR_STEPS[stepIndex - 1] : null
- const prevStep = previous === 'template' && !isNew ? null : previous
+ const prevStep = previous === 'template' && (!isNew || lockedToExperimentScanner) ? null : previous
const nextStep = stepIndex < SCANNER_EDITOR_STEPS.length - 1 ? SCANNER_EDITOR_STEPS[stepIndex + 1] : null
// A broken duration filter blocks the save, but only from the triggers step onward: gating an
// earlier step's button on it blocks the wizard with a reason nothing on screen explains. RBAC
diff --git a/products/replay_vision/frontend/replay_scanners/replayScannerLogic.test.ts b/products/replay_vision/frontend/replay_scanners/replayScannerLogic.test.ts
index 806219971d46..cd5c2596470c 100644
--- a/products/replay_vision/frontend/replay_scanners/replayScannerLogic.test.ts
+++ b/products/replay_vision/frontend/replay_scanners/replayScannerLogic.test.ts
@@ -184,6 +184,8 @@ describe('replayScannerLogic', () => {
experiment_targeting: null,
})
expect(logic.values.scanner?.query).toMatchObject({ events: query.events })
+ // The experiment fixes the type, so the wizard offers no other type and no template step.
+ expect(logic.values.lockedToExperimentScanner).toBe(true)
})
})
@@ -477,6 +479,7 @@ describe('replayScannerLogic', () => {
expect(logic.values.experimentContext).toMatchObject({ experiment: { id: 7 } })
// The goal page and template step promise to keep watching only a linked experiment.
expect(logic.values.linkedExperimentContext).toBeNull()
+ expect(logic.values.lockedToExperimentScanner).toBe(false)
router.actions.push(urls.replayVisionScannerTemplate('new'))
await expectLogic(logic, () =>
@@ -916,6 +919,29 @@ describe('replayScannerLogic', () => {
expect(readScannerDraft(teamId)?.scanner.name).toBe('Drafted')
})
+ it('keeps an experiment entry locked when its draft is resumed', async () => {
+ featureFlagLogic.actions.setFeatureFlags([], { [FEATURE_FLAGS.VISION_EXPERIMENT_SCANNER]: true })
+ useMocks({
+ get: {
+ '/api/projects/:team/experiments/:id/': () => [200, { id: 7, name: 'Checkout redesign' }],
+ },
+ })
+ router.actions.push(urls.replayVisionScannerDetails('new'), { experiment: '7' })
+ await expectLogic(logic, () => logic.actions.loadScanner()).toFinishAllListeners()
+ logic.actions.setScannerValues({ name: 'Checkout scan' })
+ expect(logic.values.lockedToExperimentScanner).toBe(true)
+ logic.unmount()
+
+ // A plain entry resumes the draft, so only the stored link can restore the lock.
+ router.actions.push(urls.replayVisionScannerDetails('new'))
+ logic = replayScannerLogic({ id: 'new' })
+ logic.mount()
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(logic.values.scanner).toMatchObject({ name: 'Checkout scan', scanner_type: 'experiment' })
+ expect(logic.values.lockedToExperimentScanner).toBe(true)
+ })
+
it('preserves an existing draft when the wizard is entered from a ?filters= deep link', async () => {
// The prefill outranks the draft for this entry but must not delete it; without the
// restoringDraft guard, persistDraft sees scanner === originalScanner and clears it.
diff --git a/products/replay_vision/frontend/replay_scanners/replayScannerLogic.ts b/products/replay_vision/frontend/replay_scanners/replayScannerLogic.ts
index e7b0c01da311..b41984215ea3 100644
--- a/products/replay_vision/frontend/replay_scanners/replayScannerLogic.ts
+++ b/products/replay_vision/frontend/replay_scanners/replayScannerLogic.ts
@@ -517,6 +517,7 @@ export interface replayScannerLogicValues {
isScannerSubmitting: boolean
isScannerValid: boolean
linkedExperimentContext: ExperimentScannerContext | null
+ lockedToExperimentScanner: boolean
observationBackfillFilter: string | null
observationDateFrom: string | null
observationDateTo: string | null
@@ -696,8 +697,8 @@ export interface replayScannerLogicActions {
tagSuggestions: TagSuggestionApi[]
payload?: any
}
- rebuildExperimentContext: () => {
- value: true
+ rebuildExperimentContext: (linkedExperimentId?: number | null) => {
+ linkedExperimentId: number | null
}
refreshObservations: () => {
value: true
@@ -960,6 +961,10 @@ export interface replayScannerLogicMeta {
experimentContext: ExperimentScannerContext | null,
experimentContextLinked: boolean
) => ExperimentScannerContext | null
+ lockedToExperimentScanner: (
+ linkedExperimentContext: ExperimentScannerContext | null,
+ scanner: ScannerFormValues
+ ) => boolean
hasUnsavedChanges: (scanner: ScannerFormValues, originalScanner: ScannerFormValues | null) => boolean
hasObservationsInFlight: (observationStatsApi: ObservationStatsApi | null) => boolean
hasActiveObservationFilters: (
@@ -1030,7 +1035,8 @@ export const replayScannerLogic = kea<replayScannerLogicType>([
setExperimentVariant: (variantKey: string | null) => ({ variantKey }),
setScannerExperiment: (experimentId: number | null) => ({ experimentId }),
detachExperimentContext: true,
- rebuildExperimentContext: true,
+ // Pass the experiment the wizard was entered from to restore that link with the context.
+ rebuildExperimentContext: (linkedExperimentId: number | null = null) => ({ linkedExperimentId }),
saveAffectedCohort: (windowDays: number, qualifier: AffectedCohortQualifier = {}) => ({
windowDays,
qualifier,
@@ -1739,6 +1745,13 @@ export const replayScannerLogic = kea<replayScannerLogicType>([
experimentContextLinked: boolean
): ExperimentScannerContext | null => (experimentContextLinked ? experimentContext : null),
],
+ // Started from an experiment as an experiment scanner: the experiment fixes the type, so the
+ // wizard offers no other type and no template step.
+ lockedToExperimentScanner: [
+ (s) => [s.linkedExperimentContext, s.scanner],
+ (linkedExperimentContext: ExperimentScannerContext | null, scanner: ScannerFormValues | null): boolean =>
+ !!linkedExperimentContext && scanner?.scanner_type === 'experiment',
+ ],
hasUnsavedChanges: [
(s) => [s.scanner, s.originalScanner],
(scanner: ReplayScanner | null, original: ReplayScanner | null): boolean => {
@@ -1956,7 +1969,12 @@ export const replayScannerLogic = kea<replayScannerLogicType>([
actions.setScannerDraftSavedAt(null)
return
}
- const savedAt = writeScannerDraft(teamId, values.scanner)
+ const linkedExperimentId = values.linkedExperimentContext?.experiment.id
+ const savedAt = writeScannerDraft(
+ teamId,
+ values.scanner,
+ typeof linkedExperimentId === 'number' ? linkedExperimentId : null
+ )
if (savedAt === null) {
// A failed write leaves any older draft behind; drop it so it can't resurrect stale edits.
clearScannerDraft()
@@ -2133,8 +2151,9 @@ export const replayScannerLogic = kea<replayScannerLogicType>([
actions.setScannerValues(draft.scanner)
actions.setScannerDraftSavedAt(draft.savedAt)
// A draft made from an experiment prefill carries targeting the
- // loadScannerSuccess above (a bare newScanner) didn't see.
- actions.rebuildExperimentContext()
+ // loadScannerSuccess above (a bare newScanner) didn't see. A draft started
+ // from an experiment link restores that link, so the wizard stays locked.
+ actions.rebuildExperimentContext(draft.linkedExperimentId)
}
} finally {
cache.restoringDraft = false
@@ -2193,7 +2212,7 @@ export const replayScannerLogic = kea<replayScannerLogicType>([
// from. The API hides the experiment from viewers denied it, so this never fetches an
// experiment the viewer can't see. Fails soft: without the context the scanner still
// edits normally.
- rebuildExperimentContext: async () => {
+ rebuildExperimentContext: async ({ linkedExperimentId }) => {
const scope = scannerExperimentScope(values.scanner)
if (!scope) {
// A card left over from earlier targeting would keep offering variants of an
@@ -2223,7 +2242,12 @@ export const replayScannerLogic = kea<replayScannerLogicType>([
// narrows to one variant through the card.
const variantKey =
values.scanner?.scanner_type === 'experiment' ? null : (current.variants?.[0] ?? null)
- actions.setExperimentContext({ experiment, variantKey })
+ const context = { experiment, variantKey }
+ if (linkedExperimentId === scope.experimentId) {
+ actions.linkExperimentContext(context)
+ } else {
+ actions.setExperimentContext(context)
+ }
} catch {
// The card simply doesn't render; targeting stays intact on the scanner.
}
diff --git a/products/replay_vision/frontend/replay_scanners/scannerDraft.ts b/products/replay_vision/frontend/replay_scanners/scannerDraft.ts
index 44543d111ccf..bde4c5d3804d 100644
--- a/products/replay_vision/frontend/replay_scanners/scannerDraft.ts
+++ b/products/replay_vision/frontend/replay_scanners/scannerDraft.ts
@@ -9,20 +9,28 @@ interface StoredScannerDraft {
teamId: number
savedAt: number
scanner: ScannerFormValues
+ // The experiment the wizard was entered from. Optional, so drafts saved without it still read.
+ linkedExperimentId?: number | null
}
export interface ScannerDraft {
scanner: ScannerFormValues
savedAt: number
+ linkedExperimentId: number | null
}
-export function writeScannerDraft(teamId: number, scanner: ScannerFormValues): number | null {
+export function writeScannerDraft(
+ teamId: number,
+ scanner: ScannerFormValues,
+ linkedExperimentId: number | null = null
+): number | null {
const savedAt = Date.now()
const draft: StoredScannerDraft = {
version: DRAFT_VERSION,
teamId,
savedAt,
scanner,
+ linkedExperimentId,
}
try {
localStorage.setItem(DRAFT_STORAGE_KEY, JSON.stringify(draft))
@@ -48,7 +56,11 @@ export function readScannerDraft(teamId: number): ScannerDraft | null {
) {
return null
}
- return { scanner: draft.scanner, savedAt: draft.savedAt }
+ return {
+ scanner: draft.scanner,
+ savedAt: draft.savedAt,
+ linkedExperimentId: typeof draft.linkedExperimentId === 'number' ? draft.linkedExperimentId : null,
+ }
} catch {
return null
}