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.

fix(taxonomic-filter): search page urls only for a url-shaped query (#114942)

Paul D'Ambraaddf6b3533d9
diff --git a/frontend/src/lib/components/PropertyFilters/PropertyFilters.component.test.tsx b/frontend/src/lib/components/PropertyFilters/PropertyFilters.component.test.tsx
index 0b9d87480d35..69c2e63bdc68 100644
--- a/frontend/src/lib/components/PropertyFilters/PropertyFilters.component.test.tsx
+++ b/frontend/src/lib/components/PropertyFilters/PropertyFilters.component.test.tsx
@@ -197,7 +197,7 @@ describe('PropertyFilters recent selections', () => {
],
},
tabTestId: 'taxonomic-tab-pageview_urls',
- searchQuery: 'example',
+ searchQuery: 'example.com',
itemTestId: 'prop-filter-pageview_urls-0',
// Pageview URLs collapse to a single `$current_url IContains <query>` shortcut,
// so the recorded value is the typed query, not a specific matched URL.
@@ -296,7 +296,7 @@ describe('PropertyFilters recent selections', () => {
await pickShortcutItem({
tabTestId: 'taxonomic-tab-pageview_urls',
- searchQuery: 'first',
+ searchQuery: '/first',
itemTestId: 'prop-filter-pageview_urls-0',
onChange,
})
@@ -323,7 +323,7 @@ describe('PropertyFilters recent selections', () => {
await pickShortcutItem({
tabTestId: 'taxonomic-tab-pageview_urls',
- searchQuery: 'pricing',
+ searchQuery: '/pricing',
itemTestId: 'prop-filter-pageview_urls-0',
onChange,
})
@@ -350,7 +350,7 @@ describe('PropertyFilters recent selections', () => {
await pickShortcutItem({
tabTestId: 'taxonomic-tab-pageview_urls',
- searchQuery: 'pricing',
+ searchQuery: '/pricing',
itemTestId: 'prop-filter-pageview_urls-0',
onChange,
})
@@ -451,7 +451,7 @@ describe('PropertyFilters recent selections', () => {
await pickShortcutItem({
tabTestId: 'taxonomic-tab-pageview_urls',
- searchQuery: 'pricing',
+ searchQuery: '/pricing',
itemTestId: 'prop-filter-pageview_urls-0',
onChange,
})
diff --git a/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.test.tsx b/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.test.tsx
index ea2e06851d6a..a9eeb3f73b00 100644
--- a/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.test.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.test.tsx
@@ -1355,11 +1355,11 @@ describe('TaxonomicFilter', () => {
})
const searchInput = await waitFor(() => screen.getByTestId('taxonomic-filter-searchfield'))
- await withoutDebounceDelay((fakeTimerUser) => fakeTimerUser.type(searchInput, 'pricing'))
+ await withoutDebounceDelay((fakeTimerUser) => fakeTimerUser.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(firstRow.querySelector('[data-attr="taxonomic-shortcut-/pricing-property"]')).not.toBeNull()
expect(screen.queryByTestId('prop-filter-pageview_urls-1')).not.toBeInTheDocument()
})
@@ -1372,10 +1372,10 @@ describe('TaxonomicFilter', () => {
})
const searchInput = await waitFor(() => screen.getByTestId('taxonomic-filter-searchfield'))
- await withoutDebounceDelay((fakeTimerUser) => fakeTimerUser.type(searchInput, 'pricing'))
+ await withoutDebounceDelay((fakeTimerUser) => fakeTimerUser.type(searchInput, '/pricing'))
const row = await waitFor(() => {
- const el = document.querySelector('[data-attr="taxonomic-shortcut-pricing-property"]')
+ const el = document.querySelector('[data-attr="taxonomic-shortcut-/pricing-property"]')
expect(el).not.toBeNull()
return el as HTMLElement
})
@@ -1383,12 +1383,12 @@ describe('TaxonomicFilter', () => {
expect(onChangeMock).toHaveBeenCalledWith(
expect.objectContaining({ type: TaxonomicFilterGroupType.PageviewUrls }),
- 'pricing',
+ '/pricing',
expect.objectContaining({
_type: 'quick_filter',
propertyKey: '$current_url',
operator: PropertyOperator.IContains,
- filterValue: 'pricing',
+ filterValue: '/pricing',
propertyFilterType: PropertyFilterType.Event,
// Tagged so commit telemetry can distinguish the URL-contains shortcut
// from keyword shortcuts (parity with the rebuild's wasUrlContainsShortcut).
@@ -1407,7 +1407,7 @@ describe('TaxonomicFilter', () => {
useMockPageviewUrls(['https://example.com/pricing', 'https://example.com/pricing/teams'])
renderFilter({
// Two substantive groups so the aggregated "All" tab survives (a single
- // substantive group drops it); Events has no 'pricing' match so the URL
+ // substantive group drops it); Events has no '/pricing' match so the URL
// shortcut is still the only aggregated row.
taxonomicGroupTypes: [
TaxonomicFilterGroupType.SuggestedFilters,
@@ -1418,12 +1418,12 @@ describe('TaxonomicFilter', () => {
})
const searchInput = await waitFor(() => screen.getByTestId('taxonomic-filter-searchfield'))
- await user.type(searchInput, 'pricing')
+ 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(firstRow.querySelector('[data-attr="taxonomic-shortcut-/pricing-property"]')).not.toBeNull()
expect(screen.queryByTestId('prop-filter-suggested_filters-1')).not.toBeInTheDocument()
})
@@ -1465,12 +1465,12 @@ describe('TaxonomicFilter', () => {
// A query unique to this test, so this stays sound even if the `apiCache` reset in
// beforeEach ever goes away — a cached non-empty response under the same URL would
// make the negative assertions below pass for the wrong reason.
- await withoutDebounceDelay((user) => user.type(searchInput, 'nomatchquery'))
+ await withoutDebounceDelay((user) => 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()
+ expect(screen.queryByText('URL contains "/nomatchquery"')).not.toBeInTheDocument()
+ expect(document.querySelector('[data-attr="taxonomic-shortcut-/nomatchquery-property"]')).toBeNull()
})
})
})
diff --git a/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.test.ts b/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.test.ts
index 66a236b863be..f5c23ef8a9fa 100644
--- a/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.test.ts
+++ b/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.test.ts
@@ -561,6 +561,38 @@ describe('infiniteListLogic', () => {
})
})
+ describe('page URL search in a picker that collapses URLs to a contains row', () => {
+ beforeEach(() => {
+ useMocks({
+ get: {
+ '/api/environments/:team/events/values': [200, [{ name: 'https://example.com/pricing' }]],
+ },
+ })
+ })
+
+ it.each([
+ { kind: 'a plain word', query: 'pricing', offeredInAllTab: false },
+ { kind: 'a path', query: '/pricing', offeredInAllTab: true },
+ { kind: 'a domain', query: 'example.com', offeredInAllTab: true },
+ ])(
+ 'offers the URL contains row for $kind on the URL tab, and in the All tab only when it looks like a URL',
+ async ({ query, offeredInAllTab }) => {
+ const urlLogic = logicWith({
+ listGroupType: TaxonomicFilterGroupType.PageviewUrls,
+ taxonomicGroupTypes: [TaxonomicFilterGroupType.PageviewUrls],
+ collapseUrlsToContainsRow: true,
+ })
+
+ await expectLogic(urlLogic, () => {
+ urlLogic.actions.setSearchQuery(query)
+ }).toDispatchActions(['setSearchQuery', 'loadRemoteItemsSuccess'])
+
+ expect(urlLogic.values.items.results).toHaveLength(1)
+ expect(urlLogic.values.topMatchesForQuery).toHaveLength(offeredInAllTab ? 1 : 0)
+ }
+ )
+ })
+
describe('unmounting clears the shared api cache', () => {
it('does not keep serving a cached response after the list unmounts', async () => {
let requestCount = 0
diff --git a/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts b/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts
index 286986386b4a..720dd1605b40 100644
--- a/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts
+++ b/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts
@@ -49,6 +49,7 @@ import {
import {
buildUrlContainsShortcut,
COLLAPSED_TO_CONTAINS_ROW,
+ offersUrlContainsRow,
partitionContainsShortcuts,
} from 'lib/components/TaxonomicFilter/utils/collapsedContainsRow'
import {
@@ -1641,7 +1642,11 @@ export const infiniteListLogic = kea<infiniteListLogicType>([
// 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
+ const hasMatch =
+ trimmed.length > 0 &&
+ offersUrlContainsRow(listGroupType, trimmed) &&
+ remoteIsFresh &&
+ remoteItems.results.length > 0
return hasMatch ? [buildUrlContainsShortcut(trimmed, listGroupType)] : []
}
const results = hasRemoteDataSource ? (remoteIsFresh ? remoteItems.results : []) : localItems.results
diff --git a/frontend/src/lib/components/TaxonomicFilter/menu/Combobox.test.tsx b/frontend/src/lib/components/TaxonomicFilter/menu/Combobox.test.tsx
index 78599f3a1b4d..651db37285df 100644
--- a/frontend/src/lib/components/TaxonomicFilter/menu/Combobox.test.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/menu/Combobox.test.tsx
@@ -598,19 +598,34 @@ describe('MenuFilterCombobox', () => {
it('collapses matching URLs into one "URL contains <query>" row, not the raw URL list', async () => {
mockUrlValues(['https://app.posthog.com/checkout', 'https://app.posthog.com/checkout/pay'])
- renderAll({ groupTypes: [TaxonomicFilterGroupType.PageviewUrls], searchQuery: 'checkout' })
+ renderAll({ groupTypes: [TaxonomicFilterGroupType.PageviewUrls], searchQuery: '/checkout' })
- await waitFor(() => expect(rowTexts().some((t) => t.includes('URL contains "checkout"'))).toBe(true))
+ await waitFor(() => expect(rowTexts().some((t) => t.includes('URL contains "/checkout"'))).toBe(true))
const rows = rowTexts()
// Exactly one synthetic row, and none of the raw matched URLs are listed.
- expect(rows.filter((t) => t.includes('URL contains "checkout"'))).toHaveLength(1)
+ expect(rows.filter((t) => t.includes('URL contains "/checkout"'))).toHaveLength(1)
expect(rows.some((t) => t.includes('https://app.posthog.com/checkout'))).toBe(false)
})
+ it.each([
+ { kind: 'a plain word', query: 'checkout', offersRow: false },
+ { kind: 'a path', query: '/checkout', offersRow: true },
+ ])('offers the URL contains row for $kind only when it looks like a URL', async ({ query, offersRow }) => {
+ mockUrlValues(['https://app.posthog.com/checkout'])
+
+ renderAll({ groupTypes: [TaxonomicFilterGroupType.PageviewUrls], searchQuery: query })
+
+ await waitFor(() =>
+ expect(apiGet.mock.calls.some(([url]: unknown[]) => String(url).includes('events/values'))).toBe(true)
+ )
+ await waitFor(() => expect(screen.queryByTestId('menu-filter-loading')).not.toBeInTheDocument())
+ expect(rowTexts().some((t) => t.includes(`URL contains "${query}"`))).toBe(offersRow)
+ })
+
it('shows no URL suggestion when no pageview URL matches (0 slots)', async () => {
mockUrlValues([])
- renderAll({ groupTypes: [TaxonomicFilterGroupType.PageviewUrls], searchQuery: 'zzznomatch' })
+ renderAll({ groupTypes: [TaxonomicFilterGroupType.PageviewUrls], searchQuery: '/zzznomatch' })
await waitFor(() => expect(screen.queryByTestId('menu-filter-loading')).not.toBeInTheDocument())
expect(screen.queryByText(/URL contains/)).not.toBeInTheDocument()
@@ -635,13 +650,13 @@ describe('MenuFilterCombobox', () => {
renderAll({
groupTypes: [TaxonomicFilterGroupType.PageviewUrls],
- searchQuery: 'checkout',
+ searchQuery: '/checkout',
onCommit,
})
- await waitFor(() => expect(rowTexts().some((t) => t.includes('URL contains "checkout"'))).toBe(true))
+ await waitFor(() => expect(rowTexts().some((t) => t.includes('URL contains "/checkout"'))).toBe(true))
const row = Array.from(document.querySelectorAll('[data-slot="taxonomic-filter-menu-row"]')).find((el) =>
- el.textContent?.includes('URL contains "checkout"')
+ el.textContent?.includes('URL contains "/checkout"')
) as HTMLElement
await user.click(row)
@@ -649,7 +664,7 @@ describe('MenuFilterCombobox', () => {
expect(entry.group.type).toBe(TaxonomicFilterGroupType.PageviewUrls)
// getValue reads the item name; the synthetic row carries the query, which
// `taxonomicPropertyFilterLogic.selectItem` turns into `$current_url IContains`.
- expect(entry.group.getValue(entry.item)).toBe('checkout')
+ expect(entry.group.getValue(entry.item)).toBe('/checkout')
// Tagged so the commit telemetry can measure adoption of the shortcut.
expect((entry.item as { isContainsShortcut?: boolean }).isContainsShortcut).toBe(true)
})
diff --git a/frontend/src/lib/components/TaxonomicFilter/menu/Combobox.tsx b/frontend/src/lib/components/TaxonomicFilter/menu/Combobox.tsx
index 15d5b6e704f3..426dd844a2b9 100644
--- a/frontend/src/lib/components/TaxonomicFilter/menu/Combobox.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/menu/Combobox.tsx
@@ -53,6 +53,7 @@ import {
} from '../types'
import {
COLLAPSED_TO_CONTAINS_ROW,
+ offersUrlContainsRow,
partitionContainsShortcuts,
urlContainsRowLabel,
} from '../utils/collapsedContainsRow'
@@ -368,7 +369,7 @@ export function MenuFilterCombobox({
// `name`), so `selectItem`'s existing PageviewUrls branch commits
// `$current_url IContains <query>`.
if (COLLAPSED_TO_CONTAINS_ROW.has(group.type)) {
- if (trimmedQuery && items.length > 0) {
+ if (trimmedQuery && offersUrlContainsRow(group.type, trimmedQuery) && items.length > 0) {
const label = urlContainsRowLabel(trimmedQuery)
merged.push({
// A plain item (not a QuickFilterItem): the commit reads its value via
diff --git a/frontend/src/lib/components/TaxonomicFilter/utils/collapsedContainsRow.ts b/frontend/src/lib/components/TaxonomicFilter/utils/collapsedContainsRow.ts
index c48c68bc2162..a9b8bd609460 100644
--- a/frontend/src/lib/components/TaxonomicFilter/utils/collapsedContainsRow.ts
+++ b/frontend/src/lib/components/TaxonomicFilter/utils/collapsedContainsRow.ts
@@ -17,6 +17,16 @@ export const COLLAPSED_TO_CONTAINS_ROW: ReadonlySet<TaxonomicFilterGroupType> =
TaxonomicFilterGroupType.PageviewEvents,
])
+const URL_SHAPED_QUERY = /[/.:]/
+
+/** In a property filter's mixed list, page URLs offer the "URL contains" row only for a query like
+ * `/pricing` or `example.com`. A plain word such as `email` usually names a property, and people
+ * often picked the row for it by mistake. Series pickers and the dedicated Pageview URLs tab offer
+ * the row for any query. Shared by both surfaces. */
+export function offersUrlContainsRow(groupType: TaxonomicFilterGroupType, query: string): boolean {
+ return groupType !== TaxonomicFilterGroupType.PageviewUrls || URL_SHAPED_QUERY.test(query)
+}
+
export function urlContainsRowLabel(query: string): string {
return `URL contains "${query}"`
}