: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(experiments): say when a recording's session has no exposure event (#76023)
Marcel Poelker5d5ff6b741ce
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 15af2a49ad13..36c41ae71102 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -5002,10 +5002,14 @@ snapshots:hash: v1.k794b7964.bbf4ff6c95e15c066d88d166ec8cb78cb339cb1d4df2cb558ee00695ef86aa37.V3S60_fvrTNlrAmUI5gXoP3-KDwPQ-551cAMEUy3dHYreplay-overview-tab--wide-overview-tab--light:hash: v1.k794b7964.deb71477c91ae3fb89eaa9c6c9a45e665db4fa8363df4de30b3737c655930825.n5T9fmKBWN7qXDwbX9sYPEtdRgVYiaUgrJfvtail2tg+ replay-overview-tab-experiments--current-experiment-not-exposed--dark:+ hash: v1.k794b7964.260d2ae6bbf96cea5304b80598f13848d8fd392d628a0c6cfcb7fbcba790725d.lw64avOMM64AbRIjmpa5BWAYh71AMIHd1sn4GMu8b7E+ replay-overview-tab-experiments--current-experiment-not-exposed--light:+ hash: v1.k794b7964.3df16a2a43537af9a1c3cf4feb182529a7633cc5d4fc01011b80ee0a129281e8.YLJI9RsTHmIC0QasDoX6Djt-U_PGNo4FfTRSVKOwPLsreplay-overview-tab-experiments--default--dark:- hash: v1.k794b7964.d8d0a5076deebd369360b47f2ae86bbd0645d082ba0e271202ae5dfc9fdbe71f._l-QzxbiRIMLOQNEH2rreVSC-AoglFfLN8V-qdtKe1M+ hash: v1.k794b7964.79330e398cb2b6402ab847a6ab8e2ee61e71bd531473a6db0624b0d31538ad67.VS3PPJVIbJk5jHfGaUd7LjpdfWGQApwqjdvAKZhlInAreplay-overview-tab-experiments--default--light:- hash: v1.k794b7964.75111a9a147dfe4dad586d19e47092c919f6a27173e6409223104337f9acb08d.kdrOerNCwGkoznYgvK6S_Y6dat9EJ-mIbVwjcrHKD14+ hash: v1.k794b7964.40d99fa3c1d49cb1f4b21f3b9f727ad298ddf24767716bca7101ed3bf05192b4.F8N5B6OxXWv_eLUhNzKlkuuU5PqwKvSYqKb3nVLCkcsreplay-overview-tab-experiments--empty--dark:hash: v1.k794b7964.13e51a486b40a1455fde0075af333e3dff21f25491d06cc59ab10c24200eb1d2.Fn0OHVeRm39HLB3-xcZUZavR375CxuNraJZdmfxTS-Ureplay-overview-tab-experiments--empty--light:diff --git a/frontend/src/scenes/session-recordings/__mocks__/experiment_session_context.ts b/frontend/src/scenes/session-recordings/__mocks__/experiment_session_context.tsindex 1dc969a90828..c8b43f2b15b6 100644--- a/frontend/src/scenes/session-recordings/__mocks__/experiment_session_context.ts+++ b/frontend/src/scenes/session-recordings/__mocks__/experiment_session_context.ts@@ -142,3 +142,28 @@ export const experimentSessionContextResponse: ExperimentSessionContextResponseA}),],}++/** Pinning only happens for the experiment whose page the player is embedded in, so callers put the+ * router on this id. */+export const ENROLLED_CURRENT_EXPERIMENT_ID = 201++/** The experiment the viewer arrived from has no exposure event in this session, so the pinned row has+ * to say so rather than read as exposure. Ids here are deliberately absent from the response above:+ * stories share a router, and reusing one would pin a row in whichever story renders next.+ * The second, exposed experiment is what makes the pin engage at all. */+export const experimentSessionContextEnrolledCurrentResponse: ExperimentSessionContextResponseApi = {+ session_id: 'experiment-context-enrolled-current',+ results: [+ makeExperimentSessionContextItem({+ experiment_id: ENROLLED_CURRENT_EXPERIMENT_ID,+ experiment_name: 'Trial length',+ flag_key: 'trial-length',+ first_exposure_timestamp: null,+ }),+ makeExperimentSessionContextItem({+ experiment_id: 202,+ experiment_name: 'Nav redesign',+ flag_key: 'nav-redesign',+ }),+ ],+}diff --git a/frontend/src/scenes/session-recordings/player/sidebar/PlayerSidebarExperimentsSection.stories.tsx b/frontend/src/scenes/session-recordings/player/sidebar/PlayerSidebarExperimentsSection.stories.tsxindex b4d04476c415..1ed3a0c342d9 100644--- a/frontend/src/scenes/session-recordings/player/sidebar/PlayerSidebarExperimentsSection.stories.tsx+++ b/frontend/src/scenes/session-recordings/player/sidebar/PlayerSidebarExperimentsSection.stories.tsx@@ -8,7 +8,11 @@ import { urls } from 'scenes/urls'import { mswDecorator } from '~/mocks/browser'-import { experimentSessionContextResponse } from '../../__mocks__/experiment_session_context'+import {+ ENROLLED_CURRENT_EXPERIMENT_ID,+ experimentSessionContextEnrolledCurrentResponse,+ experimentSessionContextResponse,+} from '../../__mocks__/experiment_session_context'import { recordingMetaJson } from '../../__mocks__/recording_meta'import { sessionRecordingDataCoordinatorLogic } from '../sessionRecordingDataCoordinatorLogic'import { sessionRecordingPlayerLogic } from '../sessionRecordingPlayerLogic'@@ -71,6 +75,27 @@ Default.decorators = [}),]+// The experiment the viewer arrived from has no exposure event in this session. Pinning takes it out+// of the enrolled group, so the row itself has to say it wasn't exposed here.+export function CurrentExperimentNotExposed(): JSX.Element {+ router.actions.push(urls.experiment(ENROLLED_CURRENT_EXPERIMENT_ID))+ return <MockedPlayerSidebarExperimentsSection sessionRecordingId="experiment-context-enrolled-current" />+}+CurrentExperimentNotExposed.parameters = {+ testOptions: {+ waitForLoadersToDisappear: true,+ waitForSelector: '[data-attr=replay-experiment-context-not-exposed]',+ },+}+CurrentExperimentNotExposed.decorators = [+ mswDecorator({+ get: {+ '/api/environments/:team_id/session_recordings/:id': recordingMetaJson,+ '/api/projects/:team_id/experiments/session_context/': experimentSessionContextEnrolledCurrentResponse,+ },+ }),+]+// While the context request is in flight the box shows a skeleton placeholder — but only when the// viewer arrived from an experiment's recordings tab, so the route is put on /experiments/<id>// first. The mocked request never resolves, holding the section in its loading state.diff --git a/frontend/src/scenes/session-recordings/player/sidebar/PlayerSidebarExperimentsSection.test.tsx b/frontend/src/scenes/session-recordings/player/sidebar/PlayerSidebarExperimentsSection.test.tsxnew file mode 100644index 000000000000..fa168975dd0e--- /dev/null+++ b/frontend/src/scenes/session-recordings/player/sidebar/PlayerSidebarExperimentsSection.test.tsx@@ -0,0 +1,52 @@+import '@testing-library/jest-dom'++import { render, screen } from '@testing-library/react'+import { BindLogic, Provider } from 'kea'+import { router } from 'kea-router'++import { FEATURE_FLAGS } from 'lib/constants'+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'+import { urls } from 'scenes/urls'++import {+ ENROLLED_CURRENT_EXPERIMENT_ID,+ experimentSessionContextEnrolledCurrentResponse,+} from '../../__mocks__/experiment_session_context'+import { setupSessionRecordingTest } from '../__mocks__/test-setup'+import { sessionRecordingPlayerLogic } from '../sessionRecordingPlayerLogic'+import { PlayerSidebarExperimentsSection } from './PlayerSidebarExperimentsSection'++describe('PlayerSidebarExperimentsSection', () => {+ const logicProps = {+ sessionRecordingId: experimentSessionContextEnrolledCurrentResponse.session_id,+ playerKey: 'experiments-section-test',+ }++ beforeEach(() => {+ setupSessionRecordingTest({+ getMocks: {+ '/api/projects/:team_id/experiments/session_context/': experimentSessionContextEnrolledCurrentResponse,+ },+ })+ featureFlagLogic.mount()+ featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.REPLAY_EXPERIMENT_CONTEXT], {+ [FEATURE_FLAGS.REPLAY_EXPERIMENT_CONTEXT]: true,+ })+ })++ // Pinning lifts the arrived-from experiment out of the enrolled group, and so out of that group's+ // label. Without a marker of its own the row claims an exposure this session has no event for.+ it('says the pinned experiment was not exposed when the session has no exposure event for it', async () => {+ router.actions.push(urls.experiment(ENROLLED_CURRENT_EXPERIMENT_ID))++ render(+ <Provider>+ <BindLogic logic={sessionRecordingPlayerLogic} props={logicProps}>+ <PlayerSidebarExperimentsSection />+ </BindLogic>+ </Provider>+ )++ expect(await screen.findByText('Not exposed in this session')).toBeInTheDocument()+ })+})diff --git a/frontend/src/scenes/session-recordings/player/sidebar/PlayerSidebarExperimentsSection.tsx b/frontend/src/scenes/session-recordings/player/sidebar/PlayerSidebarExperimentsSection.tsxindex 67e257315343..a4af50206e53 100644--- a/frontend/src/scenes/session-recordings/player/sidebar/PlayerSidebarExperimentsSection.tsx+++ b/frontend/src/scenes/session-recordings/player/sidebar/PlayerSidebarExperimentsSection.tsx@@ -253,6 +253,27 @@ function ExposureTime({)}+// The experiment analysis counts exposure events, and this session has none: that is the one claim+// that holds wherever the viewer came from. The copy must not reference the recordings tab's list,+// because when the exposure event is server-side that tab falls back to listing flag-active sessions+// (see applySessionLinkability), and enrolled-only sessions are then exactly what its list shows.+const NOT_EXPOSED_CAVEAT =+ "The flag was active in this session, but no exposure event was captured here, so this session isn't where the experiment analysis counted this person's exposure."++// The caveat hangs off an info icon, like the section header's: it's far too long to sit inline in a+// sidebar this narrow.+function NotExposedInSessionLabel({ children, className }: { children: string; className?: string }): JSX.Element {+ return (+ <Tooltip title={NOT_EXPOSED_CAVEAT}>+ {/* The icon trails the text inline so it stays with the last word when the label wraps. */}+ <span className={className} data-attr="replay-experiment-context-not-exposed">+ {children}+ <IconInfo className="inline-block ml-1 size-3 text-secondary" />+ </span>+ </Tooltip>+ )+}+function ExperimentContextRow({item,onSeek,@@ -478,7 +499,14 @@ export function PlayerSidebarExperimentsSection(): JSX.Element | null {{pinnedItem.first_exposure_timestamp != null ? (renderSeenRow(pinnedItem)) : (- <ExperimentContextRow item={pinnedItem} />+ <>+ <ExperimentContextRow item={pinnedItem} />+ {/* Pinning lifts the row out of the enrolled group below, and with it out of+ that group's label, so the row has to carry the distinction itself. */}+ <NotExposedInSessionLabel className="w-fit text-xs text-muted">+ Not exposed in this session+ </NotExposedInSessionLabel>+ </>)}</div>) : null}@@ -498,7 +526,11 @@ export function PlayerSidebarExperimentsSection(): JSX.Element | null {panels={[{key: 'enrolled',- header: `Also enrolled, not exposed in this session (${listEnrolledItems.length})`,+ header: (+ <NotExposedInSessionLabel>+ {`Also enrolled, not exposed in this session (${listEnrolledItems.length})`}+ </NotExposedInSessionLabel>+ ),content: (<div className="flex flex-col gap-y-1">{listEnrolledItems.map((item) => (