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(web-analytics): make the error tracking and replay click-throughs match (#80747)

Lucas Ricoyef99d4279325
diff --git a/frontend/src/scenes/web-analytics/CrossSellButtons/ErrorTrackingButton.tsx b/frontend/src/scenes/web-analytics/CrossSellButtons/ErrorTrackingButton.tsx
index 9857467629a3..ac18cb7d87f2 100644
--- a/frontend/src/scenes/web-analytics/CrossSellButtons/ErrorTrackingButton.tsx
+++ b/frontend/src/scenes/web-analytics/CrossSellButtons/ErrorTrackingButton.tsx
@@ -3,16 +3,19 @@ import { LemonButton } from '@posthog/lemon-ui'
import { addProductIntentForCrossSell } from 'lib/utils/product-intents'
import { urls } from 'scenes/urls'
+import { exactMatchOperatorFor } from 'scenes/web-analytics/common'
import { ProductIntentContext, ProductKey, WebStatsBreakdown } from '~/queries/schema/schema-general'
-import { FilterLogicalOperator, PropertyFilterType, PropertyOperator } from '~/types'
+import { FilterLogicalOperator, PropertyFilterType } from '~/types'
interface ErrorTrackingButtonProps {
breakdownBy: WebStatsBreakdown
value: string
+ /** Web analytics can clean paths; error tracking can't, so the operator has to clean both sides. */
+ doPathCleaning?: boolean
}
-export const ErrorTrackingButton = ({ breakdownBy, value }: ErrorTrackingButtonProps): JSX.Element => {
+export const ErrorTrackingButton = ({ breakdownBy, value, doPathCleaning }: ErrorTrackingButtonProps): JSX.Element => {
// Only show for FrustrationMetrics or Page breakdowns
if (breakdownBy !== WebStatsBreakdown.FrustrationMetrics && breakdownBy !== WebStatsBreakdown.Page) {
return <></>
@@ -24,6 +27,8 @@ export const ErrorTrackingButton = ({ breakdownBy, value }: ErrorTrackingButtonP
return (
<LemonButton
+ // Both supported breakdowns are built on `$pathname`, so `value` is a bare path such as
+ // `/pricing`. Matching it against `$current_url` never hits, as that holds the absolute URL.
to={urls.errorTracking({
filterGroup: {
type: FilterLogicalOperator.And,
@@ -32,9 +37,13 @@ export const ErrorTrackingButton = ({ breakdownBy, value }: ErrorTrackingButtonP
type: FilterLogicalOperator.And,
values: [
{
- key: '$current_url',
+ key: '$pathname',
value: [value],
- operator: PropertyOperator.Exact,
+ operator: exactMatchOperatorFor(
+ '$pathname',
+ PropertyFilterType.Event,
+ doPathCleaning
+ ),
type: PropertyFilterType.Event,
},
],
diff --git a/frontend/src/scenes/web-analytics/CrossSellButtons/ReplayButton.tsx b/frontend/src/scenes/web-analytics/CrossSellButtons/ReplayButton.tsx
index 5bc5ea2c298f..b7499709922c 100644
--- a/frontend/src/scenes/web-analytics/CrossSellButtons/ReplayButton.tsx
+++ b/frontend/src/scenes/web-analytics/CrossSellButtons/ReplayButton.tsx
@@ -3,7 +3,7 @@ import posthog from 'posthog-js'
import ViewRecordingsPlaylistButton from 'lib/components/ViewRecordingButton/ViewRecordingsPlaylistButton'
import { addProductIntentForCrossSell } from 'lib/utils/product-intents'
import { webAnalyticsAchievementsLogic } from 'scenes/web-analytics/achievements/webAnalyticsAchievementsLogic'
-import { BREAKDOWN_NULL_DISPLAY } from 'scenes/web-analytics/common'
+import { BREAKDOWN_NULL_DISPLAY, exactMatchOperatorFor } from 'scenes/web-analytics/common'
import {
ProductIntentContext,
@@ -26,12 +26,14 @@ import { InteractionKindEnumApi } from 'products/web_analytics/frontend/generate
* Build a property filter for a breakdown value. When the value is the
* BREAKDOWN_NULL_DISPLAY placeholder ("(none)"), the property isn't literally
* set to "(none)" — it just isn't set — so use IsNotSet instead of an exact
- * match.
+ * match. Otherwise `exactMatchOperatorFor` decides which exact match handles a
+ * path-cleaned value.
*/
const buildBreakdownPropertyFilter = (
key: string,
type: PropertyFilterType.Event | PropertyFilterType.Session | PropertyFilterType.Person,
- value: string
+ value: string,
+ doPathCleaning?: boolean
): AnyPropertyFilter => {
if (value === BREAKDOWN_NULL_DISPLAY) {
return {
@@ -45,7 +47,7 @@ const buildBreakdownPropertyFilter = (
key,
type,
value: [value],
- operator: PropertyOperator.Exact,
+ operator: exactMatchOperatorFor(key, type, doPathCleaning),
} as AnyPropertyFilter
}
@@ -106,6 +108,8 @@ interface ReplayButtonProps {
/** Web analytics filters test accounts by default; session replay doesn't. Forward it so the
* recordings page matches the row count. */
filter_test_accounts?: boolean
+ /** Web analytics can clean paths; session replay can't, so the operator has to clean both sides. */
+ doPathCleaning?: boolean
}
export const ReplayButton = ({
@@ -115,6 +119,7 @@ export const ReplayButton = ({
value,
properties,
filter_test_accounts,
+ doPathCleaning,
}: ReplayButtonProps): JSX.Element => {
const extraFilters: UniversalFiltersGroupValue[] = (properties ?? []) as UniversalFiltersGroupValue[]
@@ -231,5 +236,5 @@ export const ReplayButton = ({
return <></>
}
- return renderButton(buildFilters([buildBreakdownPropertyFilter(key, type, value)]))
+ return renderButton(buildFilters([buildBreakdownPropertyFilter(key, type, value, doPathCleaning)]))
}
diff --git a/frontend/src/scenes/web-analytics/common.test.ts b/frontend/src/scenes/web-analytics/common.test.ts
new file mode 100644
index 000000000000..8145c9fc4cb0
--- /dev/null
+++ b/frontend/src/scenes/web-analytics/common.test.ts
@@ -0,0 +1,16 @@
+import { PropertyFilterType, PropertyOperator } from '~/types'
+
+import { exactMatchOperatorFor } from './common'
+
+describe('exactMatchOperatorFor', () => {
+ it.each([
+ ['$pathname', PropertyFilterType.Event, false, PropertyOperator.Exact],
+ ['$pathname', PropertyFilterType.Event, true, PropertyOperator.IsCleanedPathExact],
+ ['$entry_pathname', PropertyFilterType.Session, true, PropertyOperator.IsCleanedPathExact],
+ ['$initial_pathname', PropertyFilterType.Person, true, PropertyOperator.IsCleanedPathExact],
+ ['$browser', PropertyFilterType.Event, true, PropertyOperator.Exact],
+ ['$entry_utm_source', PropertyFilterType.Session, true, PropertyOperator.Exact],
+ ])('%s (%s, cleaning: %s) uses %s', (key, type, doPathCleaning, expected) => {
+ expect(exactMatchOperatorFor(key, type, doPathCleaning)).toBe(expected)
+ })
+})
diff --git a/frontend/src/scenes/web-analytics/common.ts b/frontend/src/scenes/web-analytics/common.ts
index 525d33cc85d0..ac46a5a94c84 100644
--- a/frontend/src/scenes/web-analytics/common.ts
+++ b/frontend/src/scenes/web-analytics/common.ts
@@ -17,7 +17,7 @@ import {
WebStatsBreakdown,
} from '~/queries/schema/schema-general'
import { hogql } from '~/queries/utils'
-import { InsightLogicProps, PropertyFilterType, PropertyMathType } from '~/types'
+import { InsightLogicProps, PropertyFilterType, PropertyMathType, PropertyOperator } from '~/types'
/** Matches BREAKDOWN_NULL_DISPLAY in posthog/hogql_queries/web_analytics/stats_table.py */
export const BREAKDOWN_NULL_DISPLAY = '(none)'
@@ -566,6 +566,30 @@ export const sessionPropertiesToPathClean = new Set([
])
export const personPropertiesToPathClean = new Set(['$initial_pathname', '$initial_current_url'])
+/**
+ * Pick the operator for an exact match on a breakdown value. With path cleaning on, the value is a
+ * cleaned path such as `/user/:id`, which no raw property equals. `IsCleanedPathExact` cleans the
+ * stored property too, so the comparison happens on cleaned paths on both sides.
+ */
+export const exactMatchOperatorFor = (
+ key: string,
+ type: PropertyFilterType,
+ doPathCleaning: boolean | undefined
+): PropertyOperator => {
+ if (!doPathCleaning) {
+ return PropertyOperator.Exact
+ }
+
+ const cleanableProperties =
+ type === PropertyFilterType.Session
+ ? sessionPropertiesToPathClean
+ : type === PropertyFilterType.Person
+ ? personPropertiesToPathClean
+ : eventPropertiesToPathClean
+
+ return cleanableProperties.has(key) ? PropertyOperator.IsCleanedPathExact : PropertyOperator.Exact
+}
+
// Utility function to map SQL/internal column names to UI-friendly display names
export const getDisplayColumnName = (column: string, breakdownBy?: WebStatsBreakdown): string => {
// Strip the "context.columns." prefix if present
diff --git a/frontend/src/scenes/web-analytics/tiles/WebAnalyticsTile.tsx b/frontend/src/scenes/web-analytics/tiles/WebAnalyticsTile.tsx
index aa711fbcc7ac..388d0181ff3c 100644
--- a/frontend/src/scenes/web-analytics/tiles/WebAnalyticsTile.tsx
+++ b/frontend/src/scenes/web-analytics/tiles/WebAnalyticsTile.tsx
@@ -676,6 +676,7 @@ export const webAnalyticsDataTableQueryContext: QueryContext = {
const dateRange = source?.dateRange
const breakdownBy = source?.breakdownBy
const value = record[0] ?? ''
+ const doPathCleaning = source?.doPathCleaning
return (
<div className="flex flex-row items-center justify-end">
@@ -686,9 +687,10 @@ export const webAnalyticsDataTableQueryContext: QueryContext = {
value={value}
properties={source?.properties}
filter_test_accounts={source?.filterTestAccounts}
+ doPathCleaning={doPathCleaning}
/>
<HeatmapButton breakdownBy={breakdownBy} value={value} />
- <ErrorTrackingButton breakdownBy={breakdownBy} value={value} />
+ <ErrorTrackingButton breakdownBy={breakdownBy} value={value} doPathCleaning={doPathCleaning} />
<CreateSurveyButton value={value} />
</div>
)