: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(replay): dedupe replay summary event (#57787)
Hayne Ryu09e741e1024a
diff --git a/frontend/src/scenes/session-recordings/player/PlayerSummaryDock.tsx b/frontend/src/scenes/session-recordings/player/PlayerSummaryDock.tsxindex f04482a3b056..2d5b066ceb86 100644--- a/frontend/src/scenes/session-recordings/player/PlayerSummaryDock.tsx+++ b/frontend/src/scenes/session-recordings/player/PlayerSummaryDock.tsx@@ -33,7 +33,7 @@ export function PlayerSummaryDock(): JSX.Element | null {summaryDisabledReason,} = useValues(playerMetaLogic(logicProps))const { summarizeSession } = useActions(playerMetaLogic(logicProps))- const { openBySessionId } = useValues(sessionSummaryProgressLogic)+ const { openBySessionId, summaryIdBySessionId } = useValues(sessionSummaryProgressLogic)const { setSummaryOpen, cancelSummarization } = useActions(sessionSummaryProgressLogic)const { reportAISessionSummaryViewed } = useActions(sessionRecordingEventUsageLogic)@@ -48,17 +48,28 @@ export function PlayerSummaryDock(): JSX.Element | null {const isEnabled = featureFlags[FEATURE_FLAGS.REPLAY_VIDEO_BASED_SUMMARIZATION]const hasSummary = !!sessionSummaryconst isOpen = !!openBySessionId[sessionRecordingId]+ const summaryId = summaryIdBySessionId[sessionRecordingId] ?? null+ const hasRenderedSummary = hasSummary && !sessionSummaryErrorconst setIsOpen = (open: boolean): void => setSummaryOpen(sessionRecordingId, open)const expandedHeight = Math.max(MIN_EXPANDED_HEIGHT,Math.min(MAX_EXPANDED_HEIGHT, desiredSize ?? DEFAULT_EXPANDED_HEIGHT))+ // `isOpen` flips multiple times per summary, so dedupe to one capture per render.+ const capturedKeyRef = useRef<string | null>(null)+useEffect(() => {- if (sessionRecordingId && isOpen) {- reportAISessionSummaryViewed(sessionRecordingId, 'dock')+ if (!sessionRecordingId || !isOpen || !hasRenderedSummary) {+ return+ }+ const key = `${sessionRecordingId}|${summaryId ?? 'unknown'}`+ if (capturedKeyRef.current === key) {+ return}- }, [sessionRecordingId, isOpen, reportAISessionSummaryViewed])+ capturedKeyRef.current = key+ reportAISessionSummaryViewed(sessionRecordingId, 'dock', summaryId)+ }, [sessionRecordingId, isOpen, hasRenderedSummary, summaryId, reportAISessionSummaryViewed])if (!isEnabled) {return nulldiff --git a/frontend/src/scenes/session-recordings/sessionRecordingEventUsageLogic.ts b/frontend/src/scenes/session-recordings/sessionRecordingEventUsageLogic.tsindex ee36dd6e7ae0..a8771d604f42 100644--- a/frontend/src/scenes/session-recordings/sessionRecordingEventUsageLogic.ts+++ b/frontend/src/scenes/session-recordings/sessionRecordingEventUsageLogic.ts@@ -72,7 +72,11 @@ export const sessionRecordingEventUsageLogic = kea<sessionRecordingEventUsageLogreportRecordingPinnedToList: (pinned: boolean) => ({ pinned }),reportRecordingPlaylistCreated: (source: 'filters' | 'new' | 'pin' | 'duplicate') => ({ source }),reportRecordingOpenedFromRecentRecordingList: true,- reportAISessionSummaryViewed: (recording_id: string, source: 'dock') => ({ recording_id, source }),+ reportAISessionSummaryViewed: (recording_id: string, source: 'dock', summary_id: string | null) => ({+ recording_id,+ source,+ summary_id,+ }),}),listeners(() => ({reportRecordingLoaded: ({ playerData, metadata }) => {@@ -156,8 +160,8 @@ export const sessionRecordingEventUsageLogic = kea<sessionRecordingEventUsageLogreportRecordingPlaylistCreated: (properties) => {posthog.capture('recording playlist created', properties)},- reportAISessionSummaryViewed: ({ recording_id, source }) => {- posthog.capture('ai session summary viewed', { recording_id, source })+ reportAISessionSummaryViewed: ({ recording_id, source, summary_id }) => {+ posthog.capture('ai session summary viewed', { recording_id, source, summary_id })},})),])