: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
feat(replay): show and copy the ip address in the player overview (#114944)
posthog[bot]c46d8010c93b
diff --git a/frontend/src/scenes/session-recordings/components/OverviewGrid.tsx b/frontend/src/scenes/session-recordings/components/OverviewGrid.tsxindex 9377dcbe2aaa..448478fed1f7 100644--- a/frontend/src/scenes/session-recordings/components/OverviewGrid.tsx+++ b/frontend/src/scenes/session-recordings/components/OverviewGrid.tsx@@ -4,6 +4,8 @@ import { ReactNode } from 'react'import { IconFilter } from '@posthog/icons'import { Tooltip } from '@posthog/lemon-ui'+import { CopyToClipboardInline } from 'lib/components/CopyToClipboard'+import { PropertyFilterType } from '~/types'interface OverviewItemBase {@@ -48,6 +50,7 @@ export function OverviewGridItem({showFilter,filterDisabledReason,filterState,+ copyValue,}: {children?: ReactNodedescription: ReactNode@@ -59,6 +62,7 @@ export function OverviewGridItem({showFilter?: booleanfilterDisabledReason?: stringfilterState?: 'active' | 'replace' | 'inactive'+ copyValue?: string}): JSX.Element {const getFilterTooltip = (): string => {if (filterDisabledReason) {@@ -84,6 +88,16 @@ export function OverviewGridItem({<div className="truncate min-w-0"><Tooltip title={description}>{children}</Tooltip></div>+ {copyValue !== undefined && (+ <CopyToClipboardInline+ explicitValue={copyValue}+ description={typeof label === 'string' ? label : 'value'}+ tooltipMessage="Copy value"+ iconSize="xsmall"+ iconMargin={false}+ data-attr="player-overview-copy-property-value"+ />+ )}{showFilter && onFilterClick && (<Tooltip title={getFilterTooltip()}><divdiff --git a/frontend/src/scenes/session-recordings/player/sidebar/PlayerSidebarOverviewRows.tsx b/frontend/src/scenes/session-recordings/player/sidebar/PlayerSidebarOverviewRows.tsxindex 9c4b2cd55253..69653bfee048 100644--- a/frontend/src/scenes/session-recordings/player/sidebar/PlayerSidebarOverviewRows.tsx+++ b/frontend/src/scenes/session-recordings/player/sidebar/PlayerSidebarOverviewRows.tsx@@ -12,7 +12,10 @@ import { playerMetaLogic } from 'scenes/session-recordings/player/player-meta/plimport { PropertyOperator, UniversalFiltersGroup } from '~/types'import { OverviewGridItem, OverviewItem } from '../../components/OverviewGrid'-import { sessionRecordingsPlaylistLogic } from '../../playlist/sessionRecordingsPlaylistLogic'+import {+ overviewPropertyFilterType,+ sessionRecordingsPlaylistLogic,+} from '../../playlist/sessionRecordingsPlaylistLogic'import { sessionRecordingPlayerLogic } from '../sessionRecordingPlayerLogic'import { PlayerSidebarEditPinnedPropertiesPopover } from './PlayerSidebarEditPinnedPropertiesPopover'@@ -21,6 +24,7 @@ function getFilterState(propertyKey: string,propertyValue: string | undefined): 'active' | 'replace' | 'inactive' {+ const filterType = overviewPropertyFilterType(propertyKey)// Check first nested group (index 0) where filters are addedconst firstNestedGroup = filterGroup.values[0]if (!firstNestedGroup || !('values' in firstNestedGroup)) {@@ -31,6 +35,7 @@ function getFilterState(const hasExactMatch = firstNestedGroup.values.some((filter) => {if ('key' in filter && 'value' in filter && 'type' in filter && 'operator' in filter) {return (+ filter.type === filterType &&filter.key === propertyKey &&filter.value === propertyValue &&filter.operator === PropertyOperator.Exact@@ -46,7 +51,9 @@ function getFilterState(// Check if same key with different value existsconst hasSameKey = firstNestedGroup.values.some((filter) => {if ('key' in filter && 'type' in filter && 'operator' in filter) {- return filter.key === propertyKey && filter.operator === PropertyOperator.Exact+ return (+ filter.type === filterType && filter.key === propertyKey && filter.operator === PropertyOperator.Exact+ )}return false})@@ -110,6 +117,7 @@ export function PlayerSidebarOverviewRows({onFilterClick={isFilterable ? () => togglePropertyFilter(item.property, item.value) : undefined}+ copyValue={isFilterable && item.property === '$ip' ? item.value : undefined}><div className="flex flex-row items-center gap-2 justify-start font-medium min-w-0">{item.type === 'property' && (diff --git a/frontend/src/scenes/session-recordings/playlist/sessionRecordingsListPropertiesLogic.test.ts b/frontend/src/scenes/session-recordings/playlist/sessionRecordingsListPropertiesLogic.test.tsindex a3b612ac5c9d..05a8408a2aee 100644--- a/frontend/src/scenes/session-recordings/playlist/sessionRecordingsListPropertiesLogic.test.ts+++ b/frontend/src/scenes/session-recordings/playlist/sessionRecordingsListPropertiesLogic.test.ts@@ -17,6 +17,7 @@ const EXPECTED_RECORDING_PROPERTIES = [$os: 'Windows',$os_name: 'Windows 10',$entry_referring_domain: 'google.com',+ $ip: '192.0.2.1',},},{@@ -40,6 +41,7 @@ const EXPECTED_RECORDING_PROPERTIES_BY_ID = {$os: 'Windows',$os_name: 'Windows 10',$entry_referring_domain: 'google.com',+ $ip: '192.0.2.1',},s2: {$browser: 'Safari',@@ -83,8 +85,20 @@ const mockSessons: SessionRecordingType[] = []// matches the order of the base columns in the properties query, after the leading session_id-const S1_BASE_ROW = ['s1', 'AU', 'Chrome', 'Desktop', 'Windows', 'Windows 10', 'google.com', null, null, null]-const S2_BASE_ROW = ['s2', 'GB', 'Safari', 'Mobile', 'iOS', 'iOS 14', 'google.com', null, null, null]+const S1_BASE_ROW = [+ 's1',+ 'AU',+ 'Chrome',+ 'Desktop',+ 'Windows',+ 'Windows 10',+ 'google.com',+ null,+ null,+ null,+ '192.0.2.1',+]+const S2_BASE_ROW = ['s2', 'GB', 'Safari', 'Mobile', 'iOS', 'iOS 14', 'google.com', null, null, null, null]// mock the query endpoint with a per-request handler that receives the HogQL query stringconst useQueryMocks = (handler: (query: string) => unknown): void => {diff --git a/frontend/src/scenes/session-recordings/playlist/sessionRecordingsListPropertiesLogic.ts b/frontend/src/scenes/session-recordings/playlist/sessionRecordingsListPropertiesLogic.tsindex d521ab32eb56..52c9e70d653f 100644--- a/frontend/src/scenes/session-recordings/playlist/sessionRecordingsListPropertiesLogic.ts+++ b/frontend/src/scenes/session-recordings/playlist/sessionRecordingsListPropertiesLogic.ts@@ -26,6 +26,7 @@ const BASE_QUERY_PROPERTIES: [string, string][] = [['properties', '$geoip_subdivision_1_name'],['properties', '$geoip_city_name'],['session', '$entry_current_url'],+ ['properties', '$ip'],]const BASE_PROPERTIES = BASE_QUERY_PROPERTIES.map(([, property]) => property)diff --git a/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.test.ts b/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.test.tsindex c6fcc0b73dbf..f73ebebd57a9 100644--- a/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.test.ts+++ b/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.test.ts@@ -13,6 +13,7 @@ import {ActionFilter,FilterLogicalOperator,PropertyFilterType,+ PersonPropertyFilter,PropertyOperator,RecordingUniversalFilters,} from '~/types'@@ -2112,6 +2113,55 @@ describe('sessionRecordingsPlaylistLogic', () => {})}).toMatchValues({ filters: expect.objectContaining({ date_from: '-7d', date_to: null }) })})++ it.each([+ ['$ip', '192.0.2.1', PropertyFilterType.Event],+ ['$browser', 'Chrome', PropertyFilterType.Event],+ ['$geoip_country_code', 'AU', PropertyFilterType.Person],+ ['$entry_current_url', 'https://example.com', PropertyFilterType.Session],+ ])('toggles a %s overview filter with the matching filter type', async (key, value, type) => {+ await expectLogic(logic, () => {+ logic.actions.togglePropertyFilter(key, value)+ }).toDispatchActions(['setFilters'])++ expect(logic.values.filters.filter_group.values[0]).toMatchObject({+ values: expect.arrayContaining([{ type, key, value, operator: PropertyOperator.Exact }]),+ })+ })++ it.each([+ ['the same value', '192.0.2.1'],+ ['a different value', '192.0.2.2'],+ ])('keeps a person $ip filter with %s when toggling the overview $ip filter', async (_, existingValue) => {+ const personFilter: PersonPropertyFilter = {+ type: PropertyFilterType.Person,+ key: '$ip',+ value: existingValue,+ operator: PropertyOperator.Exact,+ }+ logic.actions.setFilters({+ filter_group: {+ type: FilterLogicalOperator.And,+ values: [{ type: FilterLogicalOperator.And, values: [personFilter] }],+ },+ })++ await expectLogic(logic, () => {+ logic.actions.togglePropertyFilter('$ip', '192.0.2.1')+ }).toDispatchActions(['setFilters'])++ expect(logic.values.filters.filter_group.values[0]).toMatchObject({+ values: [+ personFilter,+ {+ type: PropertyFilterType.Event,+ key: '$ip',+ value: '192.0.2.1',+ operator: PropertyOperator.Exact,+ },+ ],+ })+ })})describe('failed list loads', () => {diff --git a/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.ts b/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.tsindex 7e3caf1f6e5d..dfbe60ec43f4 100644--- a/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.ts+++ b/frontend/src/scenes/session-recordings/playlist/sessionRecordingsPlaylistLogic.ts@@ -321,6 +321,18 @@ const handleLoadCollectionRecordings = (shortId: string): void => {* @param filters - The filters to check.* @returns True if the filters are valid, false otherwise.*/+// Device keys and $ip are event properties, $geoip_* and custom keys are person properties, other $ keys are session properties.+export function overviewPropertyFilterType(+ propertyKey: string+): PropertyFilterType.Person | PropertyFilterType.Event | PropertyFilterType.Session {+ if (propertyKey.startsWith('$geoip_') || !propertyKey.startsWith('$')) {+ return PropertyFilterType.Person+ }+ return ['$browser', '$os', '$device_type', '$initial_device_type', '$os_name', '$ip'].includes(propertyKey)+ ? PropertyFilterType.Event+ : PropertyFilterType.Session+}+export function isValidRecordingFilters(filters: Partial<RecordingUniversalFilters> | undefined): boolean {if (!filters || typeof filters !== 'object') {return false@@ -1632,16 +1644,7 @@ export const sessionRecordingsPlaylistLogic = kea<sessionRecordingsPlaylistLogicreturn}- // Determine property filter type- // For recordings: $browser, $os, $device_type, etc are Event properties- // $geoip_* and custom properties (no $) are Person properties- // Everything else with $ is Session property- const filterType =- propertyKey.startsWith('$geoip_') || !propertyKey.startsWith('$')- ? PropertyFilterType.Person- : ['$browser', '$os', '$device_type', '$initial_device_type', '$os_name'].includes(propertyKey)- ? PropertyFilterType.Event- : PropertyFilterType.Session+ const filterType = overviewPropertyFilterType(propertyKey)// Create property filter objectconst filter = {@@ -1688,13 +1691,7 @@ export const sessionRecordingsPlaylistLogic = kea<sessionRecordingsPlaylistLogicreturn}- // Determine property filter type- const filterType =- propertyKey.startsWith('$geoip_') || !propertyKey.startsWith('$')- ? PropertyFilterType.Person- : ['$browser', '$os', '$device_type', '$initial_device_type', '$os_name'].includes(propertyKey)- ? PropertyFilterType.Event- : PropertyFilterType.Session+ const filterType = overviewPropertyFilterType(propertyKey)const currentGroup = values.filters.filter_groupconst firstNestedGroup = currentGroup.values[0]@@ -1703,10 +1700,11 @@ export const sessionRecordingsPlaylistLogic = kea<sessionRecordingsPlaylistLogicreturn}- // Check if filter with exact (key, value) exists - if so, remove it+ // Check if filter with exact (type, key, value) exists - if so, remove itconst exactMatchIndex = firstNestedGroup.values.findIndex((filter) => {- if ('key' in filter && 'value' in filter && 'operator' in filter) {+ if ('key' in filter && 'value' in filter && 'type' in filter && 'operator' in filter) {return (+ filter.type === filterType &&filter.key === propertyKey &&filter.value === propertyValue &&filter.operator === PropertyOperator.Exact@@ -1736,8 +1734,12 @@ export const sessionRecordingsPlaylistLogic = kea<sessionRecordingsPlaylistLogic} else {// Check if filter with same key but different value existsconst sameKeyIndex = firstNestedGroup.values.findIndex((filter) => {- if ('key' in filter && 'operator' in filter) {- return filter.key === propertyKey && filter.operator === PropertyOperator.Exact+ if ('key' in filter && 'type' in filter && 'operator' in filter) {+ return (+ filter.type === filterType &&+ filter.key === propertyKey &&+ filter.operator === PropertyOperator.Exact+ )}return false})@@ -1785,6 +1787,11 @@ export const sessionRecordingsPlaylistLogic = kea<sessionRecordingsPlaylistLogic}actions.setFilters({ filter_group: newGroup })+ // capture the key only, because values such as $ip can be personal data+ posthog.capture('recording overview property filter toggled', {+ property_key: propertyKey,+ action: exactMatchIndex !== -1 ? 'removed' : 'applied',+ })// Show toast notificationconst filterLabel = formatPropertyLabel(