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(surveys): view recording from open text response cards (#58430)

Lucas Faria99b6faf2a5c7
diff --git a/frontend/src/scenes/surveys/components/question-visualizations/VirtualizedResponseList.tsx b/frontend/src/scenes/surveys/components/question-visualizations/VirtualizedResponseList.tsx
index 2a18640aebad..d5da08d06cc8 100644
--- a/frontend/src/scenes/surveys/components/question-visualizations/VirtualizedResponseList.tsx
+++ b/frontend/src/scenes/surveys/components/question-visualizations/VirtualizedResponseList.tsx
@@ -3,6 +3,7 @@ import { Grid } from 'react-window'
import { AutoSizer } from 'lib/components/AutoSizer'
import { TZLabel } from 'lib/components/TZLabel'
+import ViewRecordingButton, { ViewRecordingButtonVariant } from 'lib/components/ViewRecordingButton/ViewRecordingButton'
import { useWindowSize } from 'lib/hooks/useWindowSize'
import { Popover } from 'lib/lemon-ui/Popover'
import { PersonDisplay } from 'scenes/persons/PersonDisplay'
@@ -32,16 +33,30 @@ function ResponseListItem({ response }: { response: OpenQuestionResponseData }):
onClick={isLongResponse ? () => setIsExpanded(!isExpanded) : undefined}
>
<div className="text-sm truncate mb-auto">{responseText}</div>
- <div className="flex items-center justify-between text-xs text-secondary mt-1">
- <PersonDisplay
- person={{ distinct_id: response.distinctId }}
- displayName={response.personDisplayName}
- withIcon="xs"
- noEllipsis={false}
- noLink={!response.distinctId}
- muted
- />
- {response.timestamp && <TZLabel time={response.timestamp} formatDate="MMM D" formatTime="HH:mm" />}
+ <div className="flex items-center justify-between text-xs text-secondary mt-1 gap-2 min-w-0">
+ <div className="min-w-0 flex-1">
+ <PersonDisplay
+ person={{ distinct_id: response.distinctId }}
+ displayName={response.personDisplayName}
+ withIcon="xs"
+ noEllipsis={false}
+ noLink={!response.distinctId}
+ muted
+ />
+ </div>
+ <div
+ className="flex items-center gap-2 shrink-0 whitespace-nowrap"
+ onClick={(e) => e.stopPropagation()}
+ >
+ <ViewRecordingButton
+ sessionId={response.sessionId}
+ timestamp={response.timestamp}
+ variant={ViewRecordingButtonVariant.Link}
+ className="whitespace-nowrap"
+ checkRecordingExists
+ />
+ {response.timestamp && <TZLabel time={response.timestamp} formatDate="MMM D" formatTime="HH:mm" />}
+ </div>
</div>
</div>
)
@@ -67,7 +82,15 @@ function ResponseListItem({ response }: { response: OpenQuestionResponseData }):
noEllipsis={false}
noLink={!response.distinctId}
/>
- {response.timestamp && <TZLabel time={response.timestamp} />}
+ <div className="flex items-center gap-2">
+ <ViewRecordingButton
+ sessionId={response.sessionId}
+ timestamp={response.timestamp}
+ size="xsmall"
+ checkRecordingExists
+ />
+ {response.timestamp && <TZLabel time={response.timestamp} />}
+ </div>
</div>
</div>
}
@@ -120,8 +143,8 @@ export function VirtualizedResponseList({
className,
}: VirtualizedResponseListProps): JSX.Element {
const { isWindowLessThan } = useWindowSize()
- const isMobile = isWindowLessThan('sm')
- const columnCount = isMobile ? 1 : 2
+ const isNarrow = isWindowLessThan('md')
+ const columnCount = isNarrow ? 1 : 2
const rowCount = Math.ceil(responses.length / columnCount)
const [isAtBottom, setIsAtBottom] = useState(false)
@@ -140,7 +163,7 @@ export function VirtualizedResponseList({
if (responses.length <= MAX_STATIC_RESPONSES) {
return (
- <div className={`grid grid-cols-1 sm:grid-cols-2 gap-3 ${className ?? ''}`}>
+ <div className={`grid grid-cols-1 md:grid-cols-2 gap-3 ${className ?? ''}`}>
{responses.map((response, index) => (
<ResponseListItem key={`${response.distinctId}-${index}`} response={response} />
))}
diff --git a/frontend/src/scenes/surveys/surveyLogic.test.ts b/frontend/src/scenes/surveys/surveyLogic.test.ts
index 4586be6a1c66..5aae47dd16ef 100644
--- a/frontend/src/scenes/surveys/surveyLogic.test.ts
+++ b/frontend/src/scenes/surveys/surveyLogic.test.ts
@@ -2309,9 +2309,9 @@ describe('processOpenEndedResults', () => {
'open-q1': { columnIndex: 0, questionIndex: 0, type: SurveyQuestionType.Open },
}
const rows = [
- ['Great product!', 'user123', '2024-01-15T10:30:00Z'],
- ['Could be better', 'user456', '2024-01-15T11:45:00Z'],
- ['', 'user789', '2024-01-15T12:00:00Z'],
+ ['Great product!', 'user123', '2024-01-15T10:30:00Z', 'session-abc'],
+ ['Could be better', 'user456', '2024-01-15T11:45:00Z', ''],
+ ['', 'user789', '2024-01-15T12:00:00Z', 'session-xyz'],
]
const result = processOpenEndedResults(questions, columnMap, rows)
@@ -2324,11 +2324,13 @@ describe('processOpenEndedResults', () => {
distinctId: 'user123',
response: 'Great product!',
timestamp: '2024-01-15T10:30:00Z',
+ sessionId: 'session-abc',
})
expect(openData.data[1]).toEqual({
distinctId: 'user456',
response: 'Could be better',
timestamp: '2024-01-15T11:45:00Z',
+ sessionId: undefined,
})
})
diff --git a/frontend/src/scenes/surveys/surveyLogic.tsx b/frontend/src/scenes/surveys/surveyLogic.tsx
index db30547b4b9b..d59f6df07ed7 100644
--- a/frontend/src/scenes/surveys/surveyLogic.tsx
+++ b/frontend/src/scenes/surveys/surveyLogic.tsx
@@ -543,6 +543,7 @@ export function processOpenEndedResults(
const numCols = Object.keys(columnMap).length
const distinctIdIdx = numCols
const timestampIdx = numCols + 1
+ const sessionIdIdx = numCols + 2
const result: ResponsesByQuestion = {}
for (const [questionId, { columnIndex, type }] of Object.entries(columnMap)) {
@@ -557,6 +558,7 @@ export function processOpenEndedResults(
distinctId: row[distinctIdIdx] as string,
response: value,
timestamp: row[timestampIdx] as string,
+ sessionId: (row[sessionIdIdx] as string) || undefined,
})
}
result[questionId] = { type: SurveyQuestionType.Open, data, totalResponses: data.length }
diff --git a/frontend/src/scenes/surveys/utils.ts b/frontend/src/scenes/surveys/utils.ts
index f9f69dfb057d..183eb4a6ea65 100644
--- a/frontend/src/scenes/surveys/utils.ts
+++ b/frontend/src/scenes/surveys/utils.ts
@@ -735,7 +735,8 @@ export function buildOpenEndedQuery(
const query = `SELECT
${openColumns.join(',\n')},
events.distinct_id,
- events.timestamp
+ events.timestamp,
+ events.properties.$session_id
FROM events
WHERE event = '${SurveyEventName.SENT}'
AND properties.${SurveyEventProperties.SURVEY_ID} = '${survey.id}'
diff --git a/frontend/src/types.ts b/frontend/src/types.ts
index e0b8c238f7ea..9a410f50c732 100644
--- a/frontend/src/types.ts
+++ b/frontend/src/types.ts
@@ -3490,6 +3490,7 @@ export interface OpenQuestionResponseData {
/** Pre-computed display name from server (email, name, etc.) - avoids brittle client-side property extraction */
personDisplayName?: string
timestamp?: string
+ sessionId?: string
}
export interface ChoiceQuestionProcessedResponses {