: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
fix(web-analytics): coerce non-string page URL in page reports filters (#69767)
Lucas Ricoy804a37524803
diff --git a/frontend/src/scenes/web-analytics/pageReportsLogic.test.ts b/frontend/src/scenes/web-analytics/pageReportsLogic.test.tsindex 605c7ee01e06..9075ab5d8fef 100644--- a/frontend/src/scenes/web-analytics/pageReportsLogic.test.ts+++ b/frontend/src/scenes/web-analytics/pageReportsLogic.test.ts@@ -48,6 +48,11 @@ describe('createPageReportsFilters', () => {expect(filters.map((filter) => filter.key).sort()).toEqual([...expectKeys].sort())})+ // kea-router JSON-parses query params, so ?pageURL=123 arrives (and gets persisted) as a number+ test.each([123, true, null])('non-string page URL %p does not crash the filter builder', (url) => {+ expect(() => createPageReportsFilters(url as unknown as string, true, null)).not.toThrow()+ })+test.each([{name: 'cleaning off keeps the pathname an exact match',diff --git a/frontend/src/scenes/web-analytics/pageReportsLogic.ts b/frontend/src/scenes/web-analytics/pageReportsLogic.tsindex 9630edf5e4a5..c83513bda82c 100644--- a/frontend/src/scenes/web-analytics/pageReportsLogic.ts+++ b/frontend/src/scenes/web-analytics/pageReportsLogic.ts@@ -64,7 +64,10 @@ export interface PageURLSearchResult {}export function createUrlPropertyFilter(url: string, stripQueryParams: boolean): WebAnalyticsPropertyFilters {- const parsed = parseWebAnalyticsURL(url)+ // kea-router JSON-parses query params (?pageURL=123 arrives as a number) and pageUrl is+ // persisted, so a non-string value would otherwise crash `url.split` below on every recompute+ const urlString: string = String(url ?? '')+ const parsed = parseWebAnalyticsURL(urlString)if (parsed.isValid && parsed.host && parsed.pathname) {return [@@ -87,7 +90,7 @@ export function createUrlPropertyFilter(url: string, stripQueryParams: boolean):return [{key: '$current_url',- value: stripQueryParams ? `^${url.split('?')[0]}(\\?.*)?$` : url,+ value: stripQueryParams ? `^${urlString.split('?')[0]}(\\?.*)?$` : urlString,operator: stripQueryParams ? PropertyOperator.Regex : PropertyOperator.Exact,type: PropertyFilterType.Event,},@@ -164,7 +167,7 @@ export function buildPageUrlOptions(}const representativeByCleaned = new Map<string, string>()- if (pageUrl) {+ if (typeof pageUrl === 'string' && pageUrl) {representativeByCleaned.set(cleanPageURLForDisplay(pageUrl, filters), pageUrl)}for (const { url } of pagesUrls) {@@ -957,8 +960,10 @@ export const pageReportsLogic = kea<pageReportsLogicType>({urlToAction: ({ actions, values }) => ({'/web/page-reports': (_, searchParams) => {- if (searchParams.pageURL && searchParams.pageURL !== values.pageUrl) {- actions.setPageUrl(searchParams.pageURL)+ // kea-router JSON-parses query params, so ?pageURL=123 arrives as a number+ const pageURL = searchParams.pageURL == null ? null : String(searchParams.pageURL)+ if (pageURL && pageURL !== values.pageUrl) {+ actions.setPageUrl(pageURL)}},}),