: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
feat(replay): add button for copying summaries (#57685)
Hayne Ryuf9f828023513
diff --git a/frontend/src/scenes/session-recordings/player/PlayerSummaryDock.tsx b/frontend/src/scenes/session-recordings/player/PlayerSummaryDock.tsxindex 2d5b066ceb86..c90cb3c80793 100644--- a/frontend/src/scenes/session-recordings/player/PlayerSummaryDock.tsx+++ b/frontend/src/scenes/session-recordings/player/PlayerSummaryDock.tsx@@ -2,17 +2,20 @@ import clsx from 'clsx'import { useActions, useValues } from 'kea'import { useEffect, useRef } from 'react'-import { IconChevronDown, IconMagicWand, IconX } from '@posthog/icons'+import { IconChevronDown, IconCopy, IconMagicWand, IconX } from '@posthog/icons'import { LemonBanner, LemonButton, Spinner } from '@posthog/lemon-ui'import { Resizer } from 'lib/components/Resizer/Resizer'import { ResizerLogicProps, resizerLogic } from 'lib/components/Resizer/resizerLogic'import { FEATURE_FLAGS } from 'lib/constants'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'+import { copyToClipboard } from 'lib/utils/copyToClipboard'+import { urls } from 'scenes/urls'import { sessionRecordingEventUsageLogic } from '../sessionRecordingEventUsageLogic'import { playerMetaLogic } from './player-meta/playerMetaLogic'import { sessionSummaryProgressLogic } from './player-meta/sessionSummaryProgressLogic'+import { SessionSummaryContent } from './player-meta/types'import { LoadingTimer, SessionSummary, SummarizationProgressView } from './PlayerSummaryViews'import { sessionRecordingPlayerLogic } from './sessionRecordingPlayerLogic'@@ -21,6 +24,52 @@ const DEFAULT_EXPANDED_HEIGHT = 480const MIN_EXPANDED_HEIGHT = 120const MAX_EXPANDED_HEIGHT = 800+function formatSessionSummary(summary: SessionSummaryContent, sessionId: string): string {+ const recordingUrl = window.location.origin + urls.replaySingle(sessionId)+ const lines: string[] = [`Session ID: ${sessionId}`, `Recording: ${recordingUrl}`, '']++ if (summary.session_outcome?.description) {+ const outcomeLabel = summary.session_outcome.success === false ? 'Failure' : 'Success'+ lines.push(`Outcome: ${outcomeLabel}`, summary.session_outcome.description, '')+ }++ summary.segments?.forEach((segment, i) => {+ lines.push(`${i + 1}. ${segment.name ?? 'Unnamed segment'}`)++ const segmentOutcome = summary.segment_outcomes?.find((o) => o.segment_index === segment.index)+ if (segmentOutcome) {+ const outcomeLabel = segmentOutcome.success === false ? 'Failure' : 'Success'+ lines.push(` Outcome: ${outcomeLabel}`)+ if (segmentOutcome.summary) {+ lines.push(` ${segmentOutcome.summary}`)+ }+ }++ const events = (summary.key_actions ?? [])+ .filter((k) => k.segment_index === segment.index)+ .flatMap((k) => k.events ?? [])+ if (events.length) {+ lines.push(' Key actions:')+ events.forEach((event) => {+ const parts: string[] = []+ if (event.description) {+ parts.push(event.description)+ }+ if (event.event_type) {+ parts.push(`[${event.event_type}]`)+ }+ if (event.current_url) {+ parts.push(`@ ${event.current_url}`)+ }+ lines.push(` - ${parts.join(' ')}`)+ })+ }+ lines.push('')+ })++ return lines.join('\n').trim()+}+export function PlayerSummaryDock(): JSX.Element | null {const { featureFlags } = useValues(featureFlagLogic)const { logicProps, sessionRecordingId, sessionPlayerData } = useValues(sessionRecordingPlayerLogic)@@ -35,7 +84,9 @@ export function PlayerSummaryDock(): JSX.Element | null {const { summarizeSession } = useActions(playerMetaLogic(logicProps))const { openBySessionId, summaryIdBySessionId } = useValues(sessionSummaryProgressLogic)const { setSummaryOpen, cancelSummarization } = useActions(sessionSummaryProgressLogic)- const { reportAISessionSummaryViewed } = useActions(sessionRecordingEventUsageLogic)+ const { reportAISessionSummaryViewed, reportAISessionSummaryCopiedForLLM } = useActions(+ sessionRecordingEventUsageLogic+ )const dockRef = useRef<HTMLDivElement>(null)const resizerProps: ResizerLogicProps = {@@ -120,15 +171,47 @@ export function PlayerSummaryDock(): JSX.Element | null {Use AI to summarize this session</LemonButton>)}- {(hasContentToExpand || isOpen) && (- <LemonButton- size="small"- icon={<IconChevronDown className={isOpen ? '' : 'rotate-180'} />}- onClick={() => setIsOpen(!isOpen)}- tooltip={isOpen ? 'Collapse' : 'Expand'}- aria-label={isOpen ? 'Collapse summary' : 'Expand summary'}- />- )}+ <div className="flex items-center gap-1">+ {sessionSummary && (+ <LemonButton+ size="small"+ type="secondary"+ icon={<IconCopy />}+ tooltip="Copy session summary for LLM"+ aria-label="Copy session summary for LLM"+ data-attr="copy-session-summary-for-llm"+ onClick={async () => {+ const success = await copyToClipboard(+ formatSessionSummary(sessionSummary, sessionRecordingId),+ 'session summary'+ )+ if (!success) {+ return+ }+ reportAISessionSummaryCopiedForLLM(sessionRecordingId, {+ segment_count: sessionSummary.segments?.length ?? 0,+ key_action_count:+ sessionSummary.key_actions?.reduce(+ (sum, k) => sum + (k.events?.length ?? 0),+ 0+ ) ?? 0,+ has_session_outcome: !!sessionSummary.session_outcome,+ })+ }}+ >+ Copy+ </LemonButton>+ )}+ {(hasContentToExpand || isOpen) && (+ <LemonButton+ size="small"+ icon={<IconChevronDown className={isOpen ? '' : 'rotate-180'} />}+ onClick={() => setIsOpen(!isOpen)}+ tooltip={isOpen ? 'Collapse' : 'Expand'}+ aria-label={isOpen ? 'Collapse summary' : 'Expand summary'}+ />+ )}+ </div></div>{isOpen && (<div className="flex-1 overflow-y-auto px-3 pb-3">diff --git a/frontend/src/scenes/session-recordings/sessionRecordingEventUsageLogic.ts b/frontend/src/scenes/session-recordings/sessionRecordingEventUsageLogic.tsindex a8771d604f42..f7e7e07c9d33 100644--- a/frontend/src/scenes/session-recordings/sessionRecordingEventUsageLogic.ts+++ b/frontend/src/scenes/session-recordings/sessionRecordingEventUsageLogic.ts@@ -77,6 +77,10 @@ export const sessionRecordingEventUsageLogic = kea<sessionRecordingEventUsageLogsource,summary_id,}),+ reportAISessionSummaryCopiedForLLM: (+ recording_id: string,+ properties: { segment_count: number; key_action_count: number; has_session_outcome: boolean }+ ) => ({ recording_id, ...properties }),}),listeners(() => ({reportRecordingLoaded: ({ playerData, metadata }) => {@@ -163,5 +167,18 @@ export const sessionRecordingEventUsageLogic = kea<sessionRecordingEventUsageLogreportAISessionSummaryViewed: ({ recording_id, source, summary_id }) => {posthog.capture('ai session summary viewed', { recording_id, source, summary_id })},+ reportAISessionSummaryCopiedForLLM: ({+ recording_id,+ segment_count,+ key_action_count,+ has_session_outcome,+ }) => {+ posthog.capture('ai session summary copied for llm', {+ recording_id,+ segment_count,+ key_action_count,+ has_session_outcome,+ })+ },})),])