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): propagate dashboard filters to view recordings button (#60934)

Lucas Ricoy52663cbf06d1
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 87ae41526557..63bdea8f9d86 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -4403,9 +4403,9 @@ snapshots:
scenes-app-dashboards-templates-dashboard-template-copy--no-other-projects-in-organization--light:
hash: v1.k794b7964.8d4cd29cef2f26f584fb54d8b66c4876ae47ad47c2c66d64df84e5fd39729a1b.07RDbDS_E-gMcaMuHJ_R9xJQB3iSqPEFC3Evki06JKs
scenes-app-dashboards-templates-dashboard-template-item--all-versions--dark:
- hash: v1.k794b7964.f47171fd3ca31f74f12783eac03ef4dddd84ab59769d40de18ce85b0c24cfe3e.UapVhkghncNi81EDuobiEF6EnA6oDSC01C_ouOTxcuA
+ hash: v1.k794b7964.4fb489304c84134a85749b57df28d4ab1ec04d0e4218f8229c65f6fc2b56efe9.5r8gld7ZuYKOnJ_tfKMqimkp38WuT4PEiT_r6_i46H8
scenes-app-dashboards-templates-dashboard-template-item--all-versions--light:
- hash: v1.k794b7964.3661db884a93ce65e73415cd3241934119aac05e244b0b995d02b21a669bdc9c.dhQXLuzR19s0SIdWt9F7Nf9oBV7SZvsuvMxLcC6l4us
+ hash: v1.k794b7964.681b8a0d65c6bcffb7c86c7f28b9812b004926d8f5c3f302e39d74e48854a7da.GiBOvxkJEoXB1AZ0LCLev0EHtOeEqg7Bf9aARWOiHlM
scenes-app-dashboards-templates-dashboard-templates-table--default--dark:
hash: v1.k794b7964.7b8c11e870dd934ca9c12b69fa9b60f4c7d9fcd09392822e1ece9de4b948eeae.NRtn-3-xRm0smr_2RAFLAMnWFiwzhOBCXjC_bVZL23E
scenes-app-dashboards-templates-dashboard-templates-table--default--light:
diff --git a/frontend/src/scenes/web-analytics/CrossSellButtons/ReplayButton.tsx b/frontend/src/scenes/web-analytics/CrossSellButtons/ReplayButton.tsx
index e696d4ca993c..a42fc570cc08 100644
--- a/frontend/src/scenes/web-analytics/CrossSellButtons/ReplayButton.tsx
+++ b/frontend/src/scenes/web-analytics/CrossSellButtons/ReplayButton.tsx
@@ -2,13 +2,19 @@ import ViewRecordingsPlaylistButton from 'lib/components/ViewRecordingButton/Vie
import { addProductIntentForCrossSell } from 'lib/utils/product-intents'
import { BREAKDOWN_NULL_DISPLAY } from 'scenes/web-analytics/common'
-import { ProductIntentContext, ProductKey, WebStatsBreakdown } from '~/queries/schema/schema-general'
+import {
+ ProductIntentContext,
+ ProductKey,
+ WebAnalyticsPropertyFilters,
+ WebStatsBreakdown,
+} from '~/queries/schema/schema-general'
import {
AnyPropertyFilter,
FilterLogicalOperator,
PropertyFilterType,
PropertyOperator,
RecordingUniversalFilters,
+ UniversalFiltersGroupValue,
} from '~/types'
/**
@@ -89,9 +95,49 @@ interface ReplayButtonProps {
date_to: string
breakdownBy: WebStatsBreakdown
value: string
+ /** Dashboard-level filters applied to the source web analytics query. Must be forwarded so the
+ * recordings page narrows down to the same population the row count reflects. */
+ properties?: WebAnalyticsPropertyFilters
+ /** 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
}
-export const ReplayButton = ({ date_from, date_to, breakdownBy, value }: ReplayButtonProps): JSX.Element => {
+export const ReplayButton = ({
+ date_from,
+ date_to,
+ breakdownBy,
+ value,
+ properties,
+ filter_test_accounts,
+}: ReplayButtonProps): JSX.Element => {
+ const extraFilters: UniversalFiltersGroupValue[] = (properties ?? []) as UniversalFiltersGroupValue[]
+
+ /** Compose the recordings filter from the per-breakdown property filters plus the dashboard-level
+ * `properties` and `filter_test_accounts` that every branch needs to forward. */
+ const buildFilters = (breakdownValues: UniversalFiltersGroupValue[]): Partial<RecordingUniversalFilters> => {
+ const innerValues = [...breakdownValues, ...extraFilters]
+ return {
+ date_from,
+ date_to,
+ filter_test_accounts,
+ ...(innerValues.length
+ ? {
+ filter_group: {
+ type: FilterLogicalOperator.And,
+ values: [{ type: FilterLogicalOperator.And, values: innerValues }],
+ },
+ }
+ : {}),
+ }
+ }
+
+ const renderButton = (filters: Partial<RecordingUniversalFilters>): JSX.Element => (
+ <div onClick={handleClick}>
+ <ViewRecordingsPlaylistButton filters={filters} type="tertiary" size="xsmall" />
+ </div>
+ )
+
const handleClick = (e: React.MouseEvent): void => {
e.stopPropagation()
void addProductIntentForCrossSell({
@@ -101,120 +147,68 @@ export const ReplayButton = ({ date_from, date_to, breakdownBy, value }: ReplayB
})
}
- /** If value is empty - just open session replay home page */
+ /** If value is empty - just open session replay home page, but still forward dashboard
+ * filters so the recordings list isn't wider than what the user is looking at. */
if (value === '') {
- const filters: Partial<RecordingUniversalFilters> = {
- date_from,
- date_to,
- }
- return (
- <div onClick={handleClick}>
- <ViewRecordingsPlaylistButton filters={filters} type="tertiary" size="xsmall" />
- </div>
- )
+ return renderButton(buildFilters([]))
}
/** View port is a unique case, so we need to handle it differently */
if (breakdownBy === WebStatsBreakdown.Viewport) {
- const filters: Partial<RecordingUniversalFilters> = {
- date_from,
- date_to,
- filter_group: {
- type: FilterLogicalOperator.And,
- values: [
- {
- type: FilterLogicalOperator.And,
- values: [
- {
- key: '$viewport_width',
- type: PropertyFilterType.Event,
- value: [value[0]],
- operator: PropertyOperator.Exact,
- },
- {
- key: '$viewport_height',
- type: PropertyFilterType.Event,
- value: [value[1]],
- operator: PropertyOperator.Exact,
- },
- ],
- },
- ],
- },
- }
- return (
- <div onClick={handleClick}>
- <ViewRecordingsPlaylistButton filters={filters} type="tertiary" size="xsmall" />
- </div>
+ return renderButton(
+ buildFilters([
+ {
+ key: '$viewport_width',
+ type: PropertyFilterType.Event,
+ value: [value[0]],
+ operator: PropertyOperator.Exact,
+ },
+ {
+ key: '$viewport_height',
+ type: PropertyFilterType.Event,
+ value: [value[1]],
+ operator: PropertyOperator.Exact,
+ },
+ ])
)
}
/** UTM source, medium, campaign is a unique case, so we need to handle it differently, as combining them with AND */
if (breakdownBy === WebStatsBreakdown.InitialUTMSourceMediumCampaign) {
const values = value.split(' / ')
- const filters: Partial<RecordingUniversalFilters> = {
- date_from,
- date_to,
- filter_group: {
- type: FilterLogicalOperator.And,
- values: [
- {
- type: FilterLogicalOperator.And,
- values: [
- buildBreakdownPropertyFilter(
- '$entry_utm_source',
- PropertyFilterType.Session,
- values[0] ?? BREAKDOWN_NULL_DISPLAY
- ),
- buildBreakdownPropertyFilter(
- '$entry_utm_medium',
- PropertyFilterType.Session,
- values[1] ?? BREAKDOWN_NULL_DISPLAY
- ),
- buildBreakdownPropertyFilter(
- '$entry_utm_campaign',
- PropertyFilterType.Session,
- values[2] ?? BREAKDOWN_NULL_DISPLAY
- ),
- ],
- },
- ],
- },
- }
- return (
- <div onClick={handleClick}>
- <ViewRecordingsPlaylistButton filters={filters} type="tertiary" size="xsmall" />
- </div>
+ return renderButton(
+ buildFilters([
+ buildBreakdownPropertyFilter(
+ '$entry_utm_source',
+ PropertyFilterType.Session,
+ values[0] ?? BREAKDOWN_NULL_DISPLAY
+ ),
+ buildBreakdownPropertyFilter(
+ '$entry_utm_medium',
+ PropertyFilterType.Session,
+ values[1] ?? BREAKDOWN_NULL_DISPLAY
+ ),
+ buildBreakdownPropertyFilter(
+ '$entry_utm_campaign',
+ PropertyFilterType.Session,
+ values[2] ?? BREAKDOWN_NULL_DISPLAY
+ ),
+ ])
)
}
/** Referring URL is displayed with query params stripped, so use regex to match the raw value */
if (breakdownBy === WebStatsBreakdown.InitialReferringURL) {
const escapedValue = value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
- const filters: Partial<RecordingUniversalFilters> = {
- date_from,
- date_to,
- filter_group: {
- type: FilterLogicalOperator.And,
- values: [
- {
- type: FilterLogicalOperator.And,
- values: [
- {
- key: '$session_entry_referrer',
- type: PropertyFilterType.Event,
- value: [`^${escapedValue}($|\\?|#)`],
- operator: PropertyOperator.Regex,
- },
- ],
- },
- ],
- },
- }
- return (
- <div onClick={handleClick}>
- <ViewRecordingsPlaylistButton filters={filters} type="tertiary" size="xsmall" />
- </div>
+ return renderButton(
+ buildFilters([
+ {
+ key: '$session_entry_referrer',
+ type: PropertyFilterType.Event,
+ value: [`^${escapedValue}($|\\?|#)`],
+ operator: PropertyOperator.Regex,
+ },
+ ])
)
}
@@ -225,23 +219,5 @@ export const ReplayButton = ({ date_from, date_to, breakdownBy, value }: ReplayB
return <></>
}
- /** Render the button */
- const filters: Partial<RecordingUniversalFilters> = {
- date_from,
- date_to,
- filter_group: {
- type: FilterLogicalOperator.And,
- values: [
- {
- type: FilterLogicalOperator.And,
- values: [buildBreakdownPropertyFilter(key, type, value)],
- },
- ],
- },
- }
- return (
- <div onClick={handleClick}>
- <ViewRecordingsPlaylistButton filters={filters} type="tertiary" size="xsmall" />
- </div>
- )
+ return renderButton(buildFilters([buildBreakdownPropertyFilter(key, type, value)]))
}
diff --git a/frontend/src/scenes/web-analytics/tiles/WebAnalyticsTile.tsx b/frontend/src/scenes/web-analytics/tiles/WebAnalyticsTile.tsx
index 8bb6cd755e47..a3947de9d9fe 100644
--- a/frontend/src/scenes/web-analytics/tiles/WebAnalyticsTile.tsx
+++ b/frontend/src/scenes/web-analytics/tiles/WebAnalyticsTile.tsx
@@ -611,8 +611,9 @@ export const webAnalyticsDataTableQueryContext: QueryContext = {
cross_sell: {
title: ' ',
render: ({ record, query }: { record: any; query: DataTableNode | DataVisualizationNode }) => {
- const dateRange = (query.source as any)?.dateRange
- const breakdownBy = (query.source as any)?.breakdownBy
+ const source = query.source as any
+ const dateRange = source?.dateRange
+ const breakdownBy = source?.breakdownBy
const value = record[0] ?? ''
return (
@@ -622,6 +623,8 @@ export const webAnalyticsDataTableQueryContext: QueryContext = {
date_to={dateRange?.date_to}
breakdownBy={breakdownBy}
value={value}
+ properties={source?.properties}
+ filter_test_accounts={source?.filterTestAccounts}
/>
<HeatmapButton breakdownBy={breakdownBy} value={value} />
<ErrorTrackingButton breakdownBy={breakdownBy} value={value} />