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.

fix(conversations): read the replay url the widget actually stores (#104450)

Julian Beze47ec0e386ac
diff --git a/products/conversations/frontend/scenes/ticket/SessionRecordingPanel.test.tsx b/products/conversations/frontend/scenes/ticket/SessionRecordingPanel.test.tsx
new file mode 100644
index 000000000000..82977893000c
--- /dev/null
+++ b/products/conversations/frontend/scenes/ticket/SessionRecordingPanel.test.tsx
@@ -0,0 +1,51 @@
+import '@testing-library/jest-dom'
+
+import { cleanup, render, screen } from '@testing-library/react'
+import userEvent from '@testing-library/user-event'
+
+import { recordingIdFromReplayUrl, SessionRecordingPanel } from './SessionRecordingPanel'
+
+jest.mock('scenes/session-recordings/player/SessionRecordingPlayer', () => ({
+ SessionRecordingPlayer: ({ sessionRecordingId }: { sessionRecordingId: string }) => (
+ <div data-attr="session-recording-player">{sessionRecordingId}</div>
+ ),
+}))
+
+describe('recordingIdFromReplayUrl', () => {
+ it.each([
+ ['https://us.posthog.com/replay/01890abc', '01890abc'],
+ ['https://us.posthog.com/replay/01890abc?t=12', '01890abc'],
+ ['https://us.posthog.com/replay/01890abc/', '01890abc'],
+ ['/replay/01890abc', '01890abc'],
+ ])('reads the recording id out of %s', (replayUrl, expected) => {
+ expect(recordingIdFromReplayUrl(replayUrl)).toEqual(expected)
+ })
+
+ it.each([[undefined], ['']])('returns null for %s', (replayUrl) => {
+ expect(recordingIdFromReplayUrl(replayUrl)).toBeNull()
+ })
+})
+
+// These exercise the component's `sessionContext?.replay_url` wiring, not just the helper, so a
+// revert to the old `session_replay_url` key would fail here even though the helper still works.
+describe('SessionRecordingPanel', () => {
+ afterEach(() => {
+ cleanup()
+ })
+
+ it('passes the id parsed from sessionContext.replay_url to the player', async () => {
+ render(<SessionRecordingPanel sessionContext={{ replay_url: 'https://us.posthog.com/replay/01890abc' }} />)
+
+ await userEvent.click(screen.getByText('Session recording'))
+
+ expect(screen.getByText('01890abc')).toBeInTheDocument()
+ })
+
+ it('shows the empty state when sessionContext has no replay_url', async () => {
+ render(<SessionRecordingPanel sessionContext={{}} />)
+
+ await userEvent.click(screen.getByText('Session recording'))
+
+ expect(screen.getByText('No session recording available')).toBeInTheDocument()
+ })
+})
diff --git a/products/conversations/frontend/scenes/ticket/SessionRecordingPanel.tsx b/products/conversations/frontend/scenes/ticket/SessionRecordingPanel.tsx
index edadae3356ad..a3a0b02fca5f 100644
--- a/products/conversations/frontend/scenes/ticket/SessionRecordingPanel.tsx
+++ b/products/conversations/frontend/scenes/ticket/SessionRecordingPanel.tsx
@@ -7,18 +7,22 @@ import { PersonsTabType } from '~/types'
interface SessionRecordingPanelProps {
sessionContext?: {
- session_replay_url?: string
+ replay_url?: unknown
[key: string]: any
}
distinctId?: string
}
+/** The widget stores the replay URL under `replay_url`. The id is its last path segment. */
+export function recordingIdFromReplayUrl(replayUrl: unknown): string | null {
+ if (typeof replayUrl !== 'string' || !replayUrl) {
+ return null
+ }
+ return replayUrl.split('?')[0].split('/').filter(Boolean).pop() ?? null
+}
+
export function SessionRecordingPanel({ sessionContext, distinctId }: SessionRecordingPanelProps): JSX.Element {
- // Extract recording ID from session_replay_url
- // URL format: /replay/:recordingId or similar
- const recordingId = sessionContext?.session_replay_url
- ? sessionContext.session_replay_url.split('?')[0].split('/').filter(Boolean).pop()
- : null
+ const recordingId = recordingIdFromReplayUrl(sessionContext?.replay_url)
return (
<LemonCollapse
diff --git a/products/conversations/frontend/types.ts b/products/conversations/frontend/types.ts
index 9db1611b077a..b411688e1ef6 100644
--- a/products/conversations/frontend/types.ts
+++ b/products/conversations/frontend/types.ts
@@ -163,7 +163,7 @@ export interface Ticket {
unread_customer_count: number
session_id?: string
session_context?: {
- session_replay_url?: string
+ replay_url?: string
current_url?: string
[key: string]: any
}
@@ -199,7 +199,7 @@ export interface ConversationTicket {
unread_count?: number
session_id?: string
session_context?: {
- session_replay_url?: string
+ replay_url?: string
current_url?: string
[key: string]: any
}