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(taxonomic-filter): mirror pageview URL collapse into legacy picker (#63392)

Paul D'Ambradb2adad0456b
diff --git a/frontend/src/lib/components/PropertyFilters/PropertyFilters.component.test.tsx b/frontend/src/lib/components/PropertyFilters/PropertyFilters.component.test.tsx
index f7fb3826b389..5f44a6d63b2f 100644
--- a/frontend/src/lib/components/PropertyFilters/PropertyFilters.component.test.tsx
+++ b/frontend/src/lib/components/PropertyFilters/PropertyFilters.component.test.tsx
@@ -181,8 +181,10 @@ describe('PropertyFilters recent selections', () => {
tabTestId: 'taxonomic-tab-pageview_urls',
searchQuery: 'example',
itemTestId: 'prop-filter-pageview_urls-0',
- expectedRecentPattern: /Current URL.*∋.*example\.com\/pricing/i,
- expectedValuePattern: /example\.com\/pricing/i,
+ // Pageview URLs collapse to a single `$current_url IContains <query>` shortcut,
+ // so the recorded value is the typed query, not a specific matched URL.
+ expectedRecentPattern: /Current URL.*∋.*example/i,
+ expectedValuePattern: /example/i,
},
{
description: 'screen name',
@@ -288,7 +290,8 @@ describe('PropertyFilters recent selections', () => {
await openNewFilter()
await waitFor(() => {
- expectBareKeyBeforeFullRecent(/example\.com\/first/i, /Current URL.*∋.*example\.com\/first/i)
+ // Collapsed to `$current_url IContains 'first'` — the recent shows the query.
+ expectBareKeyBeforeFullRecent(/first/i, /Current URL.*∋.*first/i)
})
})
diff --git a/frontend/src/lib/components/PropertyFilters/components/TaxonomicPropertyFilter.tsx b/frontend/src/lib/components/PropertyFilters/components/TaxonomicPropertyFilter.tsx
index 9c66ae39632e..569b2ec1ee68 100644
--- a/frontend/src/lib/components/PropertyFilters/components/TaxonomicPropertyFilter.tsx
+++ b/frontend/src/lib/components/PropertyFilters/components/TaxonomicPropertyFilter.tsx
@@ -186,6 +186,7 @@ export function TaxonomicPropertyFilter({
excludedOperators={excludedOperators}
selectingKeyOnly={selectingKeyOnly}
enableKeywordShortcuts
+ collapseUrlsToContainsRow
/>
)
diff --git a/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.test.tsx b/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.test.tsx
index da3bb40444bf..8544857ada93 100644
--- a/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.test.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.test.tsx
@@ -1047,6 +1047,135 @@ describe('TaxonomicFilter', () => {
})
})
+ describe('collapseUrlsToContainsRow', () => {
+ function useMockPageviewUrls(urls: string[]): void {
+ useMocks({
+ get: {
+ '/api/projects/:team/event_definitions': mockGetEventDefinitions,
+ '/api/projects/:team/property_definitions': mockGetPropertyDefinitions,
+ '/api/environments/:team/events/values': urls.map((name) => ({ name })),
+ },
+ })
+ }
+
+ it('collapses the matching URL list to a single "URL contains" shortcut row', async () => {
+ const user = userEvent.setup()
+ useMockPageviewUrls(['https://example.com/pricing', 'https://example.com/pricing/teams'])
+ renderFilter({
+ taxonomicGroupTypes: [TaxonomicFilterGroupType.PageviewUrls],
+ collapseUrlsToContainsRow: true,
+ })
+
+ const searchInput = await waitFor(() => screen.getByTestId('taxonomic-filter-searchfield'))
+ await user.type(searchInput, 'pricing')
+
+ const firstRow = await waitFor(() => screen.getByTestId('prop-filter-pageview_urls-0'))
+ // The two matching URLs collapse into one row, which is the contains shortcut.
+ expect(firstRow.querySelector('[data-attr="taxonomic-shortcut-pricing-property"]')).not.toBeNull()
+ expect(screen.queryByTestId('prop-filter-pageview_urls-1')).not.toBeInTheDocument()
+ })
+
+ it('commits $current_url IContains <query> when the shortcut row is selected', async () => {
+ const user = userEvent.setup()
+ useMockPageviewUrls(['https://example.com/pricing'])
+ renderFilter({
+ taxonomicGroupTypes: [TaxonomicFilterGroupType.PageviewUrls],
+ collapseUrlsToContainsRow: true,
+ })
+
+ const searchInput = await waitFor(() => screen.getByTestId('taxonomic-filter-searchfield'))
+ await user.type(searchInput, 'pricing')
+
+ const row = await waitFor(() => {
+ const el = document.querySelector('[data-attr="taxonomic-shortcut-pricing-property"]')
+ expect(el).not.toBeNull()
+ return el as HTMLElement
+ })
+ await user.click(row)
+
+ expect(onChangeMock).toHaveBeenCalledWith(
+ expect.objectContaining({ type: TaxonomicFilterGroupType.PageviewUrls }),
+ 'pricing',
+ expect.objectContaining({
+ _type: 'quick_filter',
+ propertyKey: '$current_url',
+ operator: PropertyOperator.IContains,
+ filterValue: 'pricing',
+ propertyFilterType: PropertyFilterType.Event,
+ // Tagged so commit telemetry can distinguish the URL-contains shortcut
+ // from keyword shortcuts (parity with the rebuild's wasUrlContainsShortcut).
+ isContainsShortcut: true,
+ })
+ )
+ })
+
+ it('collapses URLs in the aggregated Suggested filters tab too', async () => {
+ const user = userEvent.setup()
+ useMockPageviewUrls(['https://example.com/pricing', 'https://example.com/pricing/teams'])
+ renderFilter({
+ taxonomicGroupTypes: [TaxonomicFilterGroupType.SuggestedFilters, TaxonomicFilterGroupType.PageviewUrls],
+ collapseUrlsToContainsRow: true,
+ })
+
+ const searchInput = await waitFor(() => screen.getByTestId('taxonomic-filter-searchfield'))
+ await user.type(searchInput, 'pricing')
+
+ // The Suggested filters tab is the default and aggregates each group's top matches —
+ // the URL group must contribute the single shortcut there, not raw URLs.
+ const firstRow = await waitFor(() => screen.getByTestId('prop-filter-suggested_filters-0'))
+ expect(firstRow.querySelector('[data-attr="taxonomic-shortcut-pricing-property"]')).not.toBeNull()
+ expect(screen.queryByTestId('prop-filter-suggested_filters-1')).not.toBeInTheDocument()
+ })
+
+ it('lists individual URLs (no collapse) when the prop is omitted', async () => {
+ const user = userEvent.setup()
+ useMockPageviewUrls(['https://example.com/pricing'])
+ renderFilter({
+ taxonomicGroupTypes: [TaxonomicFilterGroupType.PageviewUrls],
+ })
+
+ const searchInput = await waitFor(() => screen.getByTestId('taxonomic-filter-searchfield'))
+ await user.type(searchInput, 'pricing')
+
+ await waitFor(() => {
+ expect(screen.getByTestId('prop-filter-pageview_urls-0')).toBeInTheDocument()
+ })
+ expect(document.querySelector('[data-attr="taxonomic-shortcut-pricing-property"]')).toBeNull()
+ })
+
+ it('shows no shortcut row when no URL matches the query', async () => {
+ const user = userEvent.setup()
+ // Flag set when the URL values endpoint actually responds (empty), so the negative
+ // assertions below aren't vacuously true before the async fetch path runs.
+ let valuesFetched = false
+ useMocks({
+ get: {
+ '/api/projects/:team/event_definitions': mockGetEventDefinitions,
+ '/api/projects/:team/property_definitions': mockGetPropertyDefinitions,
+ '/api/environments/:team/events/values': () => {
+ valuesFetched = true
+ return [200, []]
+ },
+ },
+ })
+ renderFilter({
+ taxonomicGroupTypes: [TaxonomicFilterGroupType.PageviewUrls],
+ collapseUrlsToContainsRow: true,
+ })
+
+ const searchInput = await waitFor(() => screen.getByTestId('taxonomic-filter-searchfield'))
+ // A query unique to this test so the module-level `apiCache` in infiniteListLogic
+ // can't serve a non-empty response cached by an earlier test under the same URL.
+ await user.type(searchInput, 'nomatchquery')
+
+ await waitFor(() => expect(valuesFetched).toBe(true))
+ await waitFor(() => {
+ expect(screen.queryByText('URL contains "nomatchquery"')).not.toBeInTheDocument()
+ expect(document.querySelector('[data-attr="taxonomic-shortcut-nomatchquery-property"]')).toBeNull()
+ })
+ })
+ })
+
describe('category dropdown A/B test', () => {
let unmountFeatureFlagLogic: (() => void) | null = null
diff --git a/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.tsx b/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.tsx
index e18311c7c13d..8170bf2053dd 100644
--- a/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.tsx
@@ -61,6 +61,7 @@ export function TaxonomicFilter({
enableKeywordShortcuts,
excludedOperators,
selectingKeyOnly,
+ collapseUrlsToContainsRow,
}: TaxonomicFilterProps): JSX.Element {
// Generate a unique key for each unique TaxonomicFilter that's rendered
const taxonomicFilterLogicKey = useMemo(
@@ -108,6 +109,7 @@ export function TaxonomicFilter({
enableKeywordShortcuts,
excludedOperators,
selectingKeyOnly,
+ collapseUrlsToContainsRow,
}
const logic = taxonomicFilterLogic(taxonomicFilterLogicProps)
diff --git a/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts b/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts
index c6410c502e5c..8e5ee253d78c 100644
--- a/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts
+++ b/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts
@@ -30,6 +30,10 @@ import {
TaxonomicFilterGroup,
TaxonomicFilterGroupType,
} from 'lib/components/TaxonomicFilter/types'
+import {
+ buildUrlContainsShortcut,
+ COLLAPSED_TO_CONTAINS_ROW,
+} from 'lib/components/TaxonomicFilter/utils/collapsedContainsRow'
import { promoteMatchingProperties } from 'lib/components/TaxonomicFilter/utils/promoteProperties'
import { FEATURE_FLAGS } from 'lib/constants'
import { createFuse } from 'lib/utils/fuseSearch'
@@ -706,18 +710,36 @@ export const infiniteListLogic = kea<infiniteListLogicType>([
},
],
topMatchesForQuery: [
- (s) => [s.localItems, s.remoteItems, s.searchQuery, s.hasRemoteDataSource, s.keywordShortcutItems],
+ (s) => [
+ s.localItems,
+ s.remoteItems,
+ s.searchQuery,
+ s.hasRemoteDataSource,
+ s.keywordShortcutItems,
+ s.listGroupType,
+ (_, props: InfiniteListLogicProps) => props.collapseUrlsToContainsRow,
+ ],
(
localItems,
remoteItems,
searchQuery,
hasRemoteDataSource,
- keywordShortcutItems
+ keywordShortcutItems,
+ listGroupType,
+ collapseUrlsToContainsRow
): TaxonomicDefinitionTypes[] => {
if (!searchQuery) {
return []
}
const remoteIsFresh = remoteItems.searchQuery === searchQuery
+ // Collapsed groups contribute the single "URL contains <query>" shortcut to the
+ // aggregated SuggestedFilters / "All" tab too — not the raw URL matches — so the
+ // common entry path collapses identically to the dedicated group list above.
+ if (collapseUrlsToContainsRow && COLLAPSED_TO_CONTAINS_ROW.has(listGroupType)) {
+ const trimmed = searchQuery.trim()
+ const hasMatch = trimmed.length > 0 && remoteIsFresh && remoteItems.results.length > 0
+ return hasMatch ? [buildUrlContainsShortcut(trimmed)] : []
+ }
const results = hasRemoteDataSource ? (remoteIsFresh ? remoteItems.results : []) : localItems.results
const realMatches = promoteMatchingProperties(results, searchQuery).slice(0, MAX_TOP_MATCHES_PER_GROUP)
// Shortcuts lead the group's top-match contribution so the aggregated SuggestedFilters
@@ -850,6 +872,7 @@ export const infiniteListLogic = kea<infiniteListLogicType>([
s.suggestedPinnedMatches,
s.suggestedRecentMatches,
s.keywordShortcutItems,
+ (_, props: InfiniteListLogicProps) => props.collapseUrlsToContainsRow,
],
(
remoteItems,
@@ -861,8 +884,29 @@ export const infiniteListLogic = kea<infiniteListLogicType>([
contextFilteredPinnedItems,
suggestedPinnedMatches,
suggestedRecentMatches,
- keywordShortcutItems
+ keywordShortcutItems,
+ collapseUrlsToContainsRow
) => {
+ // Collapse URL groups to a single "URL contains <query>" shortcut row
+ // (mirrors the rebuild menu's `COLLAPSED_TO_CONTAINS_ROW`). Only once
+ // the remote fetch for the *current* query has returned at least one
+ // match — otherwise the list is empty and the standard empty/loading
+ // states apply.
+ if (collapseUrlsToContainsRow && COLLAPSED_TO_CONTAINS_ROW.has(listGroupType)) {
+ const trimmed = (searchQuery ?? '').trim()
+ // The remote fetch is debounced and lags the typed query, so guard against a
+ // stale match from the previous query producing a shortcut for the new one.
+ const remoteIsFresh = (remoteItems.searchQuery ?? '').trim() === trimmed
+ const hasMatch = trimmed.length > 0 && remoteIsFresh && remoteItems.results.length > 0
+ const results = hasMatch ? [buildUrlContainsShortcut(trimmed)] : []
+ return {
+ results,
+ count: results.length,
+ searchQuery: remoteItems.searchQuery,
+ queryChanged: remoteItems.queryChanged,
+ first: remoteItems.first,
+ }
+ }
const isSuggested = listGroupType === TaxonomicFilterGroupType.SuggestedFilters
const recentPrefix = isSuggested && !searchQuery ? (contextFilteredRecentItems || []).slice(0, 3) : []
const pinnedPrefix = isSuggested && !searchQuery ? (contextFilteredPinnedItems || []).slice(0, 3) : []
diff --git a/frontend/src/lib/components/TaxonomicFilter/menu/Combobox.tsx b/frontend/src/lib/components/TaxonomicFilter/menu/Combobox.tsx
index 854193da50ec..82bc4bfca63a 100644
--- a/frontend/src/lib/components/TaxonomicFilter/menu/Combobox.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/menu/Combobox.tsx
@@ -43,6 +43,7 @@ import { getCoreFilterDefinition } from '~/taxonomy/helpers'
import { useTaxonomicFilterContext } from '../headless/context'
import { useGroupList } from '../hooks/useGroupList'
import { TaxonomicDefinitionTypes, TaxonomicFilterGroup, TaxonomicFilterGroupType } from '../types'
+import { COLLAPSED_TO_CONTAINS_ROW, urlContainsRowLabel } from '../utils/collapsedContainsRow'
import { promoteMatchingBy } from '../utils/promoteProperties'
import { MenuFilterHeader } from './Header'
import { PreviewPane } from './PreviewPane'
@@ -77,15 +78,6 @@ const HIDDEN_FROM_CHIPS: ReadonlySet<TaxonomicFilterGroupType> = new Set([
TaxonomicFilterGroupType.HogQLExpression,
])
-/** Groups that feed the "all" surface but are collapsed to a single
- * "URL contains <query>" suggestion rather than listing every matching value,
- * and are not offered as a standalone chip/category. People filtering by URL
- * overwhelmingly want a contains match, so one synthetic row (when any URL
- * matches) beats a wall of exact URLs. */
-const COLLAPSED_TO_CONTAINS_ROW: ReadonlySet<TaxonomicFilterGroupType> = new Set([
- TaxonomicFilterGroupType.PageviewUrls,
-])
-
/** How many recents and pinned each lead the default "All" surface, matching
* the pill variant's top-3 face. */
const RECENT_PINNED_PREFIX_LIMIT = 3
@@ -347,7 +339,7 @@ export function MenuFilterCombobox({
// `$current_url IContains <query>`.
if (COLLAPSED_TO_CONTAINS_ROW.has(group.type)) {
if (trimmedQuery && items.length > 0) {
- const label = `URL contains "${trimmedQuery}"`
+ const label = urlContainsRowLabel(trimmedQuery)
merged.push({
// `isContainsShortcut` tags this synthetic row so the commit
// telemetry can measure adoption of the contains shortcut vs
diff --git a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx
index 54a4c295e00c..46110add2802 100644
--- a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx
@@ -1145,8 +1145,12 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>([
type: TaxonomicFilterGroupType.PageviewUrls,
endpoint: `api/environments/${teamId}/events/values/?key=$current_url&event_name=$pageview`,
searchAlias: 'value',
- getName: (option: SimpleOption) => option.name,
- getValue: (option: SimpleOption) => option.name,
+ getName: (option: SimpleOption | QuickFilterItem) => option.name,
+ // The collapsed "URL contains <query>" row is a QuickFilterItem whose
+ // selection value is the typed query, so generic consumers reading the
+ // committed value get the query (matching the rebuild menu), not the label.
+ getValue: (option: SimpleOption | QuickFilterItem) =>
+ isQuickFilterItem(option) ? option.filterValue : option.name,
getPopoverHeader: () => `Pageview URL`,
minSearchQueryLength: 3,
searchDescription: 'URLs seen on pageview events',
@@ -1843,6 +1847,9 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>([
filterValue: item.filterValue,
propertyFilterType: item.propertyFilterType,
eventName: item.eventName,
+ // Mirrors the rebuild menu's `wasUrlContainsShortcut` so contains-shortcut
+ // adoption is comparable across arms, not muddied with keyword shortcuts.
+ wasUrlContainsShortcut: item.isContainsShortcut === true,
}),
})
diff --git a/frontend/src/lib/components/TaxonomicFilter/types.ts b/frontend/src/lib/components/TaxonomicFilter/types.ts
index e67ade987d05..a6959d937792 100644
--- a/frontend/src/lib/components/TaxonomicFilter/types.ts
+++ b/frontend/src/lib/components/TaxonomicFilter/types.ts
@@ -39,6 +39,10 @@ export interface QuickFilterItem {
propertyFilterType: PropertyFilterType.Event | PropertyFilterType.Person
eventName?: string
extraProperties?: (EventPropertyFilter | PersonPropertyFilter)[]
+ /** Set on the collapsed `URL contains "<query>"` row so commit telemetry can
+ * measure contains-shortcut adoption, matching the rebuild menu's
+ * `wasUrlContainsShortcut`. */
+ isContainsShortcut?: boolean
}
export function isQuickFilterItem(item: unknown): item is QuickFilterItem {
@@ -177,6 +181,14 @@ export interface TaxonomicFilterProps {
* - `TaxonomicPropertyFilter` hides the operator+value pair on rows whose group is key-only.
* See `SelectingKeyOnly` for the boolean-or-per-group-dict shape. */
selectingKeyOnly?: SelectingKeyOnly
+ /** Collapse URL-shaped groups (Pageview URLs) to a single `URL contains "<query>"`
+ * shortcut row instead of listing every matching URL — mirrors the rebuild menu.
+ * Selecting the row commits `$current_url IContains <query>` via a `QuickFilterItem`,
+ * so a host must handle `isQuickFilterItem(item)` in onChange to honor the contains
+ * operator. Only `TaxonomicPropertyFilter` (and the property/universal-filter hosts
+ * behind it) opts in — that covers every current pageview-URL consumer — so the paths
+ * picker keeps its full URL list. */
+ collapseUrlsToContainsRow?: boolean
}
export interface DataWarehousePopoverField {
diff --git a/frontend/src/lib/components/TaxonomicFilter/utils/collapsedContainsRow.ts b/frontend/src/lib/components/TaxonomicFilter/utils/collapsedContainsRow.ts
new file mode 100644
index 000000000000..1292a3aa9b8e
--- /dev/null
+++ b/frontend/src/lib/components/TaxonomicFilter/utils/collapsedContainsRow.ts
@@ -0,0 +1,33 @@
+import { PropertyFilterType, PropertyOperator } from '~/types'
+
+import { QuickFilterItem, TaxonomicFilterGroupType } from '../types'
+
+/** Groups that collapse to a single "URL contains <query>" suggestion instead of
+ * listing every matching value, and are not offered as a standalone value picker.
+ * People filtering by URL overwhelmingly want a contains match, so one synthetic
+ * row (when any URL matches) beats a wall of exact URLs. Shared by the legacy
+ * picker (`infiniteListLogic`) and the rebuild menu (`menu/Combobox`) so both arms
+ * of the experiment collapse identically. */
+export const COLLAPSED_TO_CONTAINS_ROW: ReadonlySet<TaxonomicFilterGroupType> = new Set([
+ TaxonomicFilterGroupType.PageviewUrls,
+])
+
+export function urlContainsRowLabel(query: string): string {
+ return `URL contains "${query}"`
+}
+
+/** Synthetic row committed as `$current_url IContains <query>`. Returned as a
+ * `QuickFilterItem` so it flows through the existing `isQuickFilterItem` handling
+ * in the property- and universal-filter hosts, committing the same filter the
+ * per-URL value picker used to — without listing every matching URL. */
+export function buildUrlContainsShortcut(query: string): QuickFilterItem {
+ return {
+ _type: 'quick_filter',
+ name: urlContainsRowLabel(query),
+ filterValue: query,
+ operator: PropertyOperator.IContains,
+ propertyKey: '$current_url',
+ propertyFilterType: PropertyFilterType.Event,
+ isContainsShortcut: true,
+ }
+}