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(replay): report third what-to-watch impression for survey trigger (#116165)

Hayne Ryue797ee2874cc
diff --git a/products/replay_vision/frontend/replay_scanners/watchPicksLogic.test.ts b/products/replay_vision/frontend/replay_scanners/watchPicksLogic.test.ts
index b3fc519dbece..ce7d7aca17cb 100644
--- a/products/replay_vision/frontend/replay_scanners/watchPicksLogic.test.ts
+++ b/products/replay_vision/frontend/replay_scanners/watchPicksLogic.test.ts
@@ -7,7 +7,7 @@ import { sessionRecordingsPlaylistLogic } from 'scenes/session-recordings/playli
import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'
-import { watchPicksLogic } from './watchPicksLogic'
+import { PICKS_SHOWN_COUNT_STORAGE_KEY, watchPicksLogic } from './watchPicksLogic'
import { watchPicksVariantFromFlag } from './watchPicksVariant'
describe('watchPicksLogic', () => {
@@ -89,7 +89,24 @@ describe('watchPicksLogic', () => {
it('opens on the picks and reports the impression with its count', () => {
expect(logic.values.effectiveListMode).toBe('picks')
- expect(shownEvents()).toEqual([{ view: 'list', count: 3, unwatched_count: 3 }])
+ expect(shownEvents()).toEqual([{ view: 'list', count: 3, unwatched_count: 3, shown_count: 1 }])
+ })
+
+ it.each([
+ [1, []],
+ [2, [{ view: 'list' }]],
+ [3, []],
+ ])('reports the third impression as its own event (stored count %i)', async (stored, thirdTimeEvents) => {
+ logic.unmount()
+ playlistLogic.unmount()
+ localStorage.setItem(PICKS_SHOWN_COUNT_STORAGE_KEY, String(stored))
+ await mountList()
+ expect(
+ captureSpy.mock.calls
+ .filter(([name]) => name === 'replay_vision_watch_picks_shown_third_time')
+ .map((call) => call[1])
+ ).toEqual(thirdTimeEvents)
+ expect(localStorage.getItem(PICKS_SHOWN_COUNT_STORAGE_KEY)).toBe(String(stored + 1))
})
it.each([
diff --git a/products/replay_vision/frontend/replay_scanners/watchPicksLogic.ts b/products/replay_vision/frontend/replay_scanners/watchPicksLogic.ts
index c4cd83bd507c..191c82d034d7 100644
--- a/products/replay_vision/frontend/replay_scanners/watchPicksLogic.ts
+++ b/products/replay_vision/frontend/replay_scanners/watchPicksLogic.ts
@@ -15,8 +15,10 @@ import {
} from 'kea'
import { loaders } from 'kea-loaders'
import { router } from 'kea-router'
+import { z } from 'zod'
import posthog from 'lib/posthog-typed'
+import { localStorageSlot } from 'lib/utils/localStorageSlot'
import {
SessionRecordingPlaylistLogicProps,
sessionRecordingsPlaylistLogic,
@@ -43,6 +45,13 @@ export const TOP_PICKS_COUNT = 10
const PICKS_LIMIT = 50
const PICKS_DATE_FROM = '-7d'
+// Survey display conditions can only trigger on an event name, so the third
+// impression of the picks (on the Watch tab or the in-list toggle) is reported
+// as its own event. The impression count lives in this browser only
+export const PICKS_SHOWN_SURVEY_IMPRESSION = 3
+export const PICKS_SHOWN_COUNT_STORAGE_KEY = 'replay-vision.watch-picks-shown-count'
+const picksShownCount = localStorageSlot(PICKS_SHOWN_COUNT_STORAGE_KEY, z.number().int().nonnegative())
+
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface watchPicksLogicValues {
currentTeamId: number | null // teamLogic
@@ -234,14 +243,21 @@ export const watchPicksLogic: LogicWrapper<watchPicksLogicType> = kea<watchPicks
if (!values.picks || (props.playlistLogicProps && values.effectiveListMode !== 'picks')) {
return
}
+ const view = props.playlistLogicProps ? 'list' : 'page'
+ const shownCount = (picksShownCount.get() ?? 0) + 1
+ picksShownCount.set(shownCount)
posthog.capture('replay_vision_watch_picks_shown', {
- view: props.playlistLogicProps ? 'list' : 'page',
+ view,
entry: props.playlistLogicProps
? undefined
: sessionReplaySceneLogic.findMounted()?.values.watchTabEntry,
count: values.picks.length,
unwatched_count: values.unwatchedCount,
+ shown_count: shownCount,
})
+ if (shownCount === PICKS_SHOWN_SURVEY_IMPRESSION) {
+ posthog.capture('replay_vision_watch_picks_shown_third_time', { view })
+ }
}
return {
loadPicksSuccess: () => {