: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): filter recordings by click, keypress and mouse activity (#66357)
Xander91cdf087f186
diff --git a/frontend/src/lib/components/PropertyFilters/components/OperatorValueSelect.tsx b/frontend/src/lib/components/PropertyFilters/components/OperatorValueSelect.tsxindex 47faa2642b19..edbed7aa3acb 100644--- a/frontend/src/lib/components/PropertyFilters/components/OperatorValueSelect.tsx+++ b/frontend/src/lib/components/PropertyFilters/components/OperatorValueSelect.tsx@@ -4,6 +4,7 @@ import { useEffect, useState } from 'react'import { LemonBanner, LemonDropdownProps, LemonSelect, LemonSelectProps, LemonSelectSection } from '@posthog/lemon-ui'import { allOperatorsToHumanName } from 'lib/components/DefinitionPopover/utils'+import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'import { dayjs } from 'lib/dayjs'import { LemonInputSelect } from 'lib/lemon-ui/LemonInputSelect/LemonInputSelect'import { Link } from 'lib/lemon-ui/Link'@@ -21,6 +22,7 @@ import {} from 'lib/utils/operators'import { RE2_DOCS_LINK, formatRE2Error } from 'lib/utils/regexp'+import { getCoreFilterDefinition } from '~/taxonomy/helpers'import {GroupTypeIndex,PropertyDefinition,@@ -235,6 +237,12 @@ export function OperatorValueSelect({)) {propertyType = PropertyType.StringArray+ } else if (type === PropertyFilterType.Recording && propertyKey) {+ // Recording properties have no entry in propertyDefinitions, so resolve their type from+ // the authoritative taxonomy (e.g. numeric activity counts get range operators + a numeric+ // input). Reading CORE_FILTER_DEFINITIONS_BY_GROUP keeps this in sync with the one source+ // of truth rather than a hardcoded key list that drifts as new recording filters are added.+ propertyType = getCoreFilterDefinition(propertyKey, TaxonomicFilterGroupType.Replay)?.type ?? propertyType}const operatorMapping: Record<string, string> = chooseOperatorMap(propertyType)diff --git a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.test.ts b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.test.tsindex 053adeed1a61..68548d7acd8c 100644--- a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.test.ts+++ b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.test.ts@@ -20,7 +20,7 @@ import { groupsModel } from '~/models/groupsModel'import { CORE_FILTER_DEFINITIONS_BY_GROUP } from '~/taxonomy/taxonomy'import { initKeaTests } from '~/test/init'import { mockEventDefinitions, mockSessionPropertyDefinitions } from '~/test/mocks'-import { AppContext, EventDefinition, PropertyDefinition } from '~/types'+import { AppContext, EventDefinition, PropertyDefinition, PropertyFilterType } from '~/types'import { infiniteListLogic } from './infiniteListLogic'import { recentTaxonomicFiltersLogic } from './recentTaxonomicFiltersLogic'@@ -1060,6 +1060,35 @@ describe('taxonomicFilterLogic', () => {})})+ describe('Replay group activity-count options', () => {+ let replayLogic: ReturnType<typeof taxonomicFilterLogic.build>++ beforeEach(() => {+ replayLogic = taxonomicFilterLogic({+ taxonomicFilterLogicKey: 'testReplayActivityCounts',+ taxonomicGroupTypes: [TaxonomicFilterGroupType.Replay],+ })+ replayLogic.mount()+ })++ afterEach(() => {+ replayLogic.unmount()+ })++ it('surfaces click/keypress/mouse activity counts as recording filters', () => {+ const replayGroup = replayLogic.values.taxonomicGroups.find(+ (g) => g.type === TaxonomicFilterGroupType.Replay+ )+ const recordingFilterKeys = (replayGroup?.options ?? [])+ .filter((o: any) => o.propertyFilterType === PropertyFilterType.Recording)+ .map((o: any) => o.key)++ expect(recordingFilterKeys).toEqual(+ expect.arrayContaining(['click_count', 'keypress_count', 'mouse_activity_count'])+ )+ })+ })+describe('keywordShortcuts on Events and EventProperties groups', () => {let testLogic: ReturnType<typeof taxonomicFilterLogic.build>diff --git a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsxindex f64e10baa22e..962245baed8d 100644--- a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx+++ b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx@@ -1389,6 +1389,21 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>([name: getFilterLabel('comment_text', TaxonomicFilterGroupType.Replay),propertyFilterType: PropertyFilterType.Recording,},+ {+ key: 'click_count',+ name: getFilterLabel('click_count', TaxonomicFilterGroupType.Replay),+ propertyFilterType: PropertyFilterType.Recording,+ },+ {+ key: 'keypress_count',+ name: getFilterLabel('keypress_count', TaxonomicFilterGroupType.Replay),+ propertyFilterType: PropertyFilterType.Recording,+ },+ {+ key: 'mouse_activity_count',+ name: getFilterLabel('mouse_activity_count', TaxonomicFilterGroupType.Replay),+ propertyFilterType: PropertyFilterType.Recording,+ },],getName: (option: Record<string, any>) => option.name,getValue: (option: Record<string, any>) => option.key,diff --git a/frontend/src/lib/components/TaxonomicFilter/utils/buildTaxonomicGroups.tsx b/frontend/src/lib/components/TaxonomicFilter/utils/buildTaxonomicGroups.tsxindex 691c2d7a3e5c..a692ec9db7b3 100644--- a/frontend/src/lib/components/TaxonomicFilter/utils/buildTaxonomicGroups.tsx+++ b/frontend/src/lib/components/TaxonomicFilter/utils/buildTaxonomicGroups.tsx@@ -947,6 +947,21 @@ export function buildTaxonomicGroups(ctx: BuildTaxonomicGroupsContext): Taxonominame: getFilterLabel('comment_text', TaxonomicFilterGroupType.Replay),propertyFilterType: PropertyFilterType.Recording,},+ {+ key: 'click_count',+ name: getFilterLabel('click_count', TaxonomicFilterGroupType.Replay),+ propertyFilterType: PropertyFilterType.Recording,+ },+ {+ key: 'keypress_count',+ name: getFilterLabel('keypress_count', TaxonomicFilterGroupType.Replay),+ propertyFilterType: PropertyFilterType.Recording,+ },+ {+ key: 'mouse_activity_count',+ name: getFilterLabel('mouse_activity_count', TaxonomicFilterGroupType.Replay),+ propertyFilterType: PropertyFilterType.Recording,+ },],getName: (option: Record<string, any>) => option.name,getValue: (option: Record<string, any>) => option.key,diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.jsonindex 7c7fb1f77d52..0fcee825e438 100644--- a/frontend/src/queries/schema.json+++ b/frontend/src/queries/schema.json@@ -39502,6 +39502,18 @@{"const": "comment_text","type": "string"+ },+ {+ "const": "click_count",+ "type": "string"+ },+ {+ "const": "keypress_count",+ "type": "string"+ },+ {+ "const": "mouse_activity_count",+ "type": "string"}]},diff --git a/frontend/src/queries/validators.js b/frontend/src/queries/validators.jsindex 898ada2007a6..882c66580fee 100644--- a/frontend/src/queries/validators.js+++ b/frontend/src/queries/validators.js@@ -1716,6 +1716,9 @@ const schema28 = {{ const: 'snapshot_source', type: 'string' },{ const: 'visited_page', type: 'string' },{ const: 'comment_text', type: 'string' },+ { const: 'click_count', type: 'string' },+ { const: 'keypress_count', type: 'string' },+ { const: 'mouse_activity_count', type: 'string' },],},label: { type: 'string' },@@ -1914,11 +1917,116 @@ function validate30(data, { instancePath = '', parentData, parentDataProperty, r}var _valid0 = _errs11 === errorsvalid1 = valid1 || _valid0+ if (!valid1) {+ const _errs13 = errors+ if (typeof data0 !== 'string') {+ const err8 = {+ instancePath: instancePath + '/key',+ schemaPath: '#/properties/key/anyOf/4/type',+ keyword: 'type',+ params: { type: 'string' },+ message: 'must be string',+ }+ if (vErrors === null) {+ vErrors = [err8]+ } else {+ vErrors.push(err8)+ }+ errors+++ }+ if ('click_count' !== data0) {+ const err9 = {+ instancePath: instancePath + '/key',+ schemaPath: '#/properties/key/anyOf/4/const',+ keyword: 'const',+ params: { allowedValue: 'click_count' },+ message: 'must be equal to constant',+ }+ if (vErrors === null) {+ vErrors = [err9]+ } else {+ vErrors.push(err9)+ }+ errors+++ }+ var _valid0 = _errs13 === errors+ valid1 = valid1 || _valid0+ if (!valid1) {+ const _errs15 = errors+ if (typeof data0 !== 'string') {+ const err10 = {+ instancePath: instancePath + '/key',+ schemaPath: '#/properties/key/anyOf/5/type',+ keyword: 'type',+ params: { type: 'string' },+ message: 'must be string',+ }+ if (vErrors === null) {+ vErrors = [err10]+ } else {+ vErrors.push(err10)+ }+ errors+++ }+ if ('keypress_count' !== data0) {+ const err11 = {+ instancePath: instancePath + '/key',+ schemaPath: '#/properties/key/anyOf/5/const',+ keyword: 'const',+ params: { allowedValue: 'keypress_count' },+ message: 'must be equal to constant',+ }+ if (vErrors === null) {+ vErrors = [err11]+ } else {+ vErrors.push(err11)+ }+ errors+++ }+ var _valid0 = _errs15 === errors+ valid1 = valid1 || _valid0+ if (!valid1) {+ const _errs17 = errors+ if (typeof data0 !== 'string') {+ const err12 = {+ instancePath: instancePath + '/key',+ schemaPath: '#/properties/key/anyOf/6/type',+ keyword: 'type',+ params: { type: 'string' },+ message: 'must be string',+ }+ if (vErrors === null) {+ vErrors = [err12]+ } else {+ vErrors.push(err12)+ }+ errors+++ }+ if ('mouse_activity_count' !== data0) {+ const err13 = {+ instancePath: instancePath + '/key',+ schemaPath: '#/properties/key/anyOf/6/const',+ keyword: 'const',+ params: { allowedValue: 'mouse_activity_count' },+ message: 'must be equal to constant',+ }+ if (vErrors === null) {+ vErrors = [err13]+ } else {+ vErrors.push(err13)+ }+ errors+++ }+ var _valid0 = _errs17 === errors+ valid1 = valid1 || _valid0+ }+ }+ }}}}if (!valid1) {- const err8 = {+ const err14 = {instancePath: instancePath + '/key',schemaPath: '#/properties/key/anyOf',keyword: 'anyOf',@@ -1926,9 +2034,9 @@ function validate30(data, { instancePath = '', parentData, parentDataProperty, rmessage: 'must match a schema in anyOf',}if (vErrors === null) {- vErrors = [err8]+ vErrors = [err14]} else {- vErrors.push(err8)+ vErrors.push(err14)}errors++validate30.errors = vErrors@@ -1949,7 +2057,7 @@ function validate30(data, { instancePath = '', parentData, parentDataProperty, r}if (valid0) {if (data.label !== undefined) {- const _errs13 = errors+ const _errs19 = errorsif (typeof data.label !== 'string') {validate30.errors = [{@@ -1962,14 +2070,14 @@ function validate30(data, { instancePath = '', parentData, parentDataProperty, r]return false}- var valid0 = _errs13 === errors+ var valid0 = _errs19 === errors} else {var valid0 = true}if (valid0) {if (data.operator !== undefined) {let data2 = data.operator- const _errs15 = errors+ const _errs21 = errorsif (typeof data2 !== 'string') {validate30.errors = [{@@ -2031,14 +2139,14 @@ function validate30(data, { instancePath = '', parentData, parentDataProperty, r]return false}- var valid0 = _errs15 === errors+ var valid0 = _errs21 === errors} else {var valid0 = true}if (valid0) {if (data.type !== undefined) {let data3 = data.type- const _errs18 = errors+ const _errs24 = errorsif (typeof data3 !== 'string') {validate30.errors = [{@@ -2063,13 +2171,13 @@ function validate30(data, { instancePath = '', parentData, parentDataProperty, r]return false}- var valid0 = _errs18 === errors+ var valid0 = _errs24 === errors} else {var valid0 = true}if (valid0) {if (data.value !== undefined) {- const _errs20 = errors+ const _errs26 = errorsif (!validate13(data.value, {instancePath: instancePath + '/value',@@ -2082,7 +2190,7 @@ function validate30(data, { instancePath = '', parentData, parentDataProperty, rvErrors === null ? validate13.errors : vErrors.concat(validate13.errors)errors = vErrors.length}- var valid0 = _errs20 === errors+ var valid0 = _errs26 === errors} else {var valid0 = true}diff --git a/frontend/src/taxonomy/core-filter-definitions-by-group.json b/frontend/src/taxonomy/core-filter-definitions-by-group.jsonindex 81995c010034..16202a70b153 100644--- a/frontend/src/taxonomy/core-filter-definitions-by-group.json+++ b/frontend/src/taxonomy/core-filter-definitions-by-group.json@@ -8238,7 +8238,8 @@"replay": {"click_count": {"description": "Number of clicks during the session",- "label": "Clicks"+ "label": "Clicks",+ "type": "Numeric"},"comment_text": {"description": "Search for text within comments on the recording",@@ -8246,7 +8247,8 @@},"console_error_count": {"description": "Number of console errors during the session",- "label": "Errors"+ "label": "Errors",+ "type": "Numeric"},"console_log_level": {"description": "Level of console logs captured",@@ -8263,7 +8265,13 @@},"keypress_count": {"description": "Number of key presses during the session",- "label": "Key presses"+ "label": "Key presses",+ "type": "Numeric"+ },+ "mouse_activity_count": {+ "description": "Number of mouse activity events during the session",+ "label": "Mouse activity",+ "type": "Numeric"},"snapshot_source": {"description": "Platform the session was recorded on",diff --git a/frontend/src/types.ts b/frontend/src/types.tsindex a1eb42d2e8f3..fda7cfc65ac7 100644--- a/frontend/src/types.ts+++ b/frontend/src/types.ts@@ -1409,7 +1409,14 @@ export type ActionStepProperties =export interface RecordingPropertyFilter extends BasePropertyFilter {type: PropertyFilterType.Recording- key: DurationType | 'snapshot_source' | 'visited_page' | 'comment_text'+ key:+ | DurationType+ | 'snapshot_source'+ | 'visited_page'+ | 'comment_text'+ | 'click_count'+ | 'keypress_count'+ | 'mouse_activity_count'operator: PropertyOperator}diff --git a/posthog/taxonomy/taxonomy.py b/posthog/taxonomy/taxonomy.pyindex c3cb39e4154d..78c2c8780a8f 100644--- a/posthog/taxonomy/taxonomy.py+++ b/posthog/taxonomy/taxonomy.py@@ -3578,14 +3578,22 @@ CORE_FILTER_DEFINITIONS_BY_GROUP: dict[str, dict[str, CoreFilterDefinition]] = {"click_count": {"label": "Clicks","description": "Number of clicks during the session",+ "type": "Numeric",},"keypress_count": {"label": "Key presses","description": "Number of key presses during the session",+ "type": "Numeric",+ },+ "mouse_activity_count": {+ "label": "Mouse activity",+ "description": "Number of mouse activity events during the session",+ "type": "Numeric",},"console_error_count": {"label": "Errors","description": "Number of console errors during the session",+ "type": "Numeric",},},"log_entries": {diff --git a/services/mcp/src/tools/generated/mcp_analytics.ts b/services/mcp/src/tools/generated/mcp_analytics.tsindex def5f100cdc4..7b180b267227 100644--- a/services/mcp/src/tools/generated/mcp_analytics.ts+++ b/services/mcp/src/tools/generated/mcp_analytics.ts@@ -265,7 +265,15 @@ const CohortPropertyFilter = z.object({const DurationType = z.enum(['duration', 'active_seconds', 'inactive_seconds'])const RecordingPropertyFilter = z.object({- key: z.union([DurationType, z.literal('snapshot_source'), z.literal('visited_page'), z.literal('comment_text')]),+ key: z.union([+ DurationType,+ z.literal('snapshot_source'),+ z.literal('visited_page'),+ z.literal('comment_text'),+ z.literal('click_count'),+ z.literal('keypress_count'),+ z.literal('mouse_activity_count'),+ ]),label: z.string().optional(),operator: PropertyOperator,type: z.literal('recording').default('recording'),