: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
feat(web-analytics): add property filters to page performance tab (#89378)
Lucas Ricoyb143767931e3
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex b2443549d2e0..6c81d07325f0 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -8453,9 +8453,9 @@ snapshots:scenes-app-web-analytics-pageperformancemetriccard--without-sparkline--light:hash: v1.k794b7964.27bbdd01e4451fe0fe7cfbf693975714907972cdef4cc9b74ab13f99c28f5c34.9VZtUj_jx6H9AXXqTTKz1uomaF3X9e8cENkeIs8iJ_Iscenes-app-web-analytics-search-ai--web-analytics-page-performance--dark:- hash: v1.k794b7964.59a8f6024a2ea5bf33a41c4c3f1de33162797cac03eeb2a6e75196686126fdcd.IEU7UFRnMeS-XS_Eibt7SRW7QxH6_R4l4Ut1Kuepjm0+ hash: v1.k794b7964.e16fba49fefaa838664302127f5c6d217c9f5e4ed524782d28c4329910e8c41f.1HBkyN4tp4cpY22NHhGYjSY4FAycELc2UGR_fHsm5XEscenes-app-web-analytics-search-ai--web-analytics-page-performance--light:- hash: v1.k794b7964.a6ba7deb703189986a29cd9fb512528232cc1fb8a602716b072fdff8a378695d.dt9pqc4bKRhF4MB52Ph_323zhIke8DbgpLAasOFzFHc+ hash: v1.k794b7964.ed85370e899c4756038835ed4299a9bfd86c3b5d4173f5f03be2ebf505f24582.5YrW-wAvpl3P_2Ikn1DEusrQl_Wq7gU-XU9HuPd35nwscenes-inbox-scout-tags--editor-and-filter--dark:hash: v1.k794b7964.b76b173ee1dc78112e700af267b53d59959164f8ebbc814df2b5f4a3811bcd49.2hfIhAW_k3BdFlo9jtUoJhOyZhS1uQmgafcdvh_CGmgscenes-inbox-scout-tags--editor-and-filter--light:diff --git a/frontend/src/scenes/web-analytics/PagePerformanceFilters.tsx b/frontend/src/scenes/web-analytics/PagePerformanceFilters.tsxindex 6394a24ec1f1..6165b393e21d 100644--- a/frontend/src/scenes/web-analytics/PagePerformanceFilters.tsx+++ b/frontend/src/scenes/web-analytics/PagePerformanceFilters.tsx@@ -1,11 +1,12 @@import { useActions, useValues } from 'kea'import { IconRefresh } from '@posthog/icons'-import { LemonButton, Spinner } from '@posthog/lemon-ui'+import { LemonButton, LemonSnack, Spinner } from '@posthog/lemon-ui'import { CompareFilter } from 'lib/components/CompareFilter/CompareFilter'import { DateFilter } from 'lib/components/DateFilter/DateFilter'import { FilterBar } from 'lib/components/FilterBar'+import { COUNTRY_CODE_TO_LONG_NAME, countryCodeToFlag } from 'lib/utils/country'import { dataNodeCollectionLogic } from '~/queries/nodes/DataNode/dataNodeCollectionLogic'@@ -13,8 +14,39 @@ import { WEB_ANALYTICS_DATA_COLLECTION_NODE_ID } from './common'import { webAnalyticsDateMapping } from './constants'import { pagePerformanceLogic } from './pagePerformanceLogic'import { PathCleaningToggle } from './PathCleaningToggle'+import { WebAnalyticsDeviceToggle, WebAnalyticsDomainSelector } from './WebAnalyticsFilters'import { webAnalyticsLogic } from './webAnalyticsLogic'import { WebConversionGoal } from './WebConversionGoal'+import { WebPropertyFilters } from './WebPropertyFilters'++/**+ * Country and referrer narrow this tab's queries and round-trip through its URL, but neither has a+ * control of its own here the way the domain and device selections do. A shared link that carries+ * one would otherwise filter the numbers with nothing on screen to explain it. Renders nothing when+ * neither is set, which is the usual case.+ */+const ActiveDrillDownFilters = (): JSX.Element | null => {+ const { countryFilter, referrerFilter } = useValues(webAnalyticsLogic)+ const { setCountryFilter, setReferrerFilter } = useActions(webAnalyticsLogic)++ if (!countryFilter && !referrerFilter) {+ return null+ }++ return (+ <>+ {countryFilter && (+ <LemonSnack onClose={() => setCountryFilter(null)}>+ Country: {countryCodeToFlag(countryFilter)}{' '}+ {COUNTRY_CODE_TO_LONG_NAME[countryFilter] ?? countryFilter}+ </LemonSnack>+ )}+ {referrerFilter && (+ <LemonSnack onClose={() => setReferrerFilter(null)}>Referrer: {referrerFilter}</LemonSnack>+ )}+ </>+ )+}export const PagePerformanceFilters = ({ tabs }: { tabs: JSX.Element }): JSX.Element => {const {@@ -49,11 +81,19 @@ export const PagePerformanceFilters = ({ tabs }: { tabs: JSX.Element }): JSX.EledateTo={dateTo}onChange={setDates}/>+ <WebAnalyticsDomainSelector />+ <WebAnalyticsDeviceToggle />+ <ActiveDrillDownFilters /><CompareFilter compareFilter={compareFilter} updateCompareFilter={setCompareFilter} /><PathCleaningToggle value={isPathCleaningEnabled} onChange={setIsPathCleaningEnabled} /></>}- right={<WebConversionGoal value={conversionGoal} onChange={setConversionGoal} />}+ right={+ <>+ <WebConversionGoal value={conversionGoal} onChange={setConversionGoal} />+ <WebPropertyFilters />+ </>+ }/>)}diff --git a/frontend/src/scenes/web-analytics/WebAnalyticsFilters.tsx b/frontend/src/scenes/web-analytics/WebAnalyticsFilters.tsxindex bedca8b99137..a501edb9aa8d 100644--- a/frontend/src/scenes/web-analytics/WebAnalyticsFilters.tsx+++ b/frontend/src/scenes/web-analytics/WebAnalyticsFilters.tsx@@ -441,7 +441,7 @@ export const WebAnalyticsLiveReferrerSelector = ({ suggestions = [] }: { suggest)}-const WebAnalyticsDeviceToggle = (): JSX.Element => {+export const WebAnalyticsDeviceToggle = (): JSX.Element => {const { deviceTypeFilter } = useValues(webAnalyticsLogic)const { setDeviceTypeFilter } = useActions(webAnalyticsLogic)const { featureFlags } = useValues(featureFlagLogic)diff --git a/frontend/src/scenes/web-analytics/botAnalyticsLogic.ts b/frontend/src/scenes/web-analytics/botAnalyticsLogic.tsindex ad8a0decc27b..a9b473868b51 100644--- a/frontend/src/scenes/web-analytics/botAnalyticsLogic.ts+++ b/frontend/src/scenes/web-analytics/botAnalyticsLogic.ts@@ -1,8 +1,11 @@-import { MakeLogicType, actions, connect, kea, listeners, path, reducers, selectors } from 'kea'+import { MakeLogicType, actions, afterMount, connect, kea, listeners, path, reducers, selectors } from 'kea'import { router } from 'kea-router'import { isNotNil } from 'lib/utils/guards'+import { removeProjectIdIfPresent, stripTrailingSlash } from 'lib/utils/kea-router'+import { objectsEqual } from 'lib/utils/objects'+import { isWebAnalyticsPropertyFilters } from '~/queries/schema-guards'import {EventsNode,GroupNode,@@ -25,9 +28,6 @@ import {import {BOT_ANALYTICS_EVENTS,- INITIAL_DATE_FROM,- INITIAL_DATE_TO,- INITIAL_INTERVAL,INITIAL_WEB_ANALYTICS_FILTER,TabsTileTab,TileId,@@ -44,6 +44,36 @@ const teamId = window.POSTHOG_APP_CONTEXT?.current_team?.id// Distinct prefix from webAnalyticsFilterLogic so bot-tab filters don't collide with the regular tab.const persistConfig = { persist: true, prefix: `${teamId}__bot_` }+// The window pathname carries the /project/:id prefix and may keep a trailing slash (route+// matching strips it, `location.pathname` does not), so normalize before comparing.+const isOnBotsRoute = (): boolean =>+ stripTrailingSlash(removeProjectIdIfPresent(router.values.location.pathname)) === '/web/bots'++// Push the bot tab's filter state into the /web/bots URL. Only writes while the bots route is+// active; never touches the regular Analytics tab URL because `rawBotAnalyticsFilters` lives in+// a separate logic.+const syncBotFiltersToUrl = (+ rawBotAnalyticsFilters: WebAnalyticsPropertyFilters,+ dateFilter: DateFilterState+): void => {+ if (!isOnBotsRoute()) {+ return+ }+ const urlParams = new URLSearchParams(router.values.location.search)+ if (rawBotAnalyticsFilters.length > 0) {+ urlParams.set('filters', JSON.stringify(rawBotAnalyticsFilters))+ } else {+ urlParams.delete('filters')+ }+ // Always write the dates: a stale date param seeded from the current search would otherwise+ // survive and be re-applied by the urlToAction pass this replace triggers.+ const { dateFrom, dateTo, interval } = dateFilter+ urlParams.set('date_from', dateFrom ?? '')+ urlParams.set('date_to', dateTo ?? '')+ urlParams.set('interval', interval ?? '')+ router.actions.replace(`/web/bots${urlParams.toString() ? '?' + urlParams.toString() : ''}`)+}+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface botAnalyticsLogicValues {dateFilter: DateFilterState // webAnalyticsLogic@@ -361,30 +391,27 @@ export const botAnalyticsLogic = kea<botAnalyticsLogicType>([],})),listeners(({ values }) => {- // Push filter changes into the URL. Only writes /web/bots params; never touches the- // regular Analytics tab URL because rawWebAnalyticsFilters lives in a separate logic.- const syncUrl = (): void => {- if (window.location.pathname !== '/web/bots') {- return- }- const urlParams = new URLSearchParams(router.values.location.search)- if (values.rawBotAnalyticsFilters.length > 0) {- urlParams.set('filters', JSON.stringify(values.rawBotAnalyticsFilters))- } else {- urlParams.delete('filters')- }- const { dateFrom, dateTo, interval } = values.dateFilter- if (dateFrom !== INITIAL_DATE_FROM || dateTo !== INITIAL_DATE_TO || interval !== INITIAL_INTERVAL) {- urlParams.set('date_from', dateFrom ?? '')- urlParams.set('date_to', dateTo ?? '')- urlParams.set('interval', interval ?? '')- }- router.actions.replace(`/web/bots${urlParams.toString() ? '?' + urlParams.toString() : ''}`)- }+ const syncUrl = (): void => syncBotFiltersToUrl(values.rawBotAnalyticsFilters, values.dateFilter)return {setBotAnalyticsFilters: syncUrl,toggleBotAnalyticsFilter: syncUrl,clearBotAnalyticsFilters: syncUrl,}}),+ afterMount(({ actions, values }) => {+ if (!isOnBotsRoute()) {+ return+ }+ // Take ownership of the shared `filters` URL param. A param present at mount is a deep+ // link (tab switches scrub it in `buildStateUrl`), so adopt it; otherwise write the+ // persisted bot filters back so the URL matches the displayed results.+ const urlFilters = router.values.searchParams['filters']+ if (isWebAnalyticsPropertyFilters(urlFilters)) {+ if (!objectsEqual(urlFilters, values.rawBotAnalyticsFilters)) {+ actions.setBotAnalyticsFilters(urlFilters)+ }+ } else if (values.rawBotAnalyticsFilters.length > 0 || urlFilters !== undefined) {+ syncBotFiltersToUrl(values.rawBotAnalyticsFilters, values.dateFilter)+ }+ }),])diff --git a/frontend/src/scenes/web-analytics/pagePerformanceLogic.ts b/frontend/src/scenes/web-analytics/pagePerformanceLogic.tsindex 686531ff2c4c..8d97ebc8ae2f 100644--- a/frontend/src/scenes/web-analytics/pagePerformanceLogic.ts+++ b/frontend/src/scenes/web-analytics/pagePerformanceLogic.ts@@ -449,6 +449,11 @@ const pageKeyExpr = (pathExpr: string): string => `concat(coalesce(properties.$hconst pageCandidatesPredicate = (pageKey: string, candidates: string[]): string =>candidates.length > 0 ? `${pageKey} IN (${candidates.map(escapeHogQLString).join(', ')})` : 'false'+/**+ * In the page_durations subquery, `{filters}` matches the carrier event (the NEXT pageview, or the+ * pageleave), not the measured page, so an event property that varies per pageview (e.g. $pathname)+ * can skew avg_time. Session- and person-scoped filters are stable across the pair and stay coherent.+ */export const buildPagePerformanceTableQuery = (window: PagePerformanceWindow,orderBy: PagePerformanceOrderBy,@@ -642,6 +647,7 @@ export interface pagePerformanceLogicValues {dateFilter: DateFilterStatefilterTestAccounts: booleanisPathCleaningEnabled: boolean+ webAnalyticsFilters: WebAnalyticsPropertyFiltersaiSectionQueries: AiSectionQueriesbreakdownModal: PagePerformanceBreakdownState | nullbreakdownQuery: DataTableNode | null@@ -718,12 +724,17 @@ export interface pagePerformanceLogicMeta {) => PagePerformanceWindowpathExpr: (isPathCleaningEnabled: boolean, currentTeam: TeamPublicType | TeamType | null) => stringpreviousPathExpr: (isPathCleaningEnabled: boolean, currentTeam: TeamPublicType | TeamType | null) => string- pageCandidateQuery: (dateFilter: DateFilterState, filterTestAccounts: boolean) => WebStatsTableQuery+ pageCandidateQuery: (+ dateFilter: DateFilterState,+ filterTestAccounts: boolean,+ webAnalyticsFilters: WebAnalyticsPropertyFilters+ ) => WebStatsTableQuerypageTableQuery: (window: PagePerformanceWindow,orderBy: PagePerformanceOrderBy,conversionGoal: WebAnalyticsConversionGoal | null,filterTestAccounts: boolean,+ webAnalyticsFilters: WebAnalyticsPropertyFilters,pathExpr: string,previousPathExpr: string,pageCandidates: string[] | null@@ -732,7 +743,8 @@ export interface pagePerformanceLogicMeta {dateFilter: DateFilterState,filterTestAccounts: boolean,conversionGoal: WebAnalyticsConversionGoal | null,- compareFilter: CompareFilter+ compareFilter: CompareFilter,+ webAnalyticsFilters: WebAnalyticsPropertyFilters) => AiSectionQueriesbucketSize: (window: PagePerformanceWindow) => PagePerformanceBucketoverviewHumanQuery: (@@ -741,12 +753,18 @@ export interface pagePerformanceLogicMeta {bucketSize: PagePerformanceBucket) => stringoverviewCrawlerQuery: (window: PagePerformanceWindow, bucketSize: PagePerformanceBucket) => string- overviewInput: (overviewHumanQuery: string, overviewCrawlerQuery: string, filterTestAccounts: boolean) => string+ overviewInput: (+ overviewHumanQuery: string,+ overviewCrawlerQuery: string,+ filterTestAccounts: boolean,+ webAnalyticsFilters: WebAnalyticsPropertyFilters+ ) => stringcandidatesInput: (pageCandidateQuery: WebStatsTableQuery) => stringbreakdownQuery: (breakdownModal: PagePerformanceBreakdownState | null,window: PagePerformanceWindow,filterTestAccounts: boolean,+ webAnalyticsFilters: WebAnalyticsPropertyFilters,pathExpr: string) => DataTableNode | nullcomparePeriods: (compareFilter: CompareFilter) => boolean@@ -784,6 +802,7 @@ export const pagePerformanceLogic = kea<pagePerformanceLogicType>(['compareFilter','conversionGoal','isPathCleaningEnabled',+ 'webAnalyticsFilters',],teamLogic,['currentTeam'],@@ -896,12 +915,16 @@ export const pagePerformanceLogic = kea<pagePerformanceLogicType>([),],pageCandidateQuery: [- (s) => [s.dateFilter, s.filterTestAccounts],- (dateFilter: DateFilterState, filterTestAccounts: boolean): WebStatsTableQuery => ({+ (s) => [s.dateFilter, s.filterTestAccounts, s.webAnalyticsFilters],+ (+ dateFilter: DateFilterState,+ filterTestAccounts: boolean,+ webAnalyticsFilters: WebAnalyticsPropertyFilters+ ): WebStatsTableQuery => ({kind: NodeKind.WebStatsTableQuery,breakdownBy: WebStatsBreakdown.Page,dateRange: { date_from: dateFilter.dateFrom, date_to: dateFilter.dateTo },- properties: [],+ properties: webAnalyticsFilters,compareFilter: { compare: false },doPathCleaning: false,filterTestAccounts,@@ -918,6 +941,7 @@ export const pagePerformanceLogic = kea<pagePerformanceLogicType>([s.orderBy,s.conversionGoal,s.filterTestAccounts,+ s.webAnalyticsFilters,s.pathExpr,s.previousPathExpr,s.pageCandidates,@@ -927,6 +951,7 @@ export const pagePerformanceLogic = kea<pagePerformanceLogicType>([orderBy: PagePerformanceOrderBy,conversionGoal: WebAnalyticsConversionGoal | null,filterTestAccounts: boolean,+ webAnalyticsFilters: WebAnalyticsPropertyFilters,pathExpr: string,previousPathExpr: string,pageCandidates: string[] | null@@ -942,7 +967,7 @@ export const pagePerformanceLogic = kea<pagePerformanceLogicType>([previousPathExpr,pageCandidates ?? []),- filters: { filterTestAccounts },+ filters: { filterTestAccounts, properties: webAnalyticsFilters },tags: WEB_ANALYTICS_DEFAULT_QUERY_TAGS,},embedded: true,@@ -959,12 +984,13 @@ export const pagePerformanceLogic = kea<pagePerformanceLogicType>([}),],aiSectionQueries: [- (s) => [s.dateFilter, s.filterTestAccounts, s.conversionGoal, s.compareFilter],+ (s) => [s.dateFilter, s.filterTestAccounts, s.conversionGoal, s.compareFilter, s.webAnalyticsFilters],(dateFilter: DateFilterState,filterTestAccounts: boolean,conversionGoal: WebAnalyticsConversionGoal | null,- compareFilter: CompareFilter+ compareFilter: CompareFilter,+ webAnalyticsFilters: WebAnalyticsPropertyFilters): AiSectionQueries => {const dateRange = { date_from: dateFilter.dateFrom, date_to: dateFilter.dateTo }const interval = dateFilter.interval@@ -976,6 +1002,7 @@ export const pagePerformanceLogic = kea<pagePerformanceLogicType>([operator: PropertyOperator.Exact,type: PropertyFilterType.Session,},+ ...webAnalyticsFilters,]const crawlerFilters: WebAnalyticsPropertyFilters = [{@@ -996,6 +1023,7 @@ export const pagePerformanceLogic = kea<pagePerformanceLogicType>([operator: PropertyOperator.Exact,type: PropertyFilterType.Event,},+ ...webAnalyticsFilters,]const referralColumns = [@@ -1132,20 +1160,26 @@ export const pagePerformanceLogic = kea<pagePerformanceLogicType>([buildOverviewCrawlerQuery(window, bucketSize),],overviewInput: [- (s) => [s.overviewHumanQuery, s.overviewCrawlerQuery, s.filterTestAccounts],- (overviewHumanQuery: string, overviewCrawlerQuery: string, filterTestAccounts: boolean): string =>- JSON.stringify([overviewHumanQuery, overviewCrawlerQuery, filterTestAccounts]),+ (s) => [s.overviewHumanQuery, s.overviewCrawlerQuery, s.filterTestAccounts, s.webAnalyticsFilters],+ (+ overviewHumanQuery: string,+ overviewCrawlerQuery: string,+ filterTestAccounts: boolean,+ webAnalyticsFilters: WebAnalyticsPropertyFilters+ ): string =>+ JSON.stringify([overviewHumanQuery, overviewCrawlerQuery, filterTestAccounts, webAnalyticsFilters]),],candidatesInput: [(s) => [s.pageCandidateQuery],(pageCandidateQuery: WebStatsTableQuery): string => JSON.stringify(pageCandidateQuery),],breakdownQuery: [- (s) => [s.breakdownModal, s.window, s.filterTestAccounts, s.pathExpr],+ (s) => [s.breakdownModal, s.window, s.filterTestAccounts, s.webAnalyticsFilters, s.pathExpr],(breakdownModal: PagePerformanceBreakdownState | null,window: PagePerformanceWindow,filterTestAccounts: boolean,+ webAnalyticsFilters: WebAnalyticsPropertyFilters,pathExpr: string): DataTableNode | null => {if (!breakdownModal) {@@ -1160,7 +1194,7 @@ export const pagePerformanceLogic = kea<pagePerformanceLogicType>([source: {kind: NodeKind.HogQLQuery,query,- filters: { filterTestAccounts },+ filters: { filterTestAccounts, properties: webAnalyticsFilters },tags: WEB_ANALYTICS_DEFAULT_QUERY_TAGS,},embedded: true,@@ -1239,7 +1273,10 @@ export const pagePerformanceLogic = kea<pagePerformanceLogicType>([const overviewNode = (query: string): HogQLQuery => ({kind: NodeKind.HogQLQuery,query,- filters: { filterTestAccounts: values.filterTestAccounts },+ filters: {+ filterTestAccounts: values.filterTestAccounts,+ properties: values.webAnalyticsFilters,+ },tags: WEB_ANALYTICS_DEFAULT_QUERY_TAGS,})try {diff --git a/frontend/src/scenes/web-analytics/webAnalyticsLogic.test.ts b/frontend/src/scenes/web-analytics/webAnalyticsLogic.test.tsindex d61a03cc26f9..b9d70dbb4dd4 100644--- a/frontend/src/scenes/web-analytics/webAnalyticsLogic.test.ts+++ b/frontend/src/scenes/web-analytics/webAnalyticsLogic.test.ts@@ -12,6 +12,7 @@ import { userLogic } from 'scenes/userLogic'import { initKeaTests } from '~/test/init'import { PropertyFilterType, PropertyOperator, UserType } from '~/types'+import { botAnalyticsLogic } from './botAnalyticsLogic'import { GraphsTab, ProductTab, TileId } from './common'import { FOCUS_MODE_TILE_IDS } from './focus-mode/focusModeMapping'import { WebAnalyticsConcern, getFocusModeOnboardingSeenKey } from './focus-mode/types'@@ -476,6 +477,19 @@ describe('webAnalyticsLogic URL restoration', () => {expect(router.values.searchParams[key]).toBe(expected)})+ const FILTER_A = {+ type: PropertyFilterType.Session as const,+ key: '$entry_utm_source',+ operator: PropertyOperator.Exact,+ value: ['google'],+ }+ const FILTER_B = {+ type: PropertyFilterType.Session as const,+ key: '$entry_utm_medium',+ operator: PropertyOperator.Exact,+ value: ['cpc'],+ }+it('keeps all page performance controls in the shareable URL', async () => {featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.WEB_ANALYTICS_PAGE_PERFORMANCE], {[FEATURE_FLAGS.WEB_ANALYTICS_PAGE_PERFORMANCE]: true,@@ -486,6 +500,13 @@ describe('webAnalyticsLogic URL restoration', () => {logic.actions.setCompareFilter({ compare: true, compare_to: '-1y' })logic.actions.setIsPathCleaningEnabled(false)logic.actions.setShouldFilterTestAccounts(true)+ logic.actions.setWebAnalyticsFilters([FILTER_A])+ logic.actions.setDomainFilter('https://hedgebox.net')+ logic.actions.setDeviceTypeFilter('Desktop')+ // country and referrer fold into the page-performance queries too, so they must round-trip+ // through the URL or a shared link shows different numbers than the sender saw.+ logic.actions.setCountryFilter('US')+ logic.actions.setReferrerFilter('google.com')await expectLogic(logic).toFinishAllListeners()expect(router.values.location.pathname.endsWith('/web/page-performance')).toBe(true)@@ -496,7 +517,88 @@ describe('webAnalyticsLogic URL restoration', () => {compare_filter: { compare: true, compare_to: '-1y' },path_cleaning: false,filter_test_accounts: true,+ filters: [FILTER_A],+ domain: 'https://hedgebox.net',+ device_type: 'Desktop',+ country: 'US',+ referrer: 'google.com',+ })+ })++ it("scrubs another tab's filters param when switching to the bots tab", async () => {+ featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.WEB_ANALYTICS_BOT_ANALYSIS], {+ [FEATURE_FLAGS.WEB_ANALYTICS_BOT_ANALYSIS]: true,+ })+ logic.actions.setWebAnalyticsFilters([FILTER_A])+ await expectLogic(logic).toFinishAllListeners()+ expect(router.values.searchParams['filters']).toEqual([FILTER_A])++ // The bots content (and so botAnalyticsLogic) has not mounted yet at serialization time.+ logic.actions.setProductTab(ProductTab.BOT_ANALYTICS)+ await expectLogic(logic).toFinishAllListeners()++ expect(router.values.location.pathname.endsWith('/web/bots')).toBe(true)+ expect(router.values.searchParams['filters']).toBeUndefined()+ })++ it('adopts a deep-linked filters param when the bots tab mounts', async () => {+ featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.WEB_ANALYTICS_BOT_ANALYSIS], {+ [FEATURE_FLAGS.WEB_ANALYTICS_BOT_ANALYSIS]: true,})+ router.actions.push('/web/bots', { filters: [FILTER_A] })+ await expectLogic(logic).toFinishAllListeners()++ const botLogic = botAnalyticsLogic()+ botLogic.mount()+ try {+ await expectLogic(botLogic).toFinishAllListeners()+ expect(botLogic.values.rawBotAnalyticsFilters).toEqual([FILTER_A])+ expect(router.values.searchParams['filters']).toEqual([FILTER_A])+ } finally {+ botLogic.unmount()+ }+ })++ it('writes persisted bot filters into the URL when the bots tab mounts', async () => {+ featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.WEB_ANALYTICS_BOT_ANALYSIS], {+ [FEATURE_FLAGS.WEB_ANALYTICS_BOT_ANALYSIS]: true,+ })+ router.actions.push('/web/bots')+ await expectLogic(logic).toFinishAllListeners()++ // First visit sets bot filters (persisted), then the user leaves the tab.+ const botLogic = botAnalyticsLogic()+ botLogic.mount()+ botLogic.actions.setBotAnalyticsFilters([FILTER_B])+ await expectLogic(botLogic).toFinishAllListeners()+ expect(router.values.searchParams['filters']).toEqual([FILTER_B])+ botLogic.unmount()++ // Returning through a bare URL: the mount serializes the persisted filters back.+ router.actions.push('/web/bots')+ await expectLogic(logic).toFinishAllListeners()+ expect(router.values.searchParams['filters']).toBeUndefined()++ const botLogicAgain = botAnalyticsLogic()+ botLogicAgain.mount()+ try {+ await expectLogic(botLogicAgain).toFinishAllListeners()+ expect(router.values.searchParams['filters']).toEqual([FILTER_B])+ } finally {+ botLogicAgain.unmount()+ }+ })++ it('applies property filters from a shared page performance URL', async () => {+ featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.WEB_ANALYTICS_PAGE_PERFORMANCE], {+ [FEATURE_FLAGS.WEB_ANALYTICS_PAGE_PERFORMANCE]: true,+ })++ router.actions.push('/web/page-performance', { filters: [FILTER_A] })+ await expectLogic(logic).toFinishAllListeners()++ expect(logic.values.productTab).toBe(ProductTab.PAGE_PERFORMANCE)+ expect(logic.values.rawWebAnalyticsFilters).toEqual([FILTER_A])})const enableBackNavReset = (): void => {@@ -505,19 +607,6 @@ describe('webAnalyticsLogic URL restoration', () => {})}- const FILTER_A = {- type: PropertyFilterType.Session as const,- key: '$entry_utm_source',- operator: PropertyOperator.Exact,- value: ['google'],- }- const FILTER_B = {- type: PropertyFilterType.Session as const,- key: '$entry_utm_medium',- operator: PropertyOperator.Exact,- value: ['cpc'],- }-it('clears a drilled-in filter when navigating back to a URL without filters (flag on)', async () => {enableBackNavReset()@@ -542,6 +631,34 @@ describe('webAnalyticsLogic URL restoration', () => {expect(logic.values.rawWebAnalyticsFilters).toEqual([FILTER_A])})+ it.each<[string, string, () => unknown]>([+ ['domain', 'example.com', () => logic.values.domainFilter],+ ['device_type', 'Desktop', () => logic.values.deviceTypeFilter],+ ['country', 'US', () => logic.values.countryFilter],+ ['referrer', 'google.com', () => logic.values.referrerFilter],+ ])(+ 'clears a drilled-in %s filter when navigating back to a URL without it (flag on)',+ async (param, value, read) => {+ // These drill-downs fold into the query like `filters` do, so a back-navigation that+ // omits the param must clear the value — otherwise the shown data no longer matches the URL.+ featureFlagLogic.actions.setFeatureFlags(+ [FEATURE_FLAGS.WEB_ANALYTICS_BACK_NAVIGATION_RESET, FEATURE_FLAGS.WEB_ANALYTICS_PAGE_PERFORMANCE],+ {+ [FEATURE_FLAGS.WEB_ANALYTICS_BACK_NAVIGATION_RESET]: true,+ [FEATURE_FLAGS.WEB_ANALYTICS_PAGE_PERFORMANCE]: true,+ }+ )++ router.actions.push('/web/page-performance', { [param]: value })+ await expectLogic(logic).toFinishAllListeners()+ expect(read()).toBe(value)++ router.actions.push('/web/page-performance')+ await expectLogic(logic).toFinishAllListeners()+ expect(read()).toBeNull()+ }+ )+it('leaves a drilled-in filter in place on back-navigation when the flag is off', async () => {router.actions.push('/web', { filters: [FILTER_A] })await expectLogic(logic).toFinishAllListeners()diff --git a/frontend/src/scenes/web-analytics/webAnalyticsLogic.tsx b/frontend/src/scenes/web-analytics/webAnalyticsLogic.tsxindex bf759bd1a667..79b65544c9a5 100644--- a/frontend/src/scenes/web-analytics/webAnalyticsLogic.tsx+++ b/frontend/src/scenes/web-analytics/webAnalyticsLogic.tsx@@ -3090,6 +3090,8 @@ export const webAnalyticsLogic = kea<webAnalyticsLogicType>([webVitalsPercentile,domainFilter,deviceTypeFilter,+ countryFilter,+ referrerFilter,tileVisualizations,includeHostPath,} = values@@ -3106,6 +3108,11 @@ export const webAnalyticsLogic = kea<webAnalyticsLogicType>([const rawBotAnalyticsFilters = botAnalyticsLogic.findMounted()?.values.rawBotAnalyticsFilters ?? []if (rawBotAnalyticsFilters.length > 0) {urlParams.set('filters', JSON.stringify(rawBotAnalyticsFilters))+ } else {+ // A seeded `filters` param belongs to the previous tab; scrub it so a URL restore+ // cannot adopt it as bot filters. The bots URL carries only the bot tab's own+ // filters, which `botAnalyticsLogic` writes back when it mounts.+ urlParams.delete('filters')}if (dateFrom !== INITIAL_DATE_FROM || dateTo !== INITIAL_DATE_TO || interval !== INITIAL_INTERVAL) {urlParams.set('date_from', dateFrom ?? '')@@ -3114,7 +3121,11 @@ export const webAnalyticsLogic = kea<webAnalyticsLogicType>([}return `/web/bots${urlParams.toString() ? '?' + urlParams.toString() : ''}`} else if (productTab === ProductTab.PAGE_PERFORMANCE) {- urlParams.delete('filters')+ if (rawWebAnalyticsFilters.length > 0) {+ urlParams.set('filters', JSON.stringify(rawWebAnalyticsFilters))+ } else {+ urlParams.delete('filters')+ }if (conversionGoal) {if ('actionId' in conversionGoal) {urlParams.set('conversionGoal.actionId', conversionGoal.actionId.toString())@@ -3139,6 +3150,30 @@ export const webAnalyticsLogic = kea<webAnalyticsLogicType>([urlParams.set('path_cleaning', isPathCleaningEnabled.toString())urlParams.set('filter_test_accounts', shouldFilterTestAccounts.toString())urlParams.set('compare_filter', JSON.stringify(rawCompareFilter))+ // The queries consume the merged `webAnalyticsFilters`, which folds these+ // drill-downs in, so a shared URL must carry every one to reproduce the same+ // data. The page-performance tab has no UI to set or clear them, so an+ // unserialized one would apply invisibly and not survive a reload.+ if (domainFilter) {+ urlParams.set('domain', domainFilter)+ } else {+ urlParams.delete('domain')+ }+ if (deviceTypeFilter) {+ urlParams.set('device_type', deviceTypeFilter)+ } else {+ urlParams.delete('device_type')+ }+ if (countryFilter) {+ urlParams.set('country', countryFilter)+ } else {+ urlParams.delete('country')+ }+ if (referrerFilter) {+ urlParams.set('referrer', referrerFilter)+ } else {+ urlParams.delete('referrer')+ }return `/web/page-performance${urlParams.toString() ? '?' + urlParams.toString() : ''}`}@@ -3258,6 +3293,8 @@ export const webAnalyticsLogic = kea<webAnalyticsLogicType>([setShouldFilterTestAccounts: stateToUrl,setDomainFilter: stateToUrl,setDeviceTypeFilter: stateToUrl,+ setCountryFilter: stateToUrl,+ setReferrerFilter: stateToUrl,setTileVisualization: stateToUrl,setIncludeHostPath: stateToUrl,}@@ -3285,6 +3322,8 @@ export const webAnalyticsLogic = kea<webAnalyticsLogicType>([percentile,domain,device_type,+ country,+ referrer,tile_visualizations,include_host_path,}: Record<string, any>,@@ -3338,10 +3377,7 @@ export const webAnalyticsLogic = kea<webAnalyticsLogicType>([if (botLogic && !objectsEqual(nextFilters, botLogic.values.rawBotAnalyticsFilters)) {botLogic.actions.setBotAnalyticsFilters(nextFilters)}- } else if (- productTab !== ProductTab.PAGE_PERFORMANCE &&- !objectsEqual(nextFilters, values.rawWebAnalyticsFilters)- ) {+ } else if (!objectsEqual(nextFilters, values.rawWebAnalyticsFilters)) {actions.setWebAnalyticsFilters(nextFilters)}}@@ -3418,11 +3454,38 @@ export const webAnalyticsLogic = kea<webAnalyticsLogicType>([if (percentile && percentile !== values.webVitalsPercentile) {actions.setWebVitalsPercentile(percentile as WebVitalsPercentile)}+ // Drill-down filters fold into the query the same way `filters` does, so on a+ // back-navigation to a URL that omits one, clear it instead of leaving the newer+ // value applied, because otherwise the shown data can't be reproduced from the URL.if (domain && domain !== values.domainFilter) {actions.setDomainFilter(domain === 'all' ? null : domain)+ } else if (!domain && shouldResetAbsentFilters && tabSerializesFilters && values.domainFilter !== null) {+ actions.setDomainFilter(null)}if (device_type && device_type !== values.deviceTypeFilter) {actions.setDeviceTypeFilter(device_type)+ } else if (+ !device_type &&+ shouldResetAbsentFilters &&+ tabSerializesFilters &&+ values.deviceTypeFilter !== null+ ) {+ actions.setDeviceTypeFilter(null)+ }+ if (country && country !== values.countryFilter) {+ actions.setCountryFilter(country)+ } else if (!country && shouldResetAbsentFilters && tabSerializesFilters && values.countryFilter !== null) {+ actions.setCountryFilter(null)+ }+ if (referrer && referrer !== values.referrerFilter) {+ actions.setReferrerFilter(referrer)+ } else if (+ !referrer &&+ shouldResetAbsentFilters &&+ tabSerializesFilters &&+ values.referrerFilter !== null+ ) {+ actions.setReferrerFilter(null)}if (tile_visualizations && !objectsEqual(tile_visualizations, values.tileVisualizations)) {for (const [tileId, visualization] of Object.entries(tile_visualizations)) {