: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
chore(replay): rename what to watch tab to filter templates (#61626)
Paul D'Ambra460673093b8c
diff --git a/frontend/src/scenes/session-recordings/SessionRecordings.tsx b/frontend/src/scenes/session-recordings/SessionRecordings.tsxindex 8c211ab6fe67..ce25332a0256 100644--- a/frontend/src/scenes/session-recordings/SessionRecordings.tsx+++ b/frontend/src/scenes/session-recordings/SessionRecordings.tsx@@ -237,7 +237,7 @@ const ReplayPageTabs: ReplayTab[] = ['data-attr': 'session-recordings-collections-tab',},{- label: 'What to watch',+ label: 'Filter templates',key: ReplayTabs.Templates,'data-attr': 'session-recordings-templates-tab',},diff --git a/frontend/src/scenes/session-recordings/components/ReplayActiveHoursHeatMap.tsx b/frontend/src/scenes/session-recordings/components/ReplayActiveHoursHeatMap.tsxdeleted file mode 100644index 6f28e42e550c..000000000000--- a/frontend/src/scenes/session-recordings/components/ReplayActiveHoursHeatMap.tsx+++ /dev/null@@ -1,34 +0,0 @@-import { useValues } from 'kea'--import { teamLogic } from 'scenes/teamLogic'-import { CalendarHeatMap } from 'scenes/web-analytics/CalendarHeatMap/CalendarHeatMap'--import { getOnClickTooltip, onCellClick, replayActiveHoursHeatMapLogic } from './replayActiveHoursHeatMapLogic'--export const ReplayActiveHoursHeatMap = (): JSX.Element => {- const { timezone } = useValues(teamLogic)- const { calendarHeatmapProps, recordingsPerHourLoading, isClickable } = useValues(- replayActiveHoursHeatMapLogic({ scene: 'templates' })- )-- return (- <div className="w-full flex flex-col">- <h2>When are your users most active?</h2>- <p>This heatmap shows you the busiest times of day for your recordings over the last 7 days.</p>- <CalendarHeatMap- isLoading={recordingsPerHourLoading}- {...calendarHeatmapProps}- allAggregationsLabel=""- getDataTooltip={() => ''}- getColumnAggregationTooltip={() => ''}- getRowAggregationTooltip={() => ''}- getOverallAggregationTooltip={() => ''}- getOnClickTooltip={getOnClickTooltip}- onClick={(colIndex, rowIndex) => onCellClick(colIndex, rowIndex, timezone)}- isClickable={isClickable}- showColumnAggregations={false}- showRowAggregations={false}- />- </div>- )-}diff --git a/frontend/src/scenes/session-recordings/components/ReplayActiveScreensTable.tsx b/frontend/src/scenes/session-recordings/components/ReplayActiveScreensTable.tsxdeleted file mode 100644index 0f8f7de65ead..000000000000--- a/frontend/src/scenes/session-recordings/components/ReplayActiveScreensTable.tsx+++ /dev/null@@ -1,79 +0,0 @@-import { useValues } from 'kea'-import { router } from 'kea-router'--import { IconInfo } from '@posthog/icons'--import { LemonTable } from 'lib/lemon-ui/LemonTable'-import { Tooltip } from 'lib/lemon-ui/Tooltip'-import { replayActiveScreensTableLogic } from 'scenes/session-recordings/components/replayActiveScreensTableLogic'-import { urls } from 'scenes/urls'--import { FilterLogicalOperator, PropertyFilterType, PropertyOperator, ReplayTabs } from '~/types'--export const ReplayActiveScreensTable = (): JSX.Element => {- const { countedScreens, countedScreensLoading, countedScreensError } = useValues(- replayActiveScreensTableLogic({ scene: 'templates' })- )-- return (- <div className="flex flex-col border rounded bg-surface-primary w-full px-4 py-2">- <LemonTable- embedded={true}- columns={[- {- title: (- <>- <Tooltip title="Click a row to see recordings.">- <div className="flex flex-row gap-2 items-center cursor-pointer">- <IconInfo className="text-xl" /> Last 7 days most active pages- </div>- </Tooltip>- </>- ),- dataIndex: 'screen',- align: 'left',- width: '90%',- },- { align: 'left', dataIndex: 'count', width: '10%' },- ]}- dataSource={countedScreens || []}- loading={countedScreensLoading}- emptyState={- countedScreensError- ? "Couldn't load most active pages right now. Please try again later."- : undefined- }- onRow={(record) => {- return {- className: 'cursor-pointer hover:bg-surface-secondary',- onClick: () => {- router.actions.push(- urls.replay(ReplayTabs.Home, {- date_from: '-7d',- filter_group: {- type: FilterLogicalOperator.And,- values: [- {- type: FilterLogicalOperator.And,- values: [- {- // Direct $current_url property filter instead of $pageview event filter- // This matches any event with $current_url property, not just pageviews- key: '$current_url',- value: record.screen,- operator: PropertyOperator.IContains,- type: PropertyFilterType.Event,- },- ],- },- ],- },- })- )- },- }- }}- />- </div>- )-}diff --git a/frontend/src/scenes/session-recordings/components/ReplayActiveUsersTable.tsx b/frontend/src/scenes/session-recordings/components/ReplayActiveUsersTable.tsxdeleted file mode 100644index e8aba32d1d9a..000000000000--- a/frontend/src/scenes/session-recordings/components/ReplayActiveUsersTable.tsx+++ /dev/null@@ -1,59 +0,0 @@-import { useValues } from 'kea'-import { router } from 'kea-router'--import { IconInfo } from '@posthog/icons'--import { LemonTable } from 'lib/lemon-ui/LemonTable'-import { Tooltip } from 'lib/lemon-ui/Tooltip'-import { PersonDisplay } from 'scenes/persons/PersonDisplay'-import { urls } from 'scenes/urls'--import { PersonType } from '~/types'--import { replayActiveUsersTableLogic } from './replayActiveUsersTableLogic'--export const ReplayActiveUsersTable = (): JSX.Element => {- const { countedUsers, countedUsersLoading, countedUsersError } = useValues(- replayActiveUsersTableLogic({ scene: 'templates' })- )-- return (- <div className="flex flex-col border rounded bg-surface-primary w-full px-4 py-2">- <LemonTable- embedded={true}- columns={[- {- title: (- <>- <Tooltip title="Click a row to see recordings.">- <div className="flex flex-row gap-2 items-center cursor-pointer">- <IconInfo className="text-xl" /> Last 7 days most active users- </div>- </Tooltip>- </>- ),- dataIndex: 'person',- align: 'left',- render: (p) => <PersonDisplay person={p as PersonType} withIcon={true} noLink={true} />,- },- { align: 'left', dataIndex: 'count', width: '10%' },- ]}- dataSource={countedUsers || []}- loading={countedUsersLoading}- emptyState={- countedUsersError ? "Couldn't load most active users right now. Please try again later." : undefined- }- onRow={(record) => {- return {- className: 'cursor-pointer hover:bg-surface-secondary',- onClick: () => {- router.actions.push(- urls.personByUUID(record.person.id as string) + '#activeTab=sessionRecordings'- )- },- }- }}- />- </div>- )-}diff --git a/frontend/src/scenes/session-recordings/components/replayActiveHoursHeatMapLogic.ts b/frontend/src/scenes/session-recordings/components/replayActiveHoursHeatMapLogic.tsdeleted file mode 100644index 5ad8293ae36f..000000000000--- a/frontend/src/scenes/session-recordings/components/replayActiveHoursHeatMapLogic.ts+++ /dev/null@@ -1,203 +0,0 @@-import { kea, key, listeners, path, props, selectors } from 'kea'-import { lazyLoaders } from 'kea-loaders'-import { router } from 'kea-router'-import posthog from 'posthog-js'--import api from 'lib/api'-import { Dayjs, now } from 'lib/dayjs'-import { lemonToast } from 'lib/lemon-ui/LemonToast'-import { urls } from 'scenes/urls'-import { CalendarHeatMapProps } from 'scenes/web-analytics/CalendarHeatMap/CalendarHeatMap'--import { hogql } from '~/queries/utils'-import { ReplayTabs } from '~/types'--import type { replayActiveHoursHeatMapLogicType } from './replayActiveHoursHeatMapLogicType'--export interface ReplayActiveHoursHeatMapLogicProps {- // we can show this component in different contexts, and key it accordingly- scene?: 'templates' | 'filters' | 'replay-home'-}--const rowLabels = ['00:00 - 04:00', '04:00 - 08:00', '08:00 - 12:00', '12:00 - 16:00', '16:00 - 20:00', '20:00 - 00:00']--const columnLabels = (now: Dayjs): string[] => [- now.subtract(6, 'day').format('ddd D'),- now.subtract(5, 'day').format('ddd D'),- now.subtract(4, 'day').format('ddd D'),- now.subtract(3, 'day').format('ddd D'),- now.subtract(2, 'day').format('ddd D'),- now.subtract(1, 'day').format('ddd D'),- 'Today',-]--// does not need to be on the logic yet, since it's stateless for now-export const getOnClickTooltip = (colIndex: number, rowIndex: number | undefined): string => {- const day = columnLabels(now())[colIndex]- const timeRange = rowIndex === undefined ? undefined : rowLabels[rowIndex]- return `View recordings for ${day}${timeRange ? ` ${timeRange}` : ''}`-}--// does not need to be on the logic yet, since it's stateless for now-export const onCellClick = (colIndex: number, rowIndex: number | undefined, timezone: string): void => {- const daysToSubtract = 6 - colIndex- let startDate = now().subtract(daysToSubtract, 'day').startOf('day').utc(true)- let endDate = startDate.clone()-- if (rowIndex !== undefined) {- const startHour = rowIndex * 4- const endHour = startHour + 4- startDate = startDate.hour(startHour)- endDate = endDate.hour(endHour)- } else {- endDate = endDate.add(1, 'day')- }-- posthog.capture('clicked_replay_active_hours_heatmap_cell', {- isColumnHeader: rowIndex == undefined,- isIndividualCell: rowIndex != undefined,- timezone,- })-- const setTimezoneWithoutChangingOtherValues = true- router.actions.push(- urls.replay(ReplayTabs.Home, {- // here the browser might be in a different timezone to the project- // but the dateTime has already been corrected so we need to set the timezone- // but set `true` as the second parameter- // this means we set the project timezone on the dayjs object- // without changing the values- date_from: startDate.tz(timezone, setTimezoneWithoutChangingOtherValues).toISOString(),- date_to: endDate.tz(timezone, setTimezoneWithoutChangingOtherValues).toISOString(),- })- )-}--export const replayActiveHoursHeatMapLogic = kea<replayActiveHoursHeatMapLogicType>([- path(['scenes', 'session-recordings', 'components', 'replayActiveHoursHeatMapLogic']),- props({} as ReplayActiveHoursHeatMapLogicProps),- key((props) => props.scene || 'default'),- lazyLoaders(() => ({- recordingsPerHour: {- loadRecordingsPerHour: async (_, breakpoint): Promise<number[][]> => {- const q = hogql`- SELECT hour_block,- countIf(_toDate(mints) = today() - 6) AS "Day -6",- countIf(_toDate(mints) = today() - 5) AS "Day -5",- countIf(_toDate(mints) = today() - 4) AS "Day -4",- countIf(_toDate(mints) = today() - 3) AS "Day -3",- countIf(_toDate(mints) = today() - 2) AS "Day -2",- countIf(_toDate(mints) = today() - 1) AS "Day -1",- countIf(_toDate(mints) = today()) AS "Day 0"- FROM (SELECT intDiv(toHour(mints), 4) * 4 AS real_hour_block,- mints- FROM (SELECT min(min_first_timestamp) AS mints- FROM raw_session_replay_events- WHERE min_first_timestamp >= now() - INTERVAL 7 day- AND min_first_timestamp <= now()- GROUP BY session_id- having dateDiff('SECOND'- , min (min_first_timestamp)- , max (max_last_timestamp))- > 5)) AS data- RIGHT JOIN (SELECT arrayJoin([0, 4, 8, 12, 16, 20]) AS hour_block) AS hours- ON data.real_hour_block = hours.hour_block- GROUP BY hour_block- ORDER BY hour_block`-- const qResponse = await api.queryHogQL(q, { scene: 'Replay', productKey: 'session_replay' })-- // this gives an array of arrays- // we're loading hours 0-4, 4-8, 8-12, 12-16, 16-20, 20-24- // so we get an array with 6 elements- // each of those has 8 values- // [0] is the hour block- // and then each of the other 7 values is the count for that day-- breakpoint()-- return qResponse.results as number[][]- },- },- })),- selectors(() => ({- calendarHeatmapProps: [- (s) => [s.recordingsPerHour],- (- recordingsPerHour: number[][]- ): Pick<CalendarHeatMapProps, 'rowLabels' | 'columnLabels' | 'processedData'> => {- if (!recordingsPerHour || recordingsPerHour.length === 0 || recordingsPerHour[0].length === 0) {- return {- rowLabels: [],- columnLabels: [],- processedData: {- matrix: [],- columnsAggregations: [],- rowsAggregations: [],- overallValue: 0,- maxOverall: 0,- minOverall: 0,- maxRowAggregation: 0,- minRowAggregation: 0,- maxColumnAggregation: 0,- minColumnAggregation: 0,- },- }- }-- const dataWithoutHourBlock = recordingsPerHour.map((row) => row.slice(1))-- const columnsAggregations = dataWithoutHourBlock.reduce((acc, row) => {- row.forEach((value: number, index: number) => {- acc[index] = (acc[index] || 0) + value- })- return acc- }, [])- const rowsAggregations = dataWithoutHourBlock.reduce((acc, row) => {- // take each row and ignoring row[0]- // gather a sum for each index in the row- // so we end up with an array of numbers with length 6- acc[row[0]] = (acc[row[0]] || 0) + row.reduce((a: number, b: number) => a + b, 0)- return acc- }, [])- const processedData = {- matrix: dataWithoutHourBlock,- columnsAggregations: columnsAggregations,- rowsAggregations: rowsAggregations,- overallValue: columnsAggregations.reduce((a: number, b: number) => a + b, 0),- maxOverall: dataWithoutHourBlock.reduce((acc, row) => {- return Math.max(acc, ...row)- }, 0),- minOverall: dataWithoutHourBlock.reduce((acc, row) => {- return Math.min(acc, ...row)- }, 0),- maxColumnAggregation: Math.max(...columnsAggregations),- minColumnAggregation: Math.min(...columnsAggregations),- maxRowAggregation: Math.max(...rowsAggregations),- minRowAggregation: Math.min(...rowsAggregations),- }-- return {- rowLabels: rowLabels,- columnLabels: columnLabels(now()),- processedData: processedData,- }- },- ],- isClickable: [- (s) => [s.calendarHeatmapProps],- (calendarHeatmapProps) => (colIndex: number, rowIndex?: number) => {- const valueSource =- rowIndex == undefined- ? calendarHeatmapProps?.processedData.columnsAggregations- : calendarHeatmapProps?.processedData.matrix[rowIndex]- return (valueSource[colIndex] ?? 0) > 0- },- ],- })),- listeners(() => ({- loadRecordingsPerHourFailed: async () => {- lemonToast.error('Failed to load recordings activity for heatmap')- },- })),-])diff --git a/frontend/src/scenes/session-recordings/components/replayActiveScreensTableLogic.ts b/frontend/src/scenes/session-recordings/components/replayActiveScreensTableLogic.tsdeleted file mode 100644index 77437de711d6..000000000000--- a/frontend/src/scenes/session-recordings/components/replayActiveScreensTableLogic.ts+++ /dev/null@@ -1,79 +0,0 @@-import { actions, defaults, isBreakpoint, kea, key, path, props, reducers } from 'kea'-import { lazyLoaders } from 'kea-loaders'--import api from 'lib/api'--import { hogql } from '~/queries/utils'--import type { replayActiveScreensTableLogicType } from './replayActiveScreensTableLogicType'--export interface ReplayActiveScreensTableLogicProps {- scene?: 'templates' | 'filters' | 'replay-home'-}--export const replayActiveScreensTableLogic = kea<replayActiveScreensTableLogicType>([- path(['scenes', 'session-recordings', 'components', 'replayActiveScreensTableLogic']),- props({} as ReplayActiveScreensTableLogicProps),- key((props) => props.scene || 'default'),- actions({- setCountedScreensError: (hasError: boolean) => ({ hasError }),- }),- defaults({- countedScreens: [] as { screen: string; count: number }[],- }),- reducers({- countedScreensError: [- false,- {- setCountedScreensError: (_, { hasError }) => hasError,- },- ],- }),- lazyLoaders(({ actions }) => ({- countedScreens: {- loadCountedScreens: async (_, breakpoint): Promise<{ screen: string; count: number }[]> => {- const q = hogql`- SELECT- cutQueryString(cutFragment(url)) as screen,- count(distinct session_id) as count- FROM (- SELECT- session_id,- arrayJoin(any(all_urls)) as url- FROM raw_session_replay_events- WHERE min_first_timestamp >= now() - interval 7 day- AND min_first_timestamp <= now()- GROUP BY session_id- HAVING date_diff('second', min(min_first_timestamp), max(max_last_timestamp)) > 5- )- GROUP BY screen- ORDER BY count DESC- LIMIT 10- `-- try {- const qResponse = await api.queryHogQL(q, { scene: 'Replay', productKey: 'session_replay' })-- breakpoint()-- actions.setCountedScreensError(false)- return (qResponse.results || []).map((row) => {- return {- screen: row[0] as string,- count: row[1] as number,- }- }) as { screen: string; count: number }[]- } catch (e: any) {- // a breakpoint cancellation means a newer load superseded this one, let it propagate- if (isBreakpoint(e)) {- throw e- }- // the count query can time out or be rejected when ClickHouse is busy,- // degrade to an empty/error state rather than an uncaught exception- actions.setCountedScreensError(true)- return []- }- },- },- })),-])diff --git a/frontend/src/scenes/session-recordings/components/replayActiveUsersTableLogic.ts b/frontend/src/scenes/session-recordings/components/replayActiveUsersTableLogic.tsdeleted file mode 100644index 3145d8343ba6..000000000000--- a/frontend/src/scenes/session-recordings/components/replayActiveUsersTableLogic.ts+++ /dev/null@@ -1,107 +0,0 @@-import { actions, defaults, isBreakpoint, kea, key, path, props, reducers } from 'kea'-import { lazyLoaders } from 'kea-loaders'--import api from 'lib/api'--import { hogql } from '~/queries/utils'-import { PersonType } from '~/types'--import type { replayActiveUsersTableLogicType } from './replayActiveUsersTableLogicType'--export interface ReplayActiveUsersTableLogicProps {- scene?: 'templates' | 'filters' | 'replay-home'-}--export const replayActiveUsersTableLogic = kea<replayActiveUsersTableLogicType>([- path(['scenes', 'session-recordings', 'components', 'replayActiveUsersTableLogic']),- props({} as ReplayActiveUsersTableLogicProps),- key((props) => props.scene || 'default'),- actions({- setCountedUsersError: (hasError: boolean) => ({ hasError }),- }),- defaults({- countedUsers: [] as { person: PersonType; count: number }[],- }),- reducers({- countedUsersError: [- false,- {- setCountedUsersError: (_, { hasError }) => hasError,- },- ],- }),- lazyLoaders(({ actions }) => ({- countedUsers: {- loadCountedUsers: async (_, breakpoint): Promise<{ person: PersonType; count: number }[]> => {- const q = hogql`- WITH- -- get the session ids for any recorded sessions in the last 7 days- recorded_sessions AS (- SELECT session_id- FROM raw_session_replay_events- WHERE min_first_timestamp >= now() - interval 7 day- AND min_first_timestamp <= now()- GROUP BY session_id- HAVING date_diff('second', min(min_first_timestamp), max(max_last_timestamp)) > 5- ),- -- way faster to get person props from the events table- -- so get the mapping of person_id/person_properties to session_id- -- from the events table that has the same session_id as the recorded sessions- session_persons AS (- SELECT- $session_id as session_id,- any(person_id) as person_id,- any(person.properties) as pp- FROM events- WHERE timestamp >= now() - interval 7 day- AND timestamp <= now()- AND $session_id IN (SELECT session_id FROM recorded_sessions)- -- including events when querying the events table is always _much_ faster,- -- but we don't know what events an account will have- -- so we just include the most common ones- -- this won't work for everyone but then that's try with the poorly performing query- -- that this replaces, so it's at least no worse 🙈- AND event IN ('$pageview', '$screen', '$autocapture', '$feature_flag_called', '$pageleave', '$identify', '$web_vitals', '$set', 'Application Opened', 'Application Backgrounded')- -- exclude anonymous users since we don't care if user "anonymous" watched a gajillion recordings- AND (properties.$process_person_profile = true or properties.$is_identified = true)- GROUP BY $session_id- )- -- now we can count the distinct sessions per person- SELECT- sp.person_id,- sp.pp,- count(distinct sp.session_id) as total_count- FROM session_persons sp- WHERE sp.person_id IS NOT NULL- GROUP BY sp.person_id, sp.pp- ORDER BY total_count DESC- LIMIT 10- `-- try {- const qResponse = await api.queryHogQL(q, { scene: 'Replay', productKey: 'session_replay' })-- breakpoint()-- actions.setCountedUsersError(false)- return (qResponse.results || []).map((row) => {- return {- person: { id: row[0] as string, properties: JSON.parse(row[1]) as Record<string, any> },- count: row[2] as number,- }- }) as { person: PersonType; count: number }[]- } catch (e: any) {- // a breakpoint cancellation means a newer load superseded this one, let it propagate- if (isBreakpoint(e)) {- throw e- }- // this is the heaviest of the "what to watch" count queries and the most likely to- // time out or be rejected under load, degrade to an empty/error state rather than- // an uncaught exception- actions.setCountedUsersError(true)- return []- }- },- },- })),-])diff --git a/frontend/src/scenes/session-recordings/sessionReplaySceneLogic.ts b/frontend/src/scenes/session-recordings/sessionReplaySceneLogic.tsindex 64b673c060dc..21693863fc76 100644--- a/frontend/src/scenes/session-recordings/sessionReplaySceneLogic.ts+++ b/frontend/src/scenes/session-recordings/sessionReplaySceneLogic.ts@@ -19,7 +19,7 @@ export const humanFriendlyTabName = (tab: ReplayTabs): string => {case ReplayTabs.Playlists:return 'Collections'case ReplayTabs.Templates:- return 'What to watch'+ return 'Filter templates'case ReplayTabs.Settings:return 'Settings'default:diff --git a/frontend/src/scenes/session-recordings/templates/SessionRecordingTemplates.tsx b/frontend/src/scenes/session-recordings/templates/SessionRecordingTemplates.tsxindex 734163a0623f..563792a24224 100644--- a/frontend/src/scenes/session-recordings/templates/SessionRecordingTemplates.tsx+++ b/frontend/src/scenes/session-recordings/templates/SessionRecordingTemplates.tsx@@ -6,7 +6,6 @@ import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'import UniversalFilters from 'lib/components/UniversalFilters/UniversalFilters'import { universalFiltersLogic } from 'lib/components/UniversalFilters/universalFiltersLogic'import { isUniversalGroupFilterLike } from 'lib/components/UniversalFilters/utils'-import { ReplayActiveScreensTable } from 'scenes/session-recordings/components/ReplayActiveScreensTable'import { actionsModel } from '~/models/actionsModel'import {@@ -17,8 +16,6 @@ import {ReplayTemplateVariableType,} from '~/types'-import { ReplayActiveHoursHeatMap } from '../components/ReplayActiveHoursHeatMap'-import { ReplayActiveUsersTable } from '../components/ReplayActiveUsersTable'import { replayTemplates } from './availableTemplates'import { sessionReplayTemplatesLogic } from './sessionRecordingTemplatesLogic'@@ -188,13 +185,6 @@ const SessionRecordingTemplates = (): JSX.Element => {return (<div><p>To get the most out of session replay, you just need to know where to start. </p>- <div className="flex flex-col gap-2 w-full">- <div className="flex flex-row gap-2 w-full">- <ReplayActiveUsersTable />- <ReplayActiveScreensTable />- </div>- <ReplayActiveHoursHeatMap />- </div><h2 className="mt-4">Filter templates</h2><p>Use our templates to find a focus area, then watch the filtered replays to see where users struggle,