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): report why the recordings list rendered empty (#95022)

Marcel Poelkereb10ba266a69
diff --git a/frontend/src/lib/utils/eventUsageLogic.ts b/frontend/src/lib/utils/eventUsageLogic.ts
index 58a8c008a81b..35375728c7ca 100644
--- a/frontend/src/lib/utils/eventUsageLogic.ts
+++ b/frontend/src/lib/utils/eventUsageLogic.ts
@@ -160,6 +160,35 @@ export interface ExperimentRecordingsFilterContext {
watch_card_kind: string | null
}
+/**
+ * What the recordings list came back with, and — when it came back with nothing — the cause the tab
+ * can name from what it already holds. A large share of tab visits show an empty list and nothing
+ * says why, so the facets are carried alongside `empty_reason` to tell a project with replay off
+ * apart from an experiment too young to have recordings, or a filter that matched nothing.
+ * Carries the same facets as `experiment recording opened`, so an empty list and an opened recording
+ * are comparable per facet.
+ */
+export interface ExperimentRecordingsListRenderedContext extends ExperimentRecordingsFilterContext {
+ result_count: number
+ /** Null when the list has rows. One of the tab's `ExperimentReplayListEmptyReason` values. */
+ empty_reason: string | null
+ /** Null when the experiment has not launched. */
+ days_since_start: number | null
+ /** Null while the experiment runs. */
+ days_since_end: number | null
+ /**
+ * The project's current replay retention setting, null when it has none. A recording expires on
+ * the period it was stored under, so this is the assumption `ended_past_retention` was decided
+ * on rather than proof of what expired.
+ */
+ retention_period: string | null
+ replay_opt_in: boolean
+ /** Replay's default floor drops sessions under 5 active seconds, so it can empty a list. */
+ duration_filter_active: boolean
+ /** Whether the exposure event is ever seen with a session id. Null while the check is out. */
+ exposure_linkable: boolean | null
+}
+
/**
* What the behavior comparison found, captured each time the shelf loads. The card counts are what
* say whether the feature finds anything in the wild: all zeros on most experiments would mean the
@@ -1351,6 +1380,13 @@ export interface eventUsageLogicActions {
context: ExperimentRecordingsBucketLoadedContext
experimentId: ExperimentIdType
}
+ reportExperimentRecordingsListRendered: (
+ experimentId: ExperimentIdType,
+ context: ExperimentRecordingsListRenderedContext
+ ) => {
+ context: ExperimentRecordingsListRenderedContext
+ experimentId: ExperimentIdType
+ }
reportExperimentRecordingsTabViewed: (
experimentId: ExperimentIdType,
context: ExperimentRecordingsTabContext
@@ -2800,6 +2836,10 @@ export const eventUsageLogic = kea<eventUsageLogicType>([
experimentId: ExperimentIdType,
context: ExperimentRecordingsBucketFailedContext
) => ({ experimentId, context }),
+ reportExperimentRecordingsListRendered: (
+ experimentId: ExperimentIdType,
+ context: ExperimentRecordingsListRenderedContext
+ ) => ({ experimentId, context }),
reportExperimentRecordingOpened: (
experimentId: ExperimentIdType,
context: ExperimentRecordingsFilterContext
@@ -4035,6 +4075,12 @@ export const eventUsageLogic = kea<eventUsageLogicType>([
...context,
})
},
+ reportExperimentRecordingsListRendered: ({ experimentId, context }) => {
+ posthog.capture('experiment recordings list rendered', {
+ experiment_id: experimentId,
+ ...context,
+ })
+ },
reportExperimentRecordingOpened: ({ experimentId, context }) => {
posthog.capture('experiment recording opened', {
experiment_id: experimentId,
diff --git a/frontend/src/scenes/experiments/ExperimentView/ExperimentReplayTab.tsx b/frontend/src/scenes/experiments/ExperimentView/ExperimentReplayTab.tsx
index 12c1025ed42e..b4a27129eabc 100644
--- a/frontend/src/scenes/experiments/ExperimentView/ExperimentReplayTab.tsx
+++ b/frontend/src/scenes/experiments/ExperimentView/ExperimentReplayTab.tsx
@@ -513,7 +513,7 @@ export function ExperimentReplayTab({ experiment }: { experiment: Experiment }):
analyticsSource="experiment-recordings-tab"
filters={recordingsFilters}
onFiltersChange={(filters) => playlistFiltersChanged(filters)}
- onRecordingsLoaded={(recordings) => recordingsLoaded(recordings)}
+ onRecordingsLoaded={(recordings, isFirstPage) => recordingsLoaded(recordings, isFirstPage)}
onRecordingSelected={(recordingId) => recordingOpened(recordingId)}
/>
)}
diff --git a/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.test.ts b/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.test.ts
index 631b0ed76d5d..78cd606aab01 100644
--- a/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.test.ts
+++ b/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.test.ts
@@ -1,14 +1,18 @@
+import { MOCK_DEFAULT_TEAM } from 'lib/api.mock'
+
import { expectLogic } from 'kea-test-utils'
import posthog from 'posthog-js'
import api from 'lib/api'
import { FEATURE_FLAGS } from 'lib/constants'
+import { dayjs } from 'lib/dayjs'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { playerSidebarLogic } from 'scenes/session-recordings/player/sidebar/playerSidebarLogic'
+import { teamLogic } from 'scenes/teamLogic'
import { ExperimentMetricType, NodeKind } from '~/queries/schema/schema-general'
import { initKeaTests } from '~/test/init'
-import { Experiment, FilterLogicalOperator, SessionRecordingSidebarTab } from '~/types'
+import { Experiment, FilterLogicalOperator, SessionRecordingSidebarTab, TeamType } from '~/types'
import {
experimentsInSessionExposureRetrieve,
@@ -20,7 +24,11 @@ import { visionScannersList } from 'products/replay_vision/frontend/generated/ap
import { FUNNEL_DATA_WAREHOUSE_COMPLETION_REASON, FUNNEL_SERVER_SIDE_COMPLETION_REASON } from '../utils'
import { RETENTION_UNLINKABLE_REASON, viewRecordingsLinkabilityLogic } from '../viewRecordingsLinkabilityLogic'
-import { type ExperimentReplayRecording, experimentReplayTabLogic } from './experimentReplayTabLogic'
+import {
+ type ExperimentReplayRecording,
+ ExperimentReplayListEmptyReason,
+ experimentReplayTabLogic,
+} from './experimentReplayTabLogic'
jest.mock('lib/utils/product-intents', () => ({
addProductIntentForCrossSell: jest.fn().mockResolvedValue(null),
@@ -149,6 +157,75 @@ const EMPTY_FILTER_GROUP = {
values: [{ type: FilterLogicalOperator.And, values: [] }],
}
+// Run windows are relative: the reasons are read against the retention period and against today,
+// so a fixed date would start naming a different reason as it aged. Counted in hours, so a run in
+// a zone with daylight saving still lands a whole number of days back.
+const daysAgo = (days: number): string =>
+ dayjs()
+ .subtract(days * 24, 'hour')
+ .toISOString()
+
+const listsRendered = (captureSpy: jest.SpyInstance, experimentId: number): any[] =>
+ captureSpy.mock.calls.filter(
+ ([event, properties]) =>
+ event === 'experiment recordings list rendered' && (properties as any)?.experiment_id === experimentId
+ )
+
+interface EmptyReasonCase {
+ reason: ExperimentReplayListEmptyReason
+ /** One per case: the logic is keyed per experiment, and each case mounts its own. */
+ experimentId: number
+ experiment: Partial<Experiment>
+ team?: Partial<TeamType>
+ setup?: (logic: ReturnType<typeof experimentReplayTabLogic.build>) => void
+}
+
+// The team's retention period is the mock default of 30 days, which the run windows are set against.
+const EMPTY_REASON_CASES: EmptyReasonCase[] = [
+ {
+ reason: ExperimentReplayListEmptyReason.ReplayDisabled,
+ experimentId: 121,
+ experiment: {},
+ team: { session_recording_opt_in: false },
+ },
+ {
+ reason: ExperimentReplayListEmptyReason.NotLaunched,
+ experimentId: 122,
+ experiment: { start_date: null, end_date: null },
+ },
+ {
+ reason: ExperimentReplayListEmptyReason.MetricFilterMatchedNothing,
+ experimentId: 123,
+ experiment: { start_date: daysAgo(10), end_date: null },
+ setup: (logic) => {
+ ;(experimentsSessionBucketsCreate as jest.Mock).mockResolvedValue({ ...BUCKET_RESPONSE, session_ids: [] })
+ logic.actions.setMetricFilterMode('no_metric_activity')
+ },
+ },
+ {
+ reason: ExperimentReplayListEmptyReason.EndedPastRetention,
+ experimentId: 124,
+ experiment: { start_date: daysAgo(200), end_date: daysAgo(60) },
+ },
+ {
+ reason: ExperimentReplayListEmptyReason.TooEarly,
+ experimentId: 125,
+ experiment: { start_date: daysAgo(1), end_date: null },
+ },
+ {
+ reason: ExperimentReplayListEmptyReason.UnknownInWindow,
+ experimentId: 127,
+ experiment: { start_date: daysAgo(10), end_date: daysAgo(2) },
+ },
+ {
+ // Still running past the retention period: its retained days are inside retention, so this
+ // is unexplained rather than a retention loss.
+ reason: ExperimentReplayListEmptyReason.UnknownInWindow,
+ experimentId: 128,
+ experiment: { start_date: daysAgo(60), end_date: null },
+ },
+]
+
describe('experimentReplayTabLogic', () => {
let logic: ReturnType<typeof experimentReplayTabLogic.build>
let seenTogetherSpy: jest.SpyInstance
@@ -683,6 +760,132 @@ describe('experimentReplayTabLogic', () => {
expect((experimentsSessionContextsCreate as jest.Mock).mock.calls[0][1].session_ids).toHaveLength(20)
})
+ it.each(EMPTY_REASON_CASES)(
+ 'reports $reason for a list that came back empty',
+ async ({ reason, experimentId, experiment, team, setup }) => {
+ const captureSpy = jest.spyOn(posthog, 'capture').mockReturnValue(undefined as any)
+ teamLogic.actions.loadCurrentTeamSuccess({ ...MOCK_DEFAULT_TEAM, ...team })
+ const empty = experimentReplayTabLogic({
+ experiment: { ...EXPERIMENT, id: experimentId, ...experiment } as Experiment,
+ })
+ empty.mount()
+ setup?.(empty)
+ await expectLogic(empty).toFinishAllListeners()
+
+ empty.actions.recordingsLoaded([])
+ await expectLogic(empty).toFinishAllListeners()
+
+ expect(listsRendered(captureSpy, experimentId)).toHaveLength(1)
+ expect(listsRendered(captureSpy, experimentId)[0][1]).toMatchObject({
+ result_count: 0,
+ empty_reason: reason,
+ })
+ empty.unmount()
+ }
+ )
+
+ it('reports a list with rows, with no reason and the facets it was narrowed by', async () => {
+ // The empty reason names a plausible cause of emptiness, so on a list with rows it would
+ // read as a fault the tab found. The facets match `experiment recording opened`, so an
+ // empty list and an opened recording are comparable per facet.
+ const captureSpy = jest.spyOn(posthog, 'capture').mockReturnValue(undefined as any)
+ teamLogic.actions.loadCurrentTeamSuccess({ ...MOCK_DEFAULT_TEAM, session_recording_retention_period: '90d' })
+ const filled = experimentReplayTabLogic({
+ experiment: { ...EXPERIMENT, id: 111, start_date: daysAgo(10), end_date: daysAgo(2) } as Experiment,
+ })
+ filled.mount()
+ filled.actions.setSelectedVariantKey('test')
+ await expectLogic(filled).toFinishAllListeners()
+
+ filled.actions.recordingsLoaded(loadedPage(['s1', 's2']))
+ await expectLogic(filled).toFinishAllListeners()
+
+ expect(listsRendered(captureSpy, 111)).toHaveLength(1)
+ expect(listsRendered(captureSpy, 111)[0][1]).toEqual({
+ experiment_id: 111,
+ result_count: 2,
+ empty_reason: null,
+ days_since_start: 10,
+ days_since_end: 2,
+ retention_period: '90d',
+ replay_opt_in: true,
+ duration_filter_active: true,
+ exposure_linkable: true,
+ variant: 'test',
+ exposure_scope: 'all_exposed',
+ metric_filter_mode: 'fired_all',
+ selected_metric_count: 0,
+ is_bucketed: false,
+ watch_card_kind: null,
+ })
+ filled.unmount()
+ })
+
+ it('tells a refused metric filter apart from one that matched nothing, once it has answered', async () => {
+ // Both leave the list with an empty session set, since a refusal must never widen the list
+ // back out. Folded together, a broken endpoint would inflate the count of filters that
+ // legitimately match nothing — the reason a reader would act on.
+ const captureSpy = jest.spyOn(posthog, 'capture').mockReturnValue(undefined as any)
+ ;(experimentsSessionBucketsCreate as jest.Mock).mockReturnValue(new Promise(() => {}))
+ const failing = experimentReplayTabLogic({
+ experiment: { ...EXPERIMENT, id: 113, start_date: daysAgo(10), end_date: null } as Experiment,
+ })
+ failing.mount()
+ failing.actions.setMetricFilterMode('no_metric_activity')
+
+ // While the request is out the list is empty because the filter hasn't answered yet, and
+ // the caption says so. Reported, that provisional empty would be counted twice.
+ failing.actions.recordingsLoaded([])
+ expect(listsRendered(captureSpy, 113)).toHaveLength(0)
+ ;(experimentsSessionBucketsCreate as jest.Mock).mockRejectedValue(
+ Object.assign(new Error('boom'), { detail: 'Pick exactly one funnel metric' })
+ )
+ failing.actions.loadSessionBucket()
+ await expectLogic(failing).toFinishAllListeners()
+ failing.actions.recordingsLoaded([])
+ await expectLogic(failing).toFinishAllListeners()
+
+ expect(listsRendered(captureSpy, 113)).toHaveLength(1)
+ expect(listsRendered(captureSpy, 113)[0][1]).toMatchObject({
+ result_count: 0,
+ empty_reason: 'metric_filter_failed',
+ is_bucketed: true,
+ })
+ failing.unmount()
+ })
+
+ it('leaves the pages scrolling adds out of the report', async () => {
+ // Counted too, one visit would look like several lists, and a later page that comes back
+ // empty would read as an empty list rather than the end of a list with rows.
+ const captureSpy = jest.spyOn(posthog, 'capture').mockReturnValue(undefined as any)
+ logic.actions.recordingsLoaded([], false)
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(listsRendered(captureSpy, 42)).toHaveLength(0)
+ })
+
+ it('reports the exposure event as unlinkable when it is never seen with a session id', async () => {
+ // The residual "in window, replay on, still empty" bucket is the one the tab can't explain,
+ // and an exposure event captured without a session id is the likeliest cause in it.
+ const captureSpy = jest.spyOn(posthog, 'capture').mockReturnValue(undefined as any)
+ seenTogetherSpy.mockResolvedValue({ ...ALL_LINKABLE, $feature_flag_called: false })
+ const unlinkable = experimentReplayTabLogic({
+ experiment: { ...EXPERIMENT, id: 112, start_date: daysAgo(10), end_date: null } as Experiment,
+ })
+ unlinkable.mount()
+ await expectLogic(unlinkable).toFinishAllListeners()
+
+ unlinkable.actions.recordingsLoaded([])
+ await expectLogic(unlinkable).toFinishAllListeners()
+
+ expect(listsRendered(captureSpy, 112)[0][1]).toMatchObject({
+ empty_reason: 'unknown_in_window',
+ exposure_linkable: false,
+ days_since_end: null,
+ })
+ unlinkable.unmount()
+ })
+
it('offers saved/shared metrics in the facet, deduped by uuid', async () => {
const savedMetric = {
query: {
diff --git a/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.ts b/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.ts
index 79dd2e893fb1..220ddc75af37 100644
--- a/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.ts
+++ b/frontend/src/scenes/experiments/ExperimentView/experimentReplayTabLogic.ts
@@ -15,12 +15,14 @@ import {
import { loaders } from 'kea-loaders'
import { FEATURE_FLAGS } from 'lib/constants'
+import { dayjs } from 'lib/dayjs'
import { FeatureFlagsSet, featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { groupBy } from 'lib/utils/arrays'
import {
ExperimentRecordingsBucketFailedContext,
ExperimentRecordingsBucketLoadedContext,
ExperimentRecordingsFilterContext,
+ ExperimentRecordingsListRenderedContext,
ExperimentRecordingsTabContext,
ExperimentWatchCardContext,
ExperimentWatchHighlightContext,
@@ -43,8 +45,11 @@ import {
Experiment,
FilterLogicalOperator,
RecordingUniversalFilters,
+ SessionRecordingRetentionPeriod,
SessionRecordingSidebarTab,
SessionRecordingType,
+ TeamPublicType,
+ TeamType,
UniversalFiltersGroupValue,
} from '~/types'
@@ -70,6 +75,7 @@ import type { ExperimentSavedMetric } from '../experimentLogic'
import { getDefaultMetricTitle } from '../MetricsView/shared/utils'
import {
getExperimentVariants,
+ getExposureLinkabilityEventName,
getFunnelDropoffReason,
getMetricSessionFilters,
isUnlinkableEventFilter,
@@ -147,9 +153,58 @@ export type ExperimentReplayRecording = Pick<SessionRecordingType, 'id' | 'recor
/** The link an empty "what to watch" state offers, as reported to telemetry. */
export type ExperimentWatchEmptyAction = 'exposure_docs' | 'replay_settings'
+/**
+ * Why the recordings list came back with nothing, from what the client already holds. Reported, not
+ * shown: the tab has no way today to tell a project with replay switched off from an experiment
+ * launched an hour ago, and both look like "this feature is broken" to whoever opened the tab.
+ *
+ * `unknown_in_window` is the residue — replay is on, the run window is inside retention, and the
+ * filters still matched nothing. Exposure linkage and the duration floor both live in there, which
+ * is why the event carries `exposure_linkable` and `duration_filter_active` alongside the reason.
+ */
+export enum ExperimentReplayListEmptyReason {
+ /** The project does not record sessions, so no experiment on it can have any. */
+ ReplayDisabled = 'replay_disabled',
+ NotLaunched = 'not_launched',
+ /** The request behind the metric filter was refused, so the list has no session set to show. */
+ MetricFilterFailed = 'metric_filter_failed',
+ /** The selected metrics resolved to an empty session set, so the list can only be empty. */
+ MetricFilterMatchedNothing = 'metric_filter_matched_nothing',
+ /**
+ * The whole run window predates retention: every recording it had has since expired. Measured
+ * against the project's current retention setting, while a recording expires on the period it
+ * was stored under, so a project that has just changed the setting can be misread. The setting
+ * rides along on the report as `retention_period` for exactly that reason.
+ */
+ EndedPastRetention = 'ended_past_retention',
+ /** Launched within the last few days, so recordings may not have been captured yet. */
+ TooEarly = 'too_early',
+ UnknownInWindow = 'unknown_in_window',
+}
+
// Mirrors the backend's MAX_SESSION_CONTEXT_BATCH — ids beyond it would 400 the whole batch.
const SESSION_CONTEXT_PREFETCH_LIMIT = 20
+// A launch this recent has too little traffic behind it for an empty list to mean anything.
+const TOO_EARLY_DAYS = 3
+
+// 'legacy' is a project whose retention predates the setting, so it holds the pre-setting 30 days.
+const RETENTION_PERIOD_DAYS: Record<SessionRecordingRetentionPeriod, number> = {
+ legacy: 30,
+ '30d': 30,
+ '90d': 90,
+ '1y': 365,
+ '5y': 365 * 5,
+}
+
+function retentionDays(retentionPeriod: SessionRecordingRetentionPeriod | null | undefined): number {
+ return retentionPeriod ? RETENTION_PERIOD_DAYS[retentionPeriod] : RETENTION_PERIOD_DAYS['30d']
+}
+
+function daysSince(date: string | null | undefined): number | null {
+ return date ? dayjs().diff(dayjs(date), 'day') : null
+}
+
/**
* Sort metrics the way the experiment's metrics page lists them. The ordering arrays are that
* page's display order, and every metric uuid is meant to be in one of them — but only sorting
@@ -186,25 +241,31 @@ function metricSourceEventNames(metric: ExperimentMetric): string[] {
export interface experimentReplayTabLogicValues {
featureFlags: FeatureFlagsSet // featureFlagLogic
currentProjectId: number | string // teamLogic
+ currentTeam: TeamPublicType | TeamType | null // teamLogic
linkabilityLoaded: boolean // viewRecordingsLinkabilityLogic
seenTogetherMapLoading: boolean // viewRecordingsLinkabilityLogic
unlinkableEventNames: Set<string> // viewRecordingsLinkabilityLogic
behaviorComparisonAvailable: boolean
behaviorComparisonOpen: boolean
bucketSessionIds: string[] | undefined
+ durationFilterActive: boolean
effectiveExposureScope: ExperimentReplayExposureScope
effectiveMetricUuids: string[]
effectiveVariantKey: string | null
exposureInSessionUnavailableReason: string | null
+ exposureLinkable: boolean | null
exposureScope: ExperimentReplayExposureScope
+ filterContext: ExperimentRecordingsFilterContext
inSessionExposure: ExperimentInSessionExposureApi | null
inSessionExposureLoading: boolean
linkedScanners: LinkedScanner[]
linkedScannersLoading: boolean
+ listEmptyReason: ExperimentReplayListEmptyReason
loadedRecordings: ExperimentReplayRecording[]
loadedRecordingsById: Map<string, ExperimentReplayRecording>
metricFilterMode: ExperimentReplayMetricFilterMode
metricOptions: ExperimentReplayMetricOption[]
+ playlistFilters: RecordingUniversalFilters | null
playlistHeldForChecks: boolean
recordingsFilters: RecordingUniversalFilters
selectedMetricUuids: string[]
@@ -265,6 +326,13 @@ export interface experimentReplayTabLogicActions {
context: ExperimentRecordingsBucketLoadedContext
experimentId: ExperimentIdType
} // eventUsageLogic
+ reportExperimentRecordingsListRendered: (
+ experimentId: ExperimentIdType,
+ context: ExperimentRecordingsListRenderedContext
+ ) => {
+ context: ExperimentRecordingsListRenderedContext
+ experimentId: ExperimentIdType
+ } // eventUsageLogic
reportExperimentRecordingsTabViewed: (
experimentId: ExperimentIdType,
context: ExperimentRecordingsTabContext
@@ -395,7 +463,11 @@ export interface experimentReplayTabLogicActions {
recordingOpened: (sessionId: string) => {
sessionId: string
}
- recordingsLoaded: (recordings: ExperimentReplayRecording[]) => {
+ recordingsLoaded: (
+ recordings: ExperimentReplayRecording[],
+ isFirstPage?: boolean
+ ) => {
+ isFirstPage: boolean
recordings: ExperimentReplayRecording[]
}
reportTabViewed: () => {
@@ -457,6 +529,25 @@ export interface experimentReplayTabLogicMeta {
linkabilityLoaded: boolean,
seenTogetherMapLoading: boolean
) => boolean
+ exposureLinkable: (linkabilityLoaded: boolean, unlinkableEventNames: Set<string>, arg: any) => boolean | null
+ durationFilterActive: (
+ playlistFilters: RecordingUniversalFilters | null,
+ recordingsFilters: RecordingUniversalFilters
+ ) => boolean
+ listEmptyReason: (
+ currentTeam: TeamPublicType | TeamType | null,
+ bucketSessionIds: string[] | undefined,
+ sessionBucketError: string | null,
+ arg: any
+ ) => ExperimentReplayListEmptyReason
+ filterContext: (
+ effectiveVariantKey: string | null,
+ effectiveExposureScope: ExperimentReplayExposureScope,
+ metricFilterMode: ExperimentReplayMetricFilterMode,
+ effectiveMetricUuids: string[],
+ bucketSessionIds: string[] | undefined,
+ selectedWatchCard: ExperimentWatchCardApi | null
+ ) => ExperimentRecordingsFilterContext
tabViewContext: (
variantKeys: string[],
metricOptions: ExperimentReplayMetricOption[],
@@ -521,7 +612,8 @@ export const experimentReplayTabLogic = kea<experimentReplayTabLogicType>([
featureFlagLogic,
['featureFlags'],
teamLogic,
- ['currentProjectId'],
+ // The replay settings that decide whether this experiment can have recordings at all.
+ ['currentProjectId', 'currentTeam'],
],
// 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.
@@ -537,6 +629,7 @@ export const experimentReplayTabLogic = kea<experimentReplayTabLogicType>([
'reportExperimentRecordingsTabViewed',
'reportExperimentRecordingsBucketLoaded',
'reportExperimentRecordingsBucketFailed',
+ 'reportExperimentRecordingsListRendered',
'reportExperimentRecordingOpened',
'reportExperimentBehaviorComparisonToggled',
'reportExperimentBehaviorComparisonLoaded',
@@ -553,7 +646,10 @@ export const experimentReplayTabLogic = kea<experimentReplayTabLogicType>([
setMetricSelected: (metricUuid: string, selected: boolean) => ({ metricUuid, selected }),
setMetricFilterMode: (mode: ExperimentReplayMetricFilterMode) => ({ mode }),
playlistFiltersChanged: (filters: RecordingUniversalFilters) => ({ filters }),
- recordingsLoaded: (recordings: ExperimentReplayRecording[]) => ({ recordings }),
+ recordingsLoaded: (recordings: ExperimentReplayRecording[], isFirstPage: boolean = true) => ({
+ recordings,
+ isFirstPage,
+ }),
recordingOpened: (sessionId: string) => ({ sessionId }),
toggleBehaviorComparison: true,
selectWatchCard: (card: ExperimentWatchCardApi | null) => ({ card }),
@@ -770,6 +866,16 @@ export const experimentReplayTabLogic = kea<experimentReplayTabLogicType>([
recordingsLoaded: (_, { recordings }) => recordings,
},
],
+ // The filters the playlist is actually listing on. The tab hands it a starting point, which
+ // the viewer can then edit in the playlist's own filter bar, so telemetry about what the
+ // list was narrowed by has to read these rather than what the tab pushed down. Null until
+ // the playlist reports them.
+ playlistFilters: [
+ null as RecordingUniversalFilters | null,
+ {
+ playlistFiltersChanged: (_, { filters }) => filters,
+ },
+ ],
// A failed bucket must not silently fall back to the unbucketed list: the label would
// then describe a population the list isn't showing. The message is kept because a
// rejected request is usually actionable ("takes exactly one funnel metric") — a generic
@@ -878,6 +984,103 @@ export const experimentReplayTabLogic = kea<experimentReplayTabLogicType>([
exposureScope === 'in_session' &&
(inSessionExposureLoading || (!linkabilityLoaded && seenTogetherMapLoading)),
],
+ // Whether the exposure event is ever seen carrying a session id, off the shared linkability
+ // check. Null until the check lands, and for an action exposure config, which matches
+ // several events rather than one.
+ exposureLinkable: [
+ (s) => [s.linkabilityLoaded, s.unlinkableEventNames, (_, props) => props.experiment],
+ (linkabilityLoaded: boolean, unlinkableEventNames: Set<string>, experiment: Experiment): boolean | null => {
+ const exposureEventName = getExposureLinkabilityEventName(experiment)
+ if (!linkabilityLoaded || exposureEventName === null) {
+ return null
+ }
+ return !unlinkableEventNames.has(exposureEventName)
+ },
+ ],
+ // Replay's default floor keeps out sessions under 5 active seconds, which is enough to empty
+ // a list on its own, so an empty-list report says whether it was applied.
+ durationFilterActive: [
+ (s) => [s.playlistFilters, s.recordingsFilters],
+ (
+ playlistFilters: RecordingUniversalFilters | null,
+ recordingsFilters: RecordingUniversalFilters
+ ): boolean => (playlistFilters ?? recordingsFilters).duration.length > 0,
+ ],
+ /**
+ * The cause to report when the list comes back with nothing, first match wins. The order is
+ * cheapest-and-most-certain first: a project with replay off can have no recordings at all,
+ * while the window and retention reasons only say that the recordings the window would have
+ * shown no longer exist.
+ *
+ * Read only for an empty list. It names a plausible cause of emptiness, not the state of the
+ * tab, so on a list with rows it is meaningless rather than wrong.
+ */
+ listEmptyReason: [
+ (s) => [s.currentTeam, s.bucketSessionIds, s.sessionBucketError, (_, props) => props.experiment],
+ (
+ currentTeam: TeamPublicType | TeamType | null,
+ bucketSessionIds: string[] | undefined,
+ sessionBucketError: string | null,
+ experiment: Experiment
+ ): ExperimentReplayListEmptyReason => {
+ if (!currentTeam?.session_recording_opt_in) {
+ return ExperimentReplayListEmptyReason.ReplayDisabled
+ }
+ if (!experiment.start_date) {
+ return ExperimentReplayListEmptyReason.NotLaunched
+ }
+ // A refused request leaves the same empty session set as a filter that matched
+ // nothing, because it must never widen the list back out. Told apart here rather
+ // than left to a join against `experiment recordings bucket failed`, so a broken
+ // endpoint can't inflate the count of filters that legitimately match nothing.
+ if (bucketSessionIds?.length === 0) {
+ return sessionBucketError !== null
+ ? ExperimentReplayListEmptyReason.MetricFilterFailed
+ : ExperimentReplayListEmptyReason.MetricFilterMatchedNothing
+ }
+ const retention = retentionDays(currentTeam.session_recording_retention_period)
+ const daysSinceStart = dayjs().diff(dayjs(experiment.start_date), 'day')
+ const daysSinceEnd = daysSince(experiment.end_date)
+ if (daysSinceEnd !== null && daysSinceEnd > retention) {
+ return ExperimentReplayListEmptyReason.EndedPastRetention
+ }
+ if (daysSinceStart < TOO_EARLY_DAYS) {
+ return ExperimentReplayListEmptyReason.TooEarly
+ }
+ // A window that expired only in part gets no reason of its own, whether the
+ // experiment ended or still runs: its retained days are inside retention, so an
+ // empty list there is unexplained. `days_since_start` and `retention_period` ride
+ // along on the report, so that slice stays one filter away.
+ return ExperimentReplayListEmptyReason.UnknownInWindow
+ },
+ ],
+ // What the list was narrowed by, shared by the opened-recording and list-rendered reports so
+ // an empty list and an opened recording are comparable facet for facet.
+ filterContext: [
+ (s) => [
+ s.effectiveVariantKey,
+ s.effectiveExposureScope,
+ s.metricFilterMode,
+ s.effectiveMetricUuids,
+ s.bucketSessionIds,
+ s.selectedWatchCard,
+ ],
+ (
+ effectiveVariantKey: string | null,
+ effectiveExposureScope: ExperimentReplayExposureScope,
+ metricFilterMode: ExperimentReplayMetricFilterMode,
+ effectiveMetricUuids: string[],
+ bucketSessionIds: string[] | undefined,
+ selectedWatchCard: ExperimentWatchCardApi | null
+ ): ExperimentRecordingsFilterContext => ({
+ variant: effectiveVariantKey,
+ exposure_scope: effectiveExposureScope,
+ metric_filter_mode: metricFilterMode,
+ selected_metric_count: effectiveMetricUuids.length,
+ is_bucketed: bucketSessionIds !== undefined,
+ watch_card_kind: selectedWatchCard?.kind ?? null,
+ }),
+ ],
// The `experiment recordings tab viewed` payload, in a selector so the settled-checks
// report and the beforeUnmount flush send the same shape.
tabViewContext: [
@@ -1243,8 +1446,32 @@ export const experimentReplayTabLogic = kea<experimentReplayTabLogicType>([
// cache. A session's context is independent of the list filters (it's per
// session + viewer), so sessions overlapping across filter changes are already warm
// and the endpoint skips them.
- recordingsLoaded: ({ recordings }) => {
+ recordingsLoaded: ({ recordings, isFirstPage }) => {
actions.prefetchSessionContexts(recordings.map((recording) => recording.id))
+ // Only the first page is the list a viewer opened the tab to; the pages after it are
+ // what scrolling adds. Reporting those too would count one visit as several lists, and
+ // a later page that comes back empty is the end of a list that has rows, not an empty
+ // one. `recording list fetched` covers every page for anyone asking about paging.
+ if (!isFirstPage) {
+ return
+ }
+ // An empty list under an in-flight metric filter is the filter not having answered yet,
+ // which the caption says out loud. Reported, it would count twice: once here and once
+ // when the answer lands and the list reloads.
+ if (recordings.length === 0 && values.sessionBucketLoading) {
+ return
+ }
+ actions.reportExperimentRecordingsListRendered(props.experiment.id, {
+ ...values.filterContext,
+ result_count: recordings.length,
+ empty_reason: recordings.length === 0 ? values.listEmptyReason : null,
+ days_since_start: daysSince(props.experiment.start_date),
+ days_since_end: daysSince(props.experiment.end_date),
+ retention_period: values.currentTeam?.session_recording_retention_period ?? null,
+ replay_opt_in: !!values.currentTeam?.session_recording_opt_in,
+ duration_filter_active: values.durationFilterActive,
+ exposure_linkable: values.exposureLinkable,
+ })
},
// Re-warm the rest of the page whenever the user moves to another recording: the
// server-side cache entries expire on a TTL that starts at prefetch time, so a page
@@ -1256,14 +1483,7 @@ export const experimentReplayTabLogic = kea<experimentReplayTabLogicType>([
actions.prefetchSessionContexts(
values.loadedRecordings.map((recording) => recording.id).filter((id) => id !== sessionId)
)
- actions.reportExperimentRecordingOpened(props.experiment.id, {
- variant: values.effectiveVariantKey,
- exposure_scope: values.effectiveExposureScope,
- metric_filter_mode: values.metricFilterMode,
- selected_metric_count: values.effectiveMetricUuids.length,
- is_bucketed: values.bucketSessionIds !== undefined,
- watch_card_kind: values.selectedWatchCard?.kind ?? null,
- })
+ actions.reportExperimentRecordingOpened(props.experiment.id, values.filterContext)
},
// Both outcomes of the linkability check report the view, since a failed check leaves the
// tab running on its fail-open defaults rather than leaving it unusable. The availability
diff --git a/frontend/src/scenes/experiments/utils.ts b/frontend/src/scenes/experiments/utils.ts
index ae126952e4d7..3a7e39d9af17 100644
--- a/frontend/src/scenes/experiments/utils.ts
+++ b/frontend/src/scenes/experiments/utils.ts
@@ -467,6 +467,18 @@ export function isUnlinkableEventFilter(
)
}
+/**
+ * The single event an experiment's exposure is counted on, for the session-linkability check.
+ * Null for an action exposure config, which can match several events, so no one name applies.
+ */
+export function getExposureLinkabilityEventName(experiment: Experiment): string | null {
+ const exposureConfig = experiment.exposure_criteria?.exposure_config
+ if (exposureConfig && !(isEventExposureConfig(exposureConfig) && exposureConfig.event === EXPOSURE_DEFAULT_EVENT)) {
+ return isEventExposureConfig(exposureConfig) && exposureConfig.event ? exposureConfig.event : null
+ }
+ return resolvedExposureEvent(experiment)
+}
+
/**
* Event names whose session-linkability must be checked before building "View recordings" links:
* the exposure event plus every plain-event metric step across primary, secondary and shared
@@ -477,13 +489,9 @@ export function isUnlinkableEventFilter(
export function getSessionLinkabilityEventNames(experiment: Experiment): string[] {
const eventNames = new Set<string>()
- const exposureConfig = experiment.exposure_criteria?.exposure_config
- if (exposureConfig && !(isEventExposureConfig(exposureConfig) && exposureConfig.event === EXPOSURE_DEFAULT_EVENT)) {
- if (isEventExposureConfig(exposureConfig) && exposureConfig.event) {
- eventNames.add(exposureConfig.event)
- }
- } else {
- eventNames.add(resolvedExposureEvent(experiment))
+ const exposureEventName = getExposureLinkabilityEventName(experiment)
+ if (exposureEventName) {
+ eventNames.add(exposureEventName)
}
const metrics = [
diff --git a/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.ts b/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.ts
index c7653d5af0f2..85a3e16ab4dd 100644
--- a/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.ts
+++ b/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.ts
@@ -461,8 +461,12 @@ export interface SessionRecordingPlaylistLogicProps {
type?: 'filters' | 'collection'
filters?: RecordingUniversalFilters
onFiltersChange?: (filters: RecordingUniversalFilters) => void
- /** Called with each freshly loaded page of recordings (not the accumulated list). */
- onRecordingsLoaded?: (recordings: SessionRecordingType[]) => void
+ /**
+ * Called with each freshly loaded page of recordings (not the accumulated list). `isFirstPage`
+ * is false for the pages scrolling adds on either end, so a host page can tell the list it
+ * first rendered from the ones paging appended to it.
+ */
+ onRecordingsLoaded?: (recordings: SessionRecordingType[], isFirstPage: boolean) => void
/**
* Called once each time the recording the player shows changes — clicked, played next,
* picked via the URL, or the implicit autoplay fallback to the top of the list (on first
@@ -544,11 +548,21 @@ export interface sessionRecordingsPlaylistLogicActions {
loadTime: number,
filters: RecordingUniversalFilters,
defaultDurationFilter: RecordingDurationFilter,
+ page: {
+ hasNext: boolean
+ isFirstPage: boolean
+ resultCount: number
+ },
source?: string | undefined
) => {
defaultDurationFilter: RecordingDurationFilter
filters: RecordingUniversalFilters
loadTime: number
+ page: {
+ hasNext: boolean
+ isFirstPage: boolean
+ resultCount: number
+ }
source: string | undefined
} // sessionRecordingEventUsageLogic
reportRecordingsListFilterAdded: (filterType: SessionRecordingFilterType) => {
@@ -1015,6 +1029,11 @@ export const sessionRecordingsPlaylistLogic = kea<sessionRecordingsPlaylistLogic
loadTimeMs,
filters,
defaultRecordingDurationFilter,
+ {
+ resultCount: response.results.length,
+ hasNext: response.has_next,
+ isFirstPage: !direction,
+ },
props.analyticsSource
)
@@ -1504,9 +1523,11 @@ export const sessionRecordingsPlaylistLogic = kea<sessionRecordingsPlaylistLogic
actions.loadSessionRecordings(direction)
},
- loadSessionRecordingsSuccess: ({ sessionRecordingsResponse }) => {
+ loadSessionRecordingsSuccess: ({ sessionRecordingsResponse, payload }) => {
actions.maybeLoadPropertiesForSessions(values.sessionRecordings)
- props.onRecordingsLoaded?.(sessionRecordingsResponse.results)
+ // A load without a direction replaces the list rather than paging it, the same
+ // reading the `sessionRecordings` reducer takes.
+ props.onRecordingsLoaded?.(sessionRecordingsResponse.results, !payload?.direction)
pruneSelectedRecordingsIds()
notifyRecordingSelected()
},
diff --git a/frontend/src/scenes/session-recordings/sessionRecordingEventUsageLogic.ts b/frontend/src/scenes/session-recordings/sessionRecordingEventUsageLogic.ts
index c36ac9340a09..211aa4d866ae 100644
--- a/frontend/src/scenes/session-recordings/sessionRecordingEventUsageLogic.ts
+++ b/frontend/src/scenes/session-recordings/sessionRecordingEventUsageLogic.ts
@@ -114,11 +114,21 @@ export interface sessionRecordingEventUsageLogicActions {
loadTime: number,
filters: RecordingUniversalFilters,
defaultDurationFilter: RecordingDurationFilter,
+ page: {
+ hasNext: boolean
+ isFirstPage: boolean
+ resultCount: number
+ },
source?: string
) => {
defaultDurationFilter: RecordingDurationFilter
filters: RecordingUniversalFilters
loadTime: number
+ page: {
+ hasNext: boolean
+ isFirstPage: boolean
+ resultCount: number
+ }
source: string | undefined
}
reportRecordingsListFilterAdded: (filterType: SessionRecordingFilterType) => {
@@ -148,12 +158,15 @@ export const sessionRecordingEventUsageLogic = kea<sessionRecordingEventUsageLog
loadTime: number,
filters: RecordingUniversalFilters,
defaultDurationFilter: RecordingDurationFilter,
+ /** What the response held, so an empty list can be told from a full page of results. */
+ page: { resultCount: number; hasNext: boolean; isFirstPage: boolean },
/** Which surface embeds the playlist, so a list load can be read per host page. */
source?: string
) => ({
loadTime,
filters,
defaultDurationFilter,
+ page,
source,
}),
reportRecordingsListPropertiesFetched: (loadTime: number) => ({ loadTime }),
@@ -194,7 +207,7 @@ export const sessionRecordingEventUsageLogic = kea<sessionRecordingEventUsageLog
reportRecordingsListFilterAdded: ({ filterType }) => {
posthog.capture('recording list filter added', { filter_type: filterType })
},
- reportRecordingsListFetched: ({ loadTime, filters, defaultDurationFilter, source }) => {
+ reportRecordingsListFetched: ({ loadTime, filters, defaultDurationFilter, page, source }) => {
metricHistogram('replay_list_load_ms', loadTime, 'ms')
try {
const filterValues = filtersFromUniversalFilterGroups(filters)
@@ -223,6 +236,11 @@ export const sessionRecordingEventUsageLogic = kea<sessionRecordingEventUsageLog
listing_version: '3',
filters,
source,
+ result_count: page.resultCount,
+ has_next: page.hasNext,
+ // False for the pages scrolling adds, which say nothing about what the list
+ // first showed.
+ is_first_page: page.isFirstPage,
...filterBreakdown,
})
} catch (e) {