: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
import { MakeLogicType, connect, kea, key, path, props } from 'kea'
import { loaders } from 'kea-loaders'
import api from 'lib/api'
import { teamLogic } from 'scenes/teamLogic'
export interface SessionRecordingViewedResult {
viewed: boolean
otherViewers: number
}
export type SessionRecordingViewedProps = {
sessionRecordingId: string
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface sessionRecordingViewedLogicValues {
currentTeamId: number | null // teamLogic
recordingViewed: any
recordingViewedLoading: boolean
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface sessionRecordingViewedLogicActions {
loadRecordingViewed: () => any
loadRecordingViewedFailure: (
error: string,
errorObject?: any
) => {
error: string
errorObject?: any
}
loadRecordingViewedSuccess: (
recordingViewed: SessionRecordingViewedResult,
payload?: any
) => {
recordingViewed: SessionRecordingViewedResult
payload?: any
}
userClickedThrough: () => any
userClickedThroughFailure: (
error: string,
errorObject?: any
) => {
error: string
errorObject?: any
}
userClickedThroughSuccess: (
recordingViewed: {
otherViewers: any
viewed: boolean
},
payload?: any
) => {
recordingViewed: {
otherViewers: any
viewed: boolean
}
payload?: any
}
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface sessionRecordingViewedLogicMeta {
key: string
}
export type sessionRecordingViewedLogicType = MakeLogicType<
sessionRecordingViewedLogicValues,
sessionRecordingViewedLogicActions,
SessionRecordingViewedProps,
sessionRecordingViewedLogicMeta
>
export const sessionRecordingViewedLogic = kea<sessionRecordingViewedLogicType>([
path(['lib', 'components', 'ViewRecordingButton', 'sessionRecordingViewedLogic']),
key((props: Record<string, unknown>) => props.sessionRecordingId as string),
props({} as unknown as SessionRecordingViewedProps),
connect(() => ({
values: [teamLogic, ['currentTeamId']],
})),
loaders(({ props, values }) => ({
recordingViewed: {
loadRecordingViewed: async (): Promise<SessionRecordingViewedResult> => {
if (!props.sessionRecordingId || !values.currentTeamId || props.sessionRecordingId === '') {
return { viewed: false, otherViewers: 0 }
}
// nosemgrep: prefer-codegen-api -- Legacy raw API call with a hand-written URL and an unchecked response type. No generated function covers this endpoint yet. Find out why the generated client skips it (no schema, no product tag, or excluded from the spec) and fix that first.
const response = await api.get(
`/api/projects/${values.currentTeamId}/session_recordings/${props.sessionRecordingId}/viewed`
)
return response as SessionRecordingViewedResult
},
userClickedThrough: async () => {
return { viewed: true, otherViewers: values.recordingViewed?.otherViewers ?? 0 }
},
},
})),
])