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): Open recordings player on the overview tab instead of inspector for experiment context (#76021)

Marcel Poelkere1863eecaace
diff --git a/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.test.ts b/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.test.ts
index 428bf3f221a5..622b61115237 100644
--- a/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.test.ts
+++ b/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.test.ts
@@ -3,10 +3,17 @@ import { expectLogic } from 'kea-test-utils'
import api from 'lib/api'
import { FEATURE_FLAGS } from 'lib/constants'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+import { playerSidebarLogic } from 'scenes/session-recordings/player/sidebar/playerSidebarLogic'
import { ExperimentMetricType, NodeKind } from '~/queries/schema/schema-general'
import { initKeaTests } from '~/test/init'
-import { Experiment, FilterLogicalOperator, PropertyFilterType, PropertyOperator } from '~/types'
+import {
+ Experiment,
+ FilterLogicalOperator,
+ PropertyFilterType,
+ PropertyOperator,
+ SessionRecordingSidebarTab,
+} from '~/types'
import { experimentsSessionContextsCreate } from 'products/experiments/frontend/generated/api'
@@ -507,4 +514,20 @@ describe('experimentReplayTabLogic', () => {
])
withSaved.unmount()
})
+
+ it('lands the player sidebar on Overview, and hands it back when the tab goes away', () => {
+ // Held mounted across the unmount below, standing in for a player that outlives this tab —
+ // the only case in which the reset has anything to do.
+ const sidebar = playerSidebarLogic()
+ sidebar.mount()
+
+ // Recordings are opened from here to see what the experiment did to a session, which is what
+ // the Overview tab shows. Landing on Inspector instead hides it behind a click.
+ expect(sidebar.values.defaultTab).toBe(SessionRecordingSidebarTab.OVERVIEW)
+
+ logic.unmount()
+ expect(sidebar.values.defaultTab).toBe(SessionRecordingSidebarTab.INSPECTOR)
+
+ sidebar.unmount()
+ })
})
diff --git a/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.ts b/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.ts
index 365051e8c8ec..0e415f8efada 100644
--- a/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.ts
+++ b/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.ts
@@ -1,8 +1,22 @@
-import { MakeLogicType, actions, afterMount, connect, kea, key, listeners, path, props, reducers, selectors } from 'kea'
+import {
+ MakeLogicType,
+ actions,
+ afterMount,
+ beforeUnmount,
+ connect,
+ kea,
+ key,
+ listeners,
+ path,
+ props,
+ reducers,
+ selectors,
+} from 'kea'
import { FEATURE_FLAGS } from 'lib/constants'
import { FeatureFlagsSet, featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { addProductIntentForCrossSell } from 'lib/utils/product-intents'
+import { playerSidebarLogic } from 'scenes/session-recordings/player/sidebar/playerSidebarLogic'
import { DEFAULT_RECORDING_FILTERS } from 'scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic'
import { teamLogic } from 'scenes/teamLogic'
@@ -13,7 +27,13 @@ import {
ProductKey,
isExperimentRetentionMetric,
} from '~/queries/schema/schema-general'
-import { Experiment, FilterLogicalOperator, RecordingUniversalFilters, UniversalFiltersGroupValue } from '~/types'
+import {
+ Experiment,
+ FilterLogicalOperator,
+ RecordingUniversalFilters,
+ SessionRecordingSidebarTab,
+ UniversalFiltersGroupValue,
+} from '~/types'
import { experimentsSessionContextsCreate } from 'products/experiments/frontend/generated/api'
@@ -73,6 +93,9 @@ export interface experimentReplayTabLogicValues {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface experimentReplayTabLogicActions {
+ setDefaultTab: (tab: SessionRecordingSidebarTab) => {
+ tab: SessionRecordingSidebarTab
+ } // playerSidebarLogic
prefetchSessionContexts: (sessionIds: string[]) => {
sessionIds: string[]
}
@@ -144,6 +167,9 @@ export const experimentReplayTabLogic = kea<experimentReplayTabLogicType>([
teamLogic,
['currentProjectId'],
],
+ // 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']],
})),
actions({
setSelectedVariantKey: (variantKey: string | null) => ({ variantKey }),
@@ -413,7 +439,9 @@ export const experimentReplayTabLogic = kea<experimentReplayTabLogicType>([
}
},
})),
- afterMount(() => {
+ afterMount(({ actions }) => {
+ actions.setDefaultTab(SessionRecordingSidebarTab.OVERVIEW)
+
// Opening the tab is a session-replay cross-sell from experiments.
void addProductIntentForCrossSell({
from: ProductKey.EXPERIMENTS,
@@ -421,4 +449,9 @@ export const experimentReplayTabLogic = kea<experimentReplayTabLogicType>([
intent_context: ProductIntentContext.EXPERIMENT_VIEW_RECORDINGS,
})
}),
+ // The sidebar singleton normally unmounts alongside this logic and resets itself; this covers the
+ // case where another player keeps it mounted, so the experiment default doesn't leak to it.
+ beforeUnmount(({ actions }) => {
+ actions.setDefaultTab(SessionRecordingSidebarTab.INSPECTOR)
+ }),
])
diff --git a/frontend/src/scenes/session-recordings/player/sidebar/playerSidebarLogic.test.ts b/frontend/src/scenes/session-recordings/player/sidebar/playerSidebarLogic.test.ts
new file mode 100644
index 000000000000..99323b76e138
--- /dev/null
+++ b/frontend/src/scenes/session-recordings/player/sidebar/playerSidebarLogic.test.ts
@@ -0,0 +1,59 @@
+import { router } from 'kea-router'
+import { expectLogic } from 'kea-test-utils'
+
+import { initKeaTests } from '~/test/init'
+import { SessionRecordingSidebarTab } from '~/types'
+
+import { playerSidebarLogic } from './playerSidebarLogic'
+
+describe('playerSidebarLogic', () => {
+ let logic: ReturnType<typeof playerSidebarLogic.build>
+
+ beforeEach(() => {
+ initKeaTests()
+ logic = playerSidebarLogic()
+ logic.mount()
+ })
+
+ it('follows the host default until the viewer picks a tab, then keeps their pick', async () => {
+ await expectLogic(logic).toMatchValues({ activeTab: SessionRecordingSidebarTab.INSPECTOR })
+
+ await expectLogic(logic, () => {
+ logic.actions.setDefaultTab(SessionRecordingSidebarTab.OVERVIEW)
+ }).toMatchValues({ activeTab: SessionRecordingSidebarTab.OVERVIEW })
+
+ await expectLogic(logic, () => {
+ logic.actions.setTab(SessionRecordingSidebarTab.NETWORK_WATERFALL)
+ }).toMatchValues({ activeTab: SessionRecordingSidebarTab.NETWORK_WATERFALL })
+
+ // Hosts re-announce their default on every remount, so a default arriving after a pick must
+ // not drag the viewer off the tab they're on.
+ await expectLogic(logic, () => {
+ logic.actions.setDefaultTab(SessionRecordingSidebarTab.OVERVIEW)
+ }).toMatchValues({ activeTab: SessionRecordingSidebarTab.NETWORK_WATERFALL })
+ })
+
+ it('records a tab from the URL as the pick, even when a host default already matches it', async () => {
+ logic.actions.setDefaultTab(SessionRecordingSidebarTab.OVERVIEW)
+ router.actions.push('/replay', {
+ sessionRecordingId: 'abc',
+ tab: SessionRecordingSidebarTab.OVERVIEW,
+ })
+ await expectLogic(logic).toMatchValues({ selectedTab: SessionRecordingSidebarTab.OVERVIEW })
+
+ // Only sticks because the URL was taken as a pick. Had it been waved through for already
+ // matching the default, the tab would follow the host away instead of the link.
+ await expectLogic(logic, () => {
+ logic.actions.setDefaultTab(SessionRecordingSidebarTab.INSPECTOR)
+ }).toMatchValues({ activeTab: SessionRecordingSidebarTab.OVERVIEW })
+ })
+
+ it('keeps the host default out of the URL', () => {
+ logic.actions.setDefaultTab(SessionRecordingSidebarTab.OVERVIEW)
+ expect(router.values.searchParams).not.toHaveProperty('tab')
+
+ // The viewer's own pick is theirs to share, so that one does belong in the URL.
+ logic.actions.setTab(SessionRecordingSidebarTab.OVERVIEW)
+ expect(router.values.searchParams).toHaveProperty('tab', SessionRecordingSidebarTab.OVERVIEW)
+ })
+})
diff --git a/frontend/src/scenes/session-recordings/player/sidebar/playerSidebarLogic.ts b/frontend/src/scenes/session-recordings/player/sidebar/playerSidebarLogic.ts
index 4a8125a409d8..2103bac63de6 100644
--- a/frontend/src/scenes/session-recordings/player/sidebar/playerSidebarLogic.ts
+++ b/frontend/src/scenes/session-recordings/player/sidebar/playerSidebarLogic.ts
@@ -1,4 +1,4 @@
-import { MakeLogicType, actions, kea, path, reducers } from 'kea'
+import { MakeLogicType, actions, kea, path, reducers, selectors } from 'kea'
import { actionToUrl, router, urlToAction } from 'kea-router'
import { SessionRecordingSidebarTab } from '~/types'
@@ -6,32 +6,70 @@ import { SessionRecordingSidebarTab } from '~/types'
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface playerSidebarLogicValues {
activeTab: SessionRecordingSidebarTab
+ defaultTab: SessionRecordingSidebarTab
+ selectedTab: SessionRecordingSidebarTab | null
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface playerSidebarLogicActions {
+ setDefaultTab: (tab: SessionRecordingSidebarTab) => {
+ tab: SessionRecordingSidebarTab
+ }
setTab: (tab: SessionRecordingSidebarTab) => {
tab: SessionRecordingSidebarTab
}
}
-export type playerSidebarLogicType = MakeLogicType<playerSidebarLogicValues, playerSidebarLogicActions>
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface playerSidebarLogicMeta {
+ __keaTypeGenInternalSelectorTypes: {
+ activeTab: (
+ selectedTab: SessionRecordingSidebarTab | null,
+ defaultTab: SessionRecordingSidebarTab
+ ) => SessionRecordingSidebarTab
+ }
+}
+
+export type playerSidebarLogicType = MakeLogicType<
+ playerSidebarLogicValues,
+ playerSidebarLogicActions,
+ Record<string, any>,
+ playerSidebarLogicMeta
+>
export const playerSidebarLogic = kea<playerSidebarLogicType>([
path(() => ['scenes', 'session-recordings', 'player', 'playerSidebarLogic']),
actions(() => ({
setTab: (tab: SessionRecordingSidebarTab) => ({ tab }),
+ setDefaultTab: (tab: SessionRecordingSidebarTab) => ({ tab }),
})),
reducers(() => ({
- activeTab: [
+ // The tab the viewer picked, or null while they haven't picked one.
+ selectedTab: [null as SessionRecordingSidebarTab | null, { setTab: (_, { tab }) => tab }],
+ // Where the sidebar lands until the viewer picks a tab. Hosts embedding the player set this
+ // to whichever tab their surface is about — the experiment recordings tab wants Overview,
+ // since that's where the experiment context lives.
+ defaultTab: [
SessionRecordingSidebarTab.INSPECTOR as SessionRecordingSidebarTab,
- { setTab: (_, { tab }) => tab },
+ { setDefaultTab: (_, { tab }) => tab },
],
})),
+ selectors({
+ activeTab: [
+ (s) => [s.selectedTab, s.defaultTab],
+ (
+ selectedTab: SessionRecordingSidebarTab | null,
+ defaultTab: SessionRecordingSidebarTab
+ ): SessionRecordingSidebarTab => selectedTab ?? defaultTab,
+ ],
+ }),
+
actionToUrl(() => ({
+ // Only the viewer's own pick belongs in the URL. A host's default describes where the player
+ // is embedded, not what the viewer chose, so `setDefaultTab` deliberately has no entry here.
setTab: ({ tab }) => {
const { currentLocation } = router.values
return [
@@ -56,7 +94,10 @@ export const playerSidebarLogic = kea<playerSidebarLogicType>([
? (hashParams.tab as SessionRecordingSidebarTab)
: null
- if (isShowingRecording && urlTab && urlTab !== values.activeTab) {
+ // Compared against the viewer's pick rather than the active tab: a tab in the URL is an
+ // explicit choice, and checking the active tab would skip recording it whenever a host
+ // default happened to match — the choice would then evaporate once that host went away.
+ if (isShowingRecording && urlTab && urlTab !== values.selectedTab) {
actions.setTab(urlTab)
}
},