import { IncrementalSource, RecordingCustomEventTag, RecordingEventType, RecordingPluginName } from './events'; import { RecordingMetricKey } from './metrics'; const USER_INTERACTION_SOURCES = new Set([ IncrementalSource.MouseMove, IncrementalSource.MouseInteraction, IncrementalSource.Scroll, IncrementalSource.Input, IncrementalSource.TouchMove, IncrementalSource.MediaInteraction, IncrementalSource.Drag, IncrementalSource.Selection, ]); const USER_INTERACTION_TAGS = new Set([ RecordingCustomEventTag.Click, RecordingCustomEventTag.Input, RecordingCustomEventTag.RageClick, RecordingCustomEventTag.DeadClick, RecordingCustomEventTag.ScrollBack, RecordingCustomEventTag.TabUnfocus, RecordingCustomEventTag.TabRefocus, RecordingCustomEventTag.FormFieldReEdit, RecordingCustomEventTag.RouteChange, ]); const USER_INTERACTION_PLUGINS = new Set([RecordingPluginName.RouteChange]); const USER_INTERACTION_METRIC_KEYS = new Set([ RecordingMetricKey.Click, RecordingMetricKey.Input, RecordingMetricKey.RageClick, RecordingMetricKey.FormFieldReEdit, RecordingMetricKey.DeadClick, RecordingMetricKey.ScrollBack, RecordingMetricKey.TabUnfocus, RecordingMetricKey.RouteChange, ]); const isObject = (value: unknown): value is Record => typeof value === 'object' && value !== null; export const isUserInteractionEvent = (event: unknown): boolean => { if (!isObject(event) || !isObject(event.data)) { return false; } if (event.type === RecordingEventType.IncrementalSnapshot) { return typeof event.data.source === 'number' && USER_INTERACTION_SOURCES.has(event.data.source); } if (event.type === RecordingEventType.Custom) { return typeof event.data.tag === 'string' && USER_INTERACTION_TAGS.has(event.data.tag); } return ( event.type === RecordingEventType.Plugin && typeof event.data.plugin === 'string' && USER_INTERACTION_PLUGINS.has(event.data.plugin) ); }; export const isUserInteractionMetric = (metricKey: string): boolean => USER_INTERACTION_METRIC_KEYS.has(metricKey); export const isSessionActivityEvent = (event: unknown): boolean => (isObject(event) && event.type === RecordingEventType.Meta) || isUserInteractionEvent(event);