: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): use livestream-cleaned pathnames in the live view (#87295)
Lucas Ricoy593e34c48f2a
diff --git a/frontend/src/scenes/web-analytics/LiveMetricsDashboard/liveWebAnalyticsMetricsLogic.test.ts b/frontend/src/scenes/web-analytics/LiveMetricsDashboard/liveWebAnalyticsMetricsLogic.test.tsindex 9d533750b566..e3bc1d477bff 100644--- a/frontend/src/scenes/web-analytics/LiveMetricsDashboard/liveWebAnalyticsMetricsLogic.test.ts+++ b/frontend/src/scenes/web-analytics/LiveMetricsDashboard/liveWebAnalyticsMetricsLogic.test.ts@@ -71,6 +71,17 @@ describe('liveWebAnalyticsMetricsLogic', () => {expect(logic.values.topPaths).toEqual([{ path: '/classes/:id', views: 2 }])})+ it('prefers the livestream-cleaned pathname over the client-side mirror', () => {+ const event = pageview('/classes/928q3hr9paw8hfe', 'user-1')+ // Server-side RE2 cleaning can diverge from the JS mirror (e.g. re2-only+ // syntax the mirror skips), so its value must win verbatim.+ event.properties.$virt_cleaned_pathname = '/classes/:server_id'++ logic.actions.addEvents([event], new Date(Date.now() - 60_000), logic.values.pathCleaningFilters)++ expect(logic.values.topPaths).toEqual([{ path: '/classes/:server_id', views: 1 }])+ })+it('leaves streamed paths untouched once path cleaning is switched off', () => {webAnalyticsLogic.actions.setIsPathCleaningEnabled(false)diff --git a/frontend/src/scenes/web-analytics/LiveMetricsDashboard/liveWebAnalyticsMetricsLogic.tsx b/frontend/src/scenes/web-analytics/LiveMetricsDashboard/liveWebAnalyticsMetricsLogic.tsxindex 7866bbf1880a..3fd3274205ac 100644--- a/frontend/src/scenes/web-analytics/LiveMetricsDashboard/liveWebAnalyticsMetricsLogic.tsx+++ b/frontend/src/scenes/web-analytics/LiveMetricsDashboard/liveWebAnalyticsMetricsLogic.tsx@@ -368,13 +368,17 @@ export const liveWebAnalyticsMetricsLogic = kea<liveWebAnalyticsMetricsLogicTypeconst newerThanTs = newerThan.getTime() / 1000if (eventTs > newerThanTs) {- // Streamed events arrive raw, so the same cleaning the backfill query- // does server-side has to happen here for both to land on one key.+ // Prefer the livestream service's RE2-cleaned pathname — it matches the+ // backfill query exactly. The client-side mirror stays as a fallback for+ // livestream deploys that don't send it yet.const rawPathname = event.properties?.$pathname+ const serverCleanedPathname = event.properties?.$virt_cleaned_pathnameconst pathname =- typeof rawPathname === 'string'- ? applyPathCleaning(rawPathname, pathCleaningFilters)- : rawPathname+ typeof serverCleanedPathname === 'string'+ ? serverCleanedPathname+ : typeof rawPathname === 'string'+ ? applyPathCleaning(rawPathname, pathCleaningFilters)+ : rawPathnameconst deviceType = event.properties?.$device_typeconst deviceId = event.properties?.$device_idconst browser = event.properties?.$browser@@ -863,6 +867,11 @@ export const liveWebAnalyticsMetricsLogic = kea<liveWebAnalyticsMetricsLogicTypeconst recordingColumn = values.currentTeam?.session_recording_opt_in ? ',$session_id' : ''url.searchParams.append('columns', `${baseColumns}${cityColumns}${recordingColumn}`)appendFilterParams(url, values.streamFilters)+ if (values.pathCleaningFilters.length > 0) {+ // The livestream service cleans server-side with RE2 (the engine the backfill+ // query uses) and returns $virt_cleaned_pathname alongside the raw value.+ url.searchParams.append('pathCleaning', JSON.stringify(values.pathCleaningFilters))+ }cache.batch = cache.batch ?? ([] as LiveEvent[])