️(frontend) optimize PostHog survey usage and enrich event metadata

Replace costly PostHog surveys with basic surveys, which better
fit our headless usage and avoid short data retention limits.

Enhance emitted events with additional metadata, including a
unique session ID and room ID, to correlate survey responses with
specific sessions.

This lays the groundwork for further enrichment with participant
connection data.
This commit is contained in:
lebaudantoine
2026-04-09 10:08:24 +02:00
parent 037166fb21
commit 170763a1f7
3 changed files with 49 additions and 12 deletions
@@ -230,7 +230,13 @@ export const Conference = ({
onDisconnected={(e) => {
switch (e) {
case DisconnectReason.CLIENT_INITIATED:
navigateTo('feedback')
navigateTo(
'feedback',
{},
{
state: { room_id: roomId },
}
)
return
case DisconnectReason.DUPLICATE_IDENTITY:
case DisconnectReason.PARTICIPANT_REMOVED:
@@ -238,7 +244,7 @@ export const Conference = ({
'feedback',
{},
{
state: { reason: e },
state: { reason: e, room_id: roomId },
}
)
return
@@ -73,9 +73,11 @@ const labelRecipe = cva({
const OpenFeedback = ({
posthog,
onNext,
metadata,
}: {
posthog: PostHog
onNext: () => void
metadata?: Record<string, unknown>
}) => {
const { t } = useTranslation('rooms', { keyPrefix: 'openFeedback' })
const [feedback, setFeedback] = useState('')
@@ -87,9 +89,9 @@ const OpenFeedback = ({
const onSubmit = () => {
try {
posthog.capture('survey sent', {
$survey_id: '01933c5a-5a1d-0000-ada8-e39f5918c2d4',
$survey_response: feedback,
posthog.capture('open-feedback', {
feedback,
...metadata,
})
} catch (e) {
console.warn(e)
@@ -140,10 +142,12 @@ const OpenFeedback = ({
const RateQuality = ({
posthog,
onNext,
metadata,
maxRating = 7,
}: {
posthog: PostHog
onNext: () => void
metadata?: Record<string, unknown>
maxRating?: number
}) => {
const { t } = useTranslation('rooms', { keyPrefix: 'rating' })
@@ -155,9 +159,9 @@ const RateQuality = ({
const onSubmit = () => {
try {
posthog.capture('survey sent', {
$survey_id: '01933c22-d005-0000-b623-20b752171e2e',
$survey_response: `${selectedRating}`,
posthog.capture('quality-rating', {
rating: selectedRating,
...metadata,
})
} catch (e) {
console.warn(e)
@@ -299,7 +303,7 @@ const AuthenticationMessage = ({
)
}
export const Rating = () => {
export const Rating = ({ roomId }: { roomId?: string }) => {
const isAnalyticsEnabled = useIsAnalyticsEnabled()
const posthog = usePostHog()
@@ -309,14 +313,36 @@ export const Rating = () => {
const [step, setStep] = useState(0)
const sessionId = useMemo(() => crypto.randomUUID(), [])
const metadata = useMemo(
() => ({
session_id: sessionId,
room_id: roomId,
}),
[roomId, sessionId]
)
if (!isAnalyticsEnabled) return
if (step == 0) {
return <RateQuality posthog={posthog} onNext={() => setStep(step + 1)} />
return (
<RateQuality
posthog={posthog}
onNext={() => setStep(step + 1)}
metadata={metadata}
/>
)
}
if (step == 1) {
return <OpenFeedback posthog={posthog} onNext={() => setStep(step + 1)} />
return (
<OpenFeedback
posthog={posthog}
onNext={() => setStep(step + 1)}
metadata={metadata}
/>
)
}
if (step == 2) {
@@ -43,6 +43,11 @@ export const FeedbackRoute = () => {
}
}, [])
const roomId = useMemo(() => {
const state = window.history.state
return state?.room_id
}, [])
const showBackButton = reasonKey !== DisconnectReasonKey.ParticipantRemoved
return (
@@ -60,7 +65,7 @@ export const FeedbackRoute = () => {
{t('feedback.home')}
</Button>
</HStack>
<Rating />
<Rating roomId={roomId} />
</VStack>
</Center>
</Screen>