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): UX improvements recordings integration (#72228)

Marcel Poelkerba16100d76f7
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index ce28e2484ced..df5f873ada00 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -4939,9 +4939,9 @@ snapshots:
replay-overview-tab--wide-overview-tab--light:
hash: v1.k794b7964.deb71477c91ae3fb89eaa9c6c9a45e665db4fa8363df4de30b3737c655930825.n5T9fmKBWN7qXDwbX9sYPEtdRgVYiaUgrJfvtail2tg
replay-overview-tab-experiments--default--dark:
- hash: v1.k794b7964.25a125f1ccda9f810a1e6d396031977f27bdb0871bccaa500afbbdfe495d551d.1yCi_OiCfAFcalukt75bILwNnkYCfyi07maDMAtzqYA
+ hash: v1.k794b7964.33a861df26de2c58bb3f682709f548f3c18e4055068e53210d6bf0eed290f3b9.n3yoSXnVRzJVlrCCoLNytIv7UTIIaJA1fb-ApkS6_rE
replay-overview-tab-experiments--default--light:
- hash: v1.k794b7964.ab0755b8da5c67099503a8ae53ee63e34c0ea513dd3b7fd1baa0905067a7ea01.iSLqrIDxgzlGZ1DT7vgBu8DtMPs56SESNRW7avoHa8g
+ hash: v1.k794b7964.d9bf55d955df06da692463ec7d1526a899103567f37d68e807c2c3b94c575e78.dRJfZZ5apQCOXa20PcujmkCflmN-X733GYazCRK2PRg
replay-overview-tab-experiments--empty--dark:
hash: v1.k794b7964.13e51a486b40a1455fde0075af333e3dff21f25491d06cc59ab10c24200eb1d2.Fn0OHVeRm39HLB3-xcZUZavR375CxuNraJZdmfxTS-U
replay-overview-tab-experiments--empty--light:
diff --git a/frontend/src/scenes/experiments/ExperimentView/ExperimentReplayTab.tsx b/frontend/src/scenes/experiments/ExperimentView/ExperimentReplayTab.tsx
index 72cd91a01bf7..f3f5c0eebe95 100644
--- a/frontend/src/scenes/experiments/ExperimentView/ExperimentReplayTab.tsx
+++ b/frontend/src/scenes/experiments/ExperimentView/ExperimentReplayTab.tsx
@@ -9,6 +9,7 @@ import { Experiment } from '~/types'
import { isLaunched } from '../experimentStatus'
import { EXPOSURE_UNLINKABLE_REASON } from '../viewRecordingsLinkabilityLogic'
import { experimentReplayTabLogic } from './experimentReplayTabLogic'
+import { VariantTag } from './VariantTag'
// LemonSegmentedButton values must be strings; the logic stores null for "All". Variant keys are
// restricted to [a-zA-Z0-9_-], so the '$' prefix guarantees no collision with a real variant — a
@@ -37,7 +38,7 @@ export function ExperimentReplayTab({ experiment }: { experiment: Experiment }):
onChange={(value) => setSelectedVariantKey(value === ALL_VARIANTS ? null : value)}
options={[
{ value: ALL_VARIANTS, label: 'All' },
- ...variantKeys.map((key) => ({ value: key, label: key })),
+ ...variantKeys.map((key) => ({ value: key, label: <VariantTag variantKey={key} /> })),
]}
/>
</div>
diff --git a/frontend/src/scenes/session-recordings/__mocks__/experiment_session_context.ts b/frontend/src/scenes/session-recordings/__mocks__/experiment_session_context.ts
index 9f8b7b53997f..1a616faa6c29 100644
--- a/frontend/src/scenes/session-recordings/__mocks__/experiment_session_context.ts
+++ b/frontend/src/scenes/session-recordings/__mocks__/experiment_session_context.ts
@@ -18,7 +18,8 @@ export const makeExperimentSessionContextItem = (
...overrides,
})
-/** One of each interesting state: single variant, multi-variant warning, no in-session exposure event. */
+/** One of each interesting state: seen-and-jumpable, multi-variant warning, seen-but-out-of-window,
+ * carried-over assignment. The recording window is 14:46:20–14:46:32 (see recording_meta mock). */
export const experimentSessionContextResponse: ExperimentSessionContextResponseApi = {
session_id: 'experiment-context-session',
results: [
@@ -31,6 +32,15 @@ export const experimentSessionContextResponse: ExperimentSessionContextResponseA
variants_seen: ['control', 'test'],
multiple_variants: true,
}),
+ makeExperimentSessionContextItem({
+ experiment_id: 104,
+ experiment_name: 'Search bar placement',
+ flag_key: 'search-bar-placement',
+ variant: 'control',
+ variants_seen: ['control'],
+ // Exposure captured just before the recording's playable range — seen, but nothing to jump to.
+ first_exposure_timestamp: '2023-05-01T14:45:00.000000Z',
+ }),
makeExperimentSessionContextItem({
experiment_id: 103,
experiment_name: 'Onboarding checklist',
diff --git a/frontend/src/scenes/session-recordings/player/player-meta/sessionRecordingExperimentContextLogic.test.ts b/frontend/src/scenes/session-recordings/player/player-meta/sessionRecordingExperimentContextLogic.test.ts
index 87288b19ad3e..464e30a47db5 100644
--- a/frontend/src/scenes/session-recordings/player/player-meta/sessionRecordingExperimentContextLogic.test.ts
+++ b/frontend/src/scenes/session-recordings/player/player-meta/sessionRecordingExperimentContextLogic.test.ts
@@ -6,6 +6,7 @@ import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'
+import { makeExperimentSessionContextItem } from '../../__mocks__/experiment_session_context'
import { sessionRecordingExperimentContextLogic } from './sessionRecordingExperimentContextLogic'
const mockResponse = {
@@ -85,6 +86,65 @@ describe('sessionRecordingExperimentContextLogic', () => {
})
})
+ it('orders seen experiments by exposure time, breaking ties on signal rank then name', async () => {
+ setFlagEnabled(true)
+ useMocks({
+ get: {
+ '/api/projects/:team_id/experiments/session_context/': {
+ session_id: 'session-4',
+ // Deliberately shuffled, and named so a signal-rank-first sort would order them
+ // differently: a control exposed first must still lead a later multi-variant.
+ results: [
+ makeExperimentSessionContextItem({
+ experiment_id: 1,
+ experiment_name: 'Multi late',
+ variants_seen: ['control', 'test'],
+ multiple_variants: true,
+ first_exposure_timestamp: '2026-07-01T10:00:30Z',
+ }),
+ makeExperimentSessionContextItem({
+ experiment_id: 2,
+ experiment_name: 'Control early',
+ variant: 'control',
+ first_exposure_timestamp: '2026-07-01T10:00:00Z',
+ }),
+ makeExperimentSessionContextItem({
+ experiment_id: 3,
+ experiment_name: 'Enrolled only',
+ first_exposure_timestamp: null,
+ }),
+ makeExperimentSessionContextItem({
+ experiment_id: 4,
+ experiment_name: 'Treatment mid',
+ variant: 'test',
+ first_exposure_timestamp: '2026-07-01T10:00:10Z',
+ }),
+ // Ties with 'Control early' — several flags evaluated together at the start.
+ makeExperimentSessionContextItem({
+ experiment_id: 5,
+ experiment_name: 'Tie multi',
+ variants_seen: ['control', 'test'],
+ multiple_variants: true,
+ first_exposure_timestamp: '2026-07-01T10:00:00Z',
+ }),
+ ],
+ },
+ },
+ })
+ logic = sessionRecordingExperimentContextLogic({ sessionRecordingId: 'session-4' })
+ logic.mount()
+
+ await expectLogic(logic).toDispatchActions(['loadExperimentContextSuccess'])
+
+ expect(logic.values.seenItems.map((item) => item.experiment_name)).toEqual([
+ 'Tie multi',
+ 'Control early',
+ 'Treatment mid',
+ 'Multi late',
+ ])
+ expect(logic.values.enrolledItems.map((item) => item.experiment_name)).toEqual(['Enrolled only'])
+ })
+
it('loads once the feature flag arrives after mount', async () => {
setFlagEnabled(false)
logic = sessionRecordingExperimentContextLogic({ sessionRecordingId: 'session-1' })
diff --git a/frontend/src/scenes/session-recordings/player/player-meta/sessionRecordingExperimentContextLogic.ts b/frontend/src/scenes/session-recordings/player/player-meta/sessionRecordingExperimentContextLogic.ts
index ce292d768188..9a246dc61508 100644
--- a/frontend/src/scenes/session-recordings/player/player-meta/sessionRecordingExperimentContextLogic.ts
+++ b/frontend/src/scenes/session-recordings/player/player-meta/sessionRecordingExperimentContextLogic.ts
@@ -3,6 +3,7 @@ import { loaders } from 'kea-loaders'
import { subscriptions } from 'kea-subscriptions'
import { FEATURE_FLAGS } from 'lib/constants'
+import { dayjs } from 'lib/dayjs'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { teamLogic } from 'scenes/teamLogic'
@@ -30,6 +31,12 @@ export function experimentSignalRank(item: ExperimentSessionContextItemApi): num
return isControlVariant(item) ? 2 : 1
}
+// Parsed rather than string-compared: ordering by exposure is only correct if two timestamps written in
+// different shapes (offset, sub-second precision) still compare as the instants they represent.
+export function exposureMs(item: ExperimentSessionContextItemApi): number {
+ return item.first_exposure_timestamp ? dayjs(item.first_exposure_timestamp).valueOf() : 0
+}
+
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface sessionRecordingExperimentContextLogicValues {
featureFlags: FeatureFlagsSet // featureFlagLogic
@@ -135,6 +142,9 @@ export const sessionRecordingExperimentContextLogic = kea<sessionRecordingExperi
experimentContext?.results ?? [],
],
// Experiments with an exposure event during this recording — these have a moment on the timeline to jump to.
+ // Ordered by when the exposure happens so the list reads along the playback timeline. Exposures that
+ // share a timestamp (typically several flags evaluated together at the very start) fall back to signal
+ // rank, then name, so the order stays stable rather than depending on backend result order.
seenItems: [
(s) => [s.experimentItems],
(experimentItems: ExperimentSessionContextItemApi[]): ExperimentSessionContextItemApi[] =>
@@ -142,8 +152,9 @@ export const sessionRecordingExperimentContextLogic = kea<sessionRecordingExperi
.filter((item) => item.first_exposure_timestamp != null)
.sort(
(a, b) =>
+ exposureMs(a) - exposureMs(b) ||
experimentSignalRank(a) - experimentSignalRank(b) ||
- (a.first_exposure_timestamp ?? '').localeCompare(b.first_exposure_timestamp ?? '')
+ a.experiment_name.localeCompare(b.experiment_name)
),
],
// Experiments the person is enrolled in but with no exposure event in this session — the variant
diff --git a/frontend/src/scenes/session-recordings/player/sidebar/PlayerSidebarExperimentsSection.tsx b/frontend/src/scenes/session-recordings/player/sidebar/PlayerSidebarExperimentsSection.tsx
index 41b4d14deccd..4f7798627471 100644
--- a/frontend/src/scenes/session-recordings/player/sidebar/PlayerSidebarExperimentsSection.tsx
+++ b/frontend/src/scenes/session-recordings/player/sidebar/PlayerSidebarExperimentsSection.tsx
@@ -8,6 +8,7 @@ import { LemonCollapse } from 'lib/lemon-ui/LemonCollapse'
import { LemonTag, LemonTagType } from 'lib/lemon-ui/LemonTag'
import { Link } from 'lib/lemon-ui/Link'
import { Tooltip } from 'lib/lemon-ui/Tooltip'
+import { colonDelimitedDuration } from 'lib/utils/durations'
import { addProductIntentForCrossSell } from 'lib/utils/product-intents'
import { urls } from 'scenes/urls'
@@ -62,6 +63,67 @@ function OpenExperimentButton({ item }: { item: ExperimentSessionContextItemApi
)
}
+const OUT_OF_WINDOW_TOOLTIP =
+ "The exposure was captured just outside this recording's playable range, so there's no moment to jump to."
+
+// Position of the exposure within the recording, so the list's chronological order is legible rather than
+// implied. Deliberately always relative (not the player's Relative/UTC/device setting like the inspector's
+// ItemTimeDisplay): "where in this recording" is the whole point here, and an absolute date would not fit
+// the sidebar's width. An exposure captured before the recording starts clamps to zero — the row's tooltip
+// is what explains that it landed outside the playable range.
+function ExposureTime({ timeInRecording }: { timeInRecording: number }): JSX.Element {
+ return (
+ <span className="text-secondary text-xs tabular-nums shrink-0 min-w-10 text-right">
+ {colonDelimitedDuration(Math.max(0, timeInRecording) / 1000, null)}
+ </span>
+ )
+}
+
+function ExperimentContextRow({
+ item,
+ onSeek,
+ outOfWindow,
+ timeInRecording,
+}: {
+ item: ExperimentSessionContextItemApi
+ onSeek?: () => void
+ outOfWindow?: boolean
+ timeInRecording?: number | null
+}): JSX.Element {
+ let name: JSX.Element
+ if (onSeek) {
+ name = (
+ <Link
+ title="Jump to when this session matched the experiment's exposure criteria"
+ onClick={onSeek}
+ data-attr="replay-experiment-context-jump-to-first-exposure"
+ >
+ {item.experiment_name}
+ </Link>
+ )
+ } else if (outOfWindow) {
+ name = (
+ <Tooltip title={OUT_OF_WINDOW_TOOLTIP}>
+ <span>{item.experiment_name}</span>
+ </Tooltip>
+ )
+ } else {
+ name = <span>{item.experiment_name}</span>
+ }
+
+ // The name lives in its own flex-1 truncate box so the variant tag and open-experiment icon
+ // stay right-aligned whether the name is a plain span or a Link (a Link with no `to` renders a
+ // button wrapped in a non-flex span, which would otherwise let its tag hug the text).
+ return (
+ <div className="flex flex-row items-center gap-x-2 min-w-0">
+ {timeInRecording != null ? <ExposureTime timeInRecording={timeInRecording} /> : null}
+ <div className="flex-1 min-w-0 truncate">{name}</div>
+ <VariantTag item={item} />
+ <OpenExperimentButton item={item} />
+ </div>
+ )
+}
+
export function PlayerSidebarExperimentsSection(): JSX.Element | null {
const { logicProps, sessionPlayerData } = useValues(sessionRecordingPlayerLogic)
const { seekToTimestamp } = useActions(sessionRecordingPlayerLogic)
@@ -99,23 +161,23 @@ export function PlayerSidebarExperimentsSection(): JSX.Element | null {
recordingEndMs != null &&
exposedAtMs >= recordingStartMs &&
exposedAtMs <= recordingEndMs
+ // Distinguish "seen but outside the window" (worth a tooltip) from "bounds not known
+ // yet" (transient, no tooltip) so we never explain a non-jump we can't actually vouch for.
+ const outOfWindow =
+ exposedAtMs != null &&
+ recordingStartMs != null &&
+ recordingEndMs != null &&
+ (exposedAtMs < recordingStartMs || exposedAtMs > recordingEndMs)
return (
- <div key={item.experiment_id} className="flex flex-row items-center gap-x-2 min-w-0">
- {canSeek ? (
- <Link
- className="truncate flex-1 min-w-0"
- title="Jump to when this session matched the experiment's exposure criteria"
- onClick={() => exposedAtMs != null && seekToTimestamp(exposedAtMs)}
- data-attr="replay-experiment-context-jump-to-first-exposure"
- >
- {item.experiment_name}
- </Link>
- ) : (
- <span className="truncate flex-1 min-w-0">{item.experiment_name}</span>
- )}
- <VariantTag item={item} />
- <OpenExperimentButton item={item} />
- </div>
+ <ExperimentContextRow
+ key={item.experiment_id}
+ item={item}
+ onSeek={canSeek && exposedAtMs != null ? () => seekToTimestamp(exposedAtMs) : undefined}
+ outOfWindow={outOfWindow}
+ timeInRecording={
+ exposedAtMs != null && recordingStartMs != null ? exposedAtMs - recordingStartMs : null
+ }
+ />
)
})}
@@ -130,14 +192,7 @@ export function PlayerSidebarExperimentsSection(): JSX.Element | null {
content: (
<div className="flex flex-col gap-y-1">
{enrolledItems.map((item) => (
- <div
- key={item.experiment_id}
- className="flex flex-row items-center gap-x-2 min-w-0"
- >
- <span className="truncate flex-1 min-w-0">{item.experiment_name}</span>
- <VariantTag item={item} />
- <OpenExperimentButton item={item} />
- </div>
+ <ExperimentContextRow key={item.experiment_id} item={item} />
))}
</div>
),