Skip to content

: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.

feat(insights): flag-gated performed event filter on insight series (#89068)

Sam Pennington81968703e25c
diff --git a/frontend/src/lib/components/PropertyFilters/PropertyFilters.tsx b/frontend/src/lib/components/PropertyFilters/PropertyFilters.tsx
index 79c0670b7f71..b0bc7b209448 100644
--- a/frontend/src/lib/components/PropertyFilters/PropertyFilters.tsx
+++ b/frontend/src/lib/components/PropertyFilters/PropertyFilters.tsx
@@ -1,9 +1,12 @@
import './PropertyFilters.scss'
+import clsx from 'clsx'
import { BindLogic, useActions, useValues } from 'kea'
import React, { useState } from 'react'
import { BehavioralPropertyFilterRow } from 'lib/components/PropertyFilters/components/BehavioralPropertyFilterRow'
+import { FILTER_ROW_FRAME_CLASSES } from 'lib/components/PropertyFilters/components/filterRowFrame'
+import { PropertyFilterRowOperator } from 'lib/components/PropertyFilters/components/PropertyFilterRowOperator'
import { TaxonomicPropertyFilter } from 'lib/components/PropertyFilters/components/TaxonomicPropertyFilter'
import { isBehavioralPropertyFilter } from 'lib/components/PropertyFilters/utils'
import {
@@ -80,6 +83,7 @@ export interface PropertyFiltersProps {
* logic, so the caller doesn't have to rebuild the list from possibly-stale props. */
addFilterSuffix?: ((addFilter: (property: AnyPropertyFilter) => void) => JSX.Element) | null
addFilterDivider?: boolean
+ framedRows?: boolean
}
export function PropertyFilters({
@@ -126,6 +130,7 @@ export function PropertyFilters({
showRemoveButton = true,
addFilterSuffix,
addFilterDivider = false,
+ framedRows = false,
}: PropertyFiltersProps): JSX.Element {
const logicProps = { propertyFilters, onChange, pageKey, sendAllKeyUpdates }
const { filters, filtersWithNew, filterIds, filterIdsWithNew } = useValues(propertyFilterLogic(logicProps))
@@ -177,12 +182,29 @@ export function PropertyFilters({
editable={editable}
filterComponent={(onComplete) =>
isBehavioralPropertyFilter(item) ? (
- <BehavioralPropertyFilterRow
- filter={item}
- onChange={(filter) => setFilter(index, filter)}
- editable={editable}
- size={buttonSize}
- />
+ <div className="TaxonomicPropertyFilter__row w-full min-w-0">
+ {hasRowOperator && (
+ <PropertyFilterRowOperator
+ index={index}
+ orFiltering={orFiltering}
+ propertyGroupType={propertyGroupType}
+ hasKey={!!item.key}
+ />
+ )}
+ <div
+ className={clsx(
+ 'TaxonomicPropertyFilter__row-items',
+ framedRows && FILTER_ROW_FRAME_CLASSES
+ )}
+ >
+ <BehavioralPropertyFilterRow
+ filter={item}
+ onChange={(filter) => setFilter(index, filter)}
+ editable={editable}
+ size={buttonSize}
+ />
+ </div>
+ </div>
) : (
<TaxonomicPropertyFilter
pageKey={pageKey}
@@ -217,6 +239,7 @@ export function PropertyFilters({
propertyDefinitionsOverride={propertyDefinitionsOverride}
propertyKeyEditable={propertyKeyEditable}
singleLine={singleLine}
+ framedRows={framedRows}
/>
)
}
diff --git a/frontend/src/lib/components/PropertyFilters/components/AddBehavioralFilterButton.tsx b/frontend/src/lib/components/PropertyFilters/components/AddBehavioralFilterButton.tsx
new file mode 100644
index 000000000000..f04b3f04de76
--- /dev/null
+++ b/frontend/src/lib/components/PropertyFilters/components/AddBehavioralFilterButton.tsx
@@ -0,0 +1,38 @@
+import { IconPlusSmall } from '@posthog/icons'
+
+import { newBehavioralFilter } from 'lib/components/PropertyFilters/utils'
+import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
+import { TaxonomicPopover } from 'lib/components/TaxonomicPopover/TaxonomicPopover'
+
+import { BehavioralPropertyFilter } from '~/types'
+
+export interface AddBehavioralFilterButtonProps {
+ onAdd: (filter: BehavioralPropertyFilter) => void
+ 'data-attr': string
+}
+
+export function AddBehavioralFilterButton({
+ onAdd,
+ 'data-attr': dataAttr,
+}: AddBehavioralFilterButtonProps): JSX.Element {
+ return (
+ <TaxonomicPopover
+ groupType={TaxonomicFilterGroupType.Events}
+ groupTypes={[TaxonomicFilterGroupType.Events, TaxonomicFilterGroupType.Actions]}
+ value={null}
+ onChange={(value, groupType) =>
+ onAdd(
+ newBehavioralFilter(
+ String(value),
+ groupType === TaxonomicFilterGroupType.Actions ? 'actions' : 'events'
+ )
+ )
+ }
+ placeholder="Performed"
+ placeholderClass=""
+ icon={<IconPlusSmall />}
+ sideIcon={null}
+ data-attr={dataAttr}
+ />
+ )
+}
diff --git a/frontend/src/lib/components/PropertyFilters/components/BehavioralPropertyFilterRow.tsx b/frontend/src/lib/components/PropertyFilters/components/BehavioralPropertyFilterRow.tsx
index aaacafb7663c..83fb0d358fcd 100644
--- a/frontend/src/lib/components/PropertyFilters/components/BehavioralPropertyFilterRow.tsx
+++ b/frontend/src/lib/components/PropertyFilters/components/BehavioralPropertyFilterRow.tsx
@@ -128,7 +128,7 @@ export function BehavioralPropertyFilterRow({
</div>
</div>
{!filter.negation && (
- <div className="flex items-center gap-2">
+ <div className="flex min-w-0 flex-wrap items-center gap-2">
<LemonSelect
size={size}
value={countOperator}
@@ -148,7 +148,7 @@ export function BehavioralPropertyFilterRow({
<span className="whitespace-nowrap">{countValue === 1 ? 'time' : 'times'}</span>
</div>
)}
- <div className="flex items-center gap-2">
+ <div className="flex min-w-0 flex-wrap items-center gap-2">
<span className="whitespace-nowrap">in the last</span>
<LemonInput
type="number"
diff --git a/frontend/src/lib/components/PropertyFilters/components/FilterRow.tsx b/frontend/src/lib/components/PropertyFilters/components/FilterRow.tsx
index 003aa800c875..0e66c89d8ff0 100644
--- a/frontend/src/lib/components/PropertyFilters/components/FilterRow.tsx
+++ b/frontend/src/lib/components/PropertyFilters/components/FilterRow.tsx
@@ -73,7 +73,9 @@ export const FilterRow = React.memo(function FilterRow({
return (
<>
<div
- className={clsx('property-filter-row flex items-center flex-nowrap deprecated-space-x-2 max-w-full', {
+ className={clsx('property-filter-row flex items-center max-w-full', {
+ 'flex-wrap gap-2': !!suffix,
+ 'flex-nowrap deprecated-space-x-2': !suffix,
'grow sm:grow-0': isValid,
'grow-0': !isValid,
'wrap-filters': !disablePopover,
diff --git a/frontend/src/lib/components/PropertyFilters/components/PropertyFilterRowOperator.tsx b/frontend/src/lib/components/PropertyFilters/components/PropertyFilterRowOperator.tsx
new file mode 100644
index 000000000000..97e0d3e72434
--- /dev/null
+++ b/frontend/src/lib/components/PropertyFilters/components/PropertyFilterRowOperator.tsx
@@ -0,0 +1,43 @@
+import clsx from 'clsx'
+
+import { FilterLogicalOperator } from '~/types'
+
+import { OperandTag } from './OperandTag'
+
+export interface PropertyFilterRowOperatorProps {
+ index: number
+ orFiltering?: boolean
+ propertyGroupType?: FilterLogicalOperator | null
+ hasKey?: boolean
+}
+
+export function PropertyFilterRowOperator({
+ index,
+ orFiltering,
+ propertyGroupType,
+ hasKey,
+}: PropertyFilterRowOperatorProps): JSX.Element {
+ const content = orFiltering ? (
+ propertyGroupType && index !== 0 && hasKey ? (
+ <OperandTag operand={propertyGroupType === FilterLogicalOperator.And ? 'and' : 'or'} />
+ ) : null
+ ) : index === 0 ? (
+ <>
+ <span className="TaxonomicPropertyFilter__row-arrow">&#8627;</span>
+ <span>where</span>
+ </>
+ ) : hasKey ? (
+ <OperandTag operand="and" />
+ ) : null
+
+ return (
+ <div
+ className={clsx(
+ 'TaxonomicPropertyFilter__row-operator',
+ !content && 'TaxonomicPropertyFilter__row-operator--empty'
+ )}
+ >
+ {content ? <div className="flex items-center gap-1">{content}</div> : null}
+ </div>
+ )
+}
diff --git a/frontend/src/lib/components/PropertyFilters/components/TaxonomicPropertyFilter.tsx b/frontend/src/lib/components/PropertyFilters/components/TaxonomicPropertyFilter.tsx
index bbe5c1305982..5f7fff2ae826 100644
--- a/frontend/src/lib/components/PropertyFilters/components/TaxonomicPropertyFilter.tsx
+++ b/frontend/src/lib/components/PropertyFilters/components/TaxonomicPropertyFilter.tsx
@@ -36,17 +36,12 @@ import { teamLogic } from 'scenes/teamLogic'
import { cohortsModel } from '~/models/cohortsModel'
import { propertyDefinitionsModel } from '~/models/propertyDefinitionsModel'
-import {
- AnyPropertyFilter,
- FilterLogicalOperator,
- GroupTypeIndex,
- PropertyDefinitionType,
- PropertyFilterType,
-} from '~/types'
+import { AnyPropertyFilter, GroupTypeIndex, PropertyDefinitionType, PropertyFilterType } from '~/types'
import { joinsLogic } from 'products/data_warehouse/frontend/shared/logics/joinsLogic'
-import { OperandTag } from './OperandTag'
+import { FILTER_ROW_FRAME_CLASSES } from './filterRowFrame'
+import { PropertyFilterRowOperator } from './PropertyFilterRowOperator'
import { taxonomicPropertyFilterLogic } from './taxonomicPropertyFilterLogic'
export const DEFAULT_TAXONOMIC_GROUP_TYPES = [
@@ -95,6 +90,7 @@ export function TaxonomicPropertyFilter({
propertyDefinitionsOverride,
propertyKeyEditable = true,
singleLine,
+ framedRows,
}: PropertyFilterInternalProps): JSX.Element {
const generatedKey = useId()
const pageKey = pageKeyInput || `filter-${generatedKey}`
@@ -372,37 +368,19 @@ export function TaxonomicPropertyFilter({
})}
>
{hasRowOperator && (
- <div className="TaxonomicPropertyFilter__row-operator">
- {orFiltering ? (
- <>
- {propertyGroupType && index !== 0 && filter?.key && (
- <div className="flex items-center">
- {propertyGroupType === FilterLogicalOperator.And ? (
- <OperandTag operand="and" />
- ) : (
- <OperandTag operand="or" />
- )}
- </div>
- )}
- </>
- ) : (
- <div className="flex items-center gap-1">
- {index === 0 ? (
- <>
- <span className="TaxonomicPropertyFilter__row-arrow">&#8627;</span>
- <span>where</span>
- </>
- ) : (
- <OperandTag operand="and" />
- )}
- </div>
- )}
- </div>
+ <PropertyFilterRowOperator
+ index={index}
+ orFiltering={orFiltering}
+ propertyGroupType={propertyGroupType}
+ hasKey={!!filter?.key}
+ />
)}
<div
- className={clsx('TaxonomicPropertyFilter__row-items', {
- 'TaxonomicPropertyFilter__row-items--single-line': singleLine,
- })}
+ className={clsx(
+ 'TaxonomicPropertyFilter__row-items',
+ { 'TaxonomicPropertyFilter__row-items--single-line': singleLine },
+ framedRows && filter?.key && FILTER_ROW_FRAME_CLASSES
+ )}
>
{showOperatorValueSelect && placeOperatorValueSelectOnLeft && operatorValueSelect}
{editable && propertyKeyEditable ? editablePicker : filterContent}
diff --git a/frontend/src/lib/components/PropertyFilters/components/filterRowFrame.ts b/frontend/src/lib/components/PropertyFilters/components/filterRowFrame.ts
new file mode 100644
index 000000000000..1cac7574034e
--- /dev/null
+++ b/frontend/src/lib/components/PropertyFilters/components/filterRowFrame.ts
@@ -0,0 +1,2 @@
+/** Frames a filter row's controls like a filter group. */
+export const FILTER_ROW_FRAME_CLASSES = '-mx-1.5 rounded border border-primary bg-primary p-1.5'
diff --git a/frontend/src/lib/components/PropertyFilters/types.ts b/frontend/src/lib/components/PropertyFilters/types.ts
index 5c4862d064bc..5be18a64046c 100644
--- a/frontend/src/lib/components/PropertyFilters/types.ts
+++ b/frontend/src/lib/components/PropertyFilters/types.ts
@@ -87,4 +87,6 @@ export interface PropertyFilterInternalProps {
propertyKeyEditable?: boolean
/** Keep key, operator, and value controls on one row when the host has enough width. */
singleLine?: boolean
+ /** Frame each row's controls like a filter group, so a multi-line condition reads as one unit. */
+ framedRows?: boolean
}
diff --git a/frontend/src/lib/components/PropertyFilters/utils.ts b/frontend/src/lib/components/PropertyFilters/utils.ts
index 40fde6044bd4..1539afcb7ae1 100644
--- a/frontend/src/lib/components/PropertyFilters/utils.ts
+++ b/frontend/src/lib/components/PropertyFilters/utils.ts
@@ -250,6 +250,17 @@ export function isBehavioralPropertyFilter(filter?: AnyFilterLike | null): filte
return filter?.type === PropertyFilterType.Behavioral
}
+export function newBehavioralFilter(key: string, eventType: 'events' | 'actions'): BehavioralPropertyFilter {
+ return {
+ type: PropertyFilterType.Behavioral,
+ value: BehavioralEventType.PerformEvent,
+ key,
+ event_type: eventType,
+ time_value: 30,
+ time_interval: TimeUnitType.Day,
+ }
+}
+
export const BEHAVIORAL_COUNT_OPERATOR_LABELS: Partial<Record<PropertyOperator, string>> = {
[PropertyOperator.GreaterThanOrEqual]: 'at least',
[PropertyOperator.LessThanOrEqual]: 'at most',
diff --git a/frontend/src/queries/nodes/InsightViz/InsightViz.scss b/frontend/src/queries/nodes/InsightViz/InsightViz.scss
index 0e507d3f64f7..52182a7ff431 100644
--- a/frontend/src/queries/nodes/InsightViz/InsightViz.scss
+++ b/frontend/src/queries/nodes/InsightViz/InsightViz.scss
@@ -67,6 +67,26 @@
flex-basis: 100%;
}
}
+
+ @container editor-panel (max-width: 400px) {
+ .ActionFilterRow-filters .TaxonomicPropertyFilter__row {
+ flex-wrap: wrap;
+ }
+
+ .ActionFilterRow-filters .TaxonomicPropertyFilter__row-items {
+ flex-basis: 100%;
+ }
+
+ .ActionFilterRow-filters .TaxonomicPropertyFilter__row-operator {
+ justify-content: flex-start;
+ width: auto;
+ height: auto;
+ }
+
+ .ActionFilterRow-filters .TaxonomicPropertyFilter__row-operator--empty {
+ display: none;
+ }
+ }
}
&:not(.EditorFiltersWrapper--panels) {
diff --git a/frontend/src/queries/nodes/InsightViz/PropertyGroupFilters/PropertyGroupFilters.tsx b/frontend/src/queries/nodes/InsightViz/PropertyGroupFilters/PropertyGroupFilters.tsx
index 6cd5ce6289f1..d5ad6de6f2db 100644
--- a/frontend/src/queries/nodes/InsightViz/PropertyGroupFilters/PropertyGroupFilters.tsx
+++ b/frontend/src/queries/nodes/InsightViz/PropertyGroupFilters/PropertyGroupFilters.tsx
@@ -7,6 +7,7 @@ import React from 'react'
import { IconCopy, IconPlusSmall, IconTrash } from '@posthog/icons'
import { LemonButton, LemonDivider } from '@posthog/lemon-ui'
+import { AddBehavioralFilterButton } from 'lib/components/PropertyFilters/components/AddBehavioralFilterButton'
import { PropertyFilters } from 'lib/components/PropertyFilters/PropertyFilters'
import { isPropertyGroupFilterLike } from 'lib/components/PropertyFilters/utils'
import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
@@ -15,31 +16,12 @@ import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { keyForInsightLogicProps } from 'scenes/insights/sharedUtils'
import { InsightQueryNode, ProductAnalyticsInsightQueryNode } from '~/queries/schema/schema-general'
-import {
- AnyPropertyFilter,
- BehavioralEventType,
- BehavioralPropertyFilter,
- InsightLogicProps,
- PropertyFilterType,
- PropertyGroupFilterValue,
- TimeUnitType,
-} from '~/types'
+import { AnyPropertyFilter, InsightLogicProps, PropertyGroupFilterValue } from '~/types'
import { InsightTestAccountFilter } from '../filters/InsightTestAccountFilter'
import { AndOrFilterSelect } from './AndOrFilterSelect'
import { propertyGroupFilterLogic } from './propertyGroupFilterLogic'
-function newBehavioralFilter(): BehavioralPropertyFilter {
- return {
- type: PropertyFilterType.Behavioral,
- value: BehavioralEventType.PerformEvent,
- key: '$pageview',
- event_type: 'events',
- time_value: 30,
- time_interval: TimeUnitType.Day,
- }
-}
-
type PropertyGroupFiltersProps = {
insightProps: InsightLogicProps
query: ProductAnalyticsInsightQueryNode
@@ -197,17 +179,10 @@ export function PropertyGroupFilters({
addFilterSuffix={
behavioralFiltersEnabled
? (addFilter) => (
- <LemonButton
+ <AddBehavioralFilterButton
data-attr={`${pageKey}-add-behavioral-filter`}
- type="secondary"
- icon={<IconPlusSmall />}
- sideIcon={null}
- onClick={() =>
- addFilter(newBehavioralFilter())
- }
- >
- Performed
- </LemonButton>
+ onAdd={addFilter}
+ />
)
: null
}
diff --git a/frontend/src/queries/nodes/InsightViz/TrendsSeries.tsx b/frontend/src/queries/nodes/InsightViz/TrendsSeries.tsx
index f192796396c8..9e19be696f85 100644
--- a/frontend/src/queries/nodes/InsightViz/TrendsSeries.tsx
+++ b/frontend/src/queries/nodes/InsightViz/TrendsSeries.tsx
@@ -87,6 +87,7 @@ export function TrendsSeries(): JSX.Element | null {
<>
{isLifecycle && <LifecycleSeriesHeader />}
<ActionFilter
+ allowBehavioralPropertyFilter
filters={filters}
setFilters={(payload: Partial<FilterType>): void => {
if (isLifecycle) {
diff --git a/frontend/src/scenes/insights/EditorFilters/FunnelsQuerySteps.tsx b/frontend/src/scenes/insights/EditorFilters/FunnelsQuerySteps.tsx
index 9606d8168efa..e3109f83e86a 100644
--- a/frontend/src/scenes/insights/EditorFilters/FunnelsQuerySteps.tsx
+++ b/frontend/src/scenes/insights/EditorFilters/FunnelsQuerySteps.tsx
@@ -52,6 +52,7 @@ export function FunnelsQuerySteps({ insightProps }: EditorFilterProps): JSX.Elem
<>
<div className="FunnelsQuerySteps">
<ActionFilter
+ allowBehavioralPropertyFilter
bordered={false}
filters={actionFilters}
setFilters={setActionFilters}
diff --git a/frontend/src/scenes/insights/filters/ActionFilter/ActionFilter.tsx b/frontend/src/scenes/insights/filters/ActionFilter/ActionFilter.tsx
index 25af68beb320..fc42d55e1492 100644
--- a/frontend/src/scenes/insights/filters/ActionFilter/ActionFilter.tsx
+++ b/frontend/src/scenes/insights/filters/ActionFilter/ActionFilter.tsx
@@ -65,6 +65,9 @@ export interface ActionFilterProps {
hideDuplicate?: boolean
/** Whether to show the nested PropertyFilters in popover mode or not */
propertyFiltersPopover?: boolean
+ /** Opt in the flag-gated "Performed event" behavioral filter on each series. Only insight
+ * query contexts should enable it — realtime contexts (CDP, workflows) reject behavioral filters. */
+ allowBehavioralPropertyFilter?: boolean
/** A limit of entities (series or funnel steps) beyond which more can't be added */
entitiesLimit?: number
/** Custom suffix element to show in each ActionFilterRow */
@@ -131,6 +134,7 @@ export const ActionFilter = React.forwardRef<HTMLDivElement, ActionFilterProps>(
hideRename = false,
hideDuplicate = false,
propertyFiltersPopover,
+ allowBehavioralPropertyFilter,
customRowSuffix,
entitiesLimit,
showNestedArrow = false,
@@ -203,6 +207,7 @@ export const ActionFilter = React.forwardRef<HTMLDivElement, ActionFilterProps>(
actionsTaxonomicGroupTypes,
propertiesTaxonomicGroupTypes,
propertyFiltersPopover,
+ allowBehavioralPropertyFilter,
disabled,
readOnly,
renderRow,
diff --git a/frontend/src/scenes/insights/filters/ActionFilter/ActionFilterRow/ActionFilterRow.test.tsx b/frontend/src/scenes/insights/filters/ActionFilter/ActionFilterRow/ActionFilterRow.test.tsx
index 9ba143e5f1f6..e57c43189705 100644
--- a/frontend/src/scenes/insights/filters/ActionFilter/ActionFilterRow/ActionFilterRow.test.tsx
+++ b/frontend/src/scenes/insights/filters/ActionFilter/ActionFilterRow/ActionFilterRow.test.tsx
@@ -7,6 +7,8 @@ import userEvent from '@testing-library/user-event'
import { Provider } from 'kea'
import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
+import { FEATURE_FLAGS } from 'lib/constants'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { databaseTableListLogic } from 'scenes/data-management/database/databaseTableListLogic'
import { entityFilterLogic } from 'scenes/insights/filters/ActionFilter/entityFilterLogic'
@@ -380,6 +382,22 @@ describe('ActionFilterRow', () => {
renderRow(logic)
expect(document.querySelector('.ActionFilterRow-filters')).not.toBeInTheDocument()
})
+
+ it.each<{ flags: string[]; variants: Record<string, string | boolean>; shown: boolean }>([
+ {
+ flags: [FEATURE_FLAGS.BEHAVIORAL_PROPERTY_FILTER],
+ variants: { [FEATURE_FLAGS.BEHAVIORAL_PROPERTY_FILTER]: true },
+ shown: true,
+ },
+ { flags: [], variants: {}, shown: false },
+ ])('behavioral "Performed" entry point shown=$shown when flag present', ({ flags, variants, shown }) => {
+ featureFlagLogic.mount()
+ featureFlagLogic.actions.setFeatureFlags(flags, variants)
+ const { logic } = setup()
+ logic.actions.setEntityFilterVisibility(0, true)
+ renderRow(logic, { allowBehavioralPropertyFilter: true })
+ expect(!!screen.queryByText('Performed')).toBe(shown)
+ })
})
describe('drag handle', () => {
diff --git a/frontend/src/scenes/insights/filters/ActionFilter/ActionFilterRow/ActionFilterRow.tsx b/frontend/src/scenes/insights/filters/ActionFilter/ActionFilterRow/ActionFilterRow.tsx
index c42ed05122ad..f2902b8cd399 100644
--- a/frontend/src/scenes/insights/filters/ActionFilter/ActionFilterRow/ActionFilterRow.tsx
+++ b/frontend/src/scenes/insights/filters/ActionFilter/ActionFilterRow/ActionFilterRow.tsx
@@ -11,6 +11,7 @@ import { useCallback } from 'react'
import { IconCopy, IconFilter, IconGroupIntersect, IconPencil, IconTrash } from '@posthog/icons'
import { EntityFilterInfo } from 'lib/components/EntityFilterInfo'
+import { AddBehavioralFilterButton } from 'lib/components/PropertyFilters/components/AddBehavioralFilterButton'
import { PropertyFilters } from 'lib/components/PropertyFilters/PropertyFilters'
import { SeriesGlyph, SeriesLetter } from 'lib/components/SeriesGlyph'
import { defaultDataWarehousePopoverFields } from 'lib/components/TaxonomicFilter/taxonomicFilterLogic'
@@ -21,8 +22,10 @@ import {
quickFilterToPropertyFilters,
} from 'lib/components/TaxonomicFilter/types'
import { TaxonomicPopover, TaxonomicPopoverProps } from 'lib/components/TaxonomicPopover/TaxonomicPopover'
+import { FEATURE_FLAGS } from 'lib/constants'
import { IconWithCount, SortableDragIcon } from 'lib/lemon-ui/icons'
import { LemonButton } from 'lib/lemon-ui/LemonButton'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { getEventNamesForAction } from 'lib/utils/events'
import { databaseTableListLogic } from 'scenes/data-management/database/databaseTableListLogic'
import { funnelDataLogic } from 'scenes/funnels/funnelDataLogic'
@@ -94,6 +97,7 @@ export function ActionFilterRow({
hideDeleteBtn = false,
showCombine = false,
insightType,
+ allowBehavioralPropertyFilter = false,
propertyFiltersPopover = false,
onRenameClick = () => {},
showSeriesIndicator,
@@ -142,6 +146,7 @@ export function ActionFilterRow({
const { actions } = useValues(actionsModel)
const { mathDefinitions } = useValues(mathsLogic)
const { dataWarehouseTablesMap } = useValues(databaseTableListLogic)
+ const { featureFlags } = useValues(featureFlagLogic)
const mountedInsightDataLogic = insightDataLogic.findMounted({ dashboardItemId: typeKey })
const query = mountedInsightDataLogic?.values?.query
@@ -355,6 +360,11 @@ export function ActionFilterRow({
)
const isDataWarehouseFilter = filter.type === EntityTypes.DATA_WAREHOUSE
+ // A behavioral filter compiles to a person_id subquery over the events table, which a warehouse series has no key for
+ const behavioralFiltersEnabled =
+ allowBehavioralPropertyFilter &&
+ !!featureFlags[FEATURE_FLAGS.BEHAVIORAL_PROPERTY_FILTER] &&
+ !isDataWarehouseFilter
// CDP destination/workflow filters restrict the picker to the one warehouse table family their
// trigger fires on, so each family gets its own typeKey.
const dataWarehouseGroupType =
@@ -734,6 +744,18 @@ export function ActionFilterRow({
hogQLGlobals={hogQLGlobals}
operatorAllowlist={operatorAllowlist}
triggerVariant="input"
+ framedRows={behavioralFiltersEnabled}
+ addText={behavioralFiltersEnabled ? 'Filter' : undefined}
+ addFilterSuffix={
+ behavioralFiltersEnabled
+ ? (addFilter) => (
+ <AddBehavioralFilterButton
+ data-attr={`${index}-${value}-${typeKey}-add-behavioral-filter`}
+ onAdd={addFilter}
+ />
+ )
+ : null
+ }
/>
<SaveAsActionBanner filter={filter} />
</div>
diff --git a/frontend/src/scenes/insights/filters/ActionFilter/ActionFilterRow/types.ts b/frontend/src/scenes/insights/filters/ActionFilter/ActionFilterRow/types.ts
index b6bb68d8a282..8bb273ae8051 100644
--- a/frontend/src/scenes/insights/filters/ActionFilter/ActionFilterRow/types.ts
+++ b/frontend/src/scenes/insights/filters/ActionFilter/ActionFilterRow/types.ts
@@ -40,6 +40,9 @@ export interface ActionFilterRowProps {
hideDeleteBtn?: boolean // Choose to hide delete btn. You can use the onClose function passed into customRow{Pre|Suf}fix to render the delete btn anywhere
showCombine?: boolean // Show the combine inline events option
insightType?: InsightType // The type of insight (trends, funnels, etc.)
+ // Opt in the flag-gated "Performed event" behavioral filter. Off by default because behavioral
+ // filters compile to a person_id subquery, which realtime contexts (CDP, workflows) reject.
+ allowBehavioralPropertyFilter?: boolean
propertyFiltersPopover?: boolean
onRenameClick?: () => void // Used to open rename modal
showSeriesIndicator?: boolean // Show series badge