: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
chore(web-analytics): Move Web Analytics Live Filters under same feature flag (#58288)
Jordan Mryyanc418c9b2ae0b
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsxindex 43d61d1dac84..5d5892ff1c7d 100644--- a/frontend/src/lib/constants.tsx+++ b/frontend/src/lib/constants.tsx@@ -491,7 +491,6 @@ export const FEATURE_FLAGS = {WEB_ANALYTICS_HEALTH_TAB: 'web_analytics_health_tab', // owner: @jordanm-posthog #team-web-analyticsWEB_ANALYTICS_INCLUDE_HOST: 'web-analytics-include-host', // owner: @lricoy #team-web-analyticsWEB_ANALYTICS_LIVE_CITY_BREAKDOWN: 'web-analytics-live-city-breakdown', // owner: @jordanm-posthog #team-web-analytics- WEB_ANALYTICS_LIVE_DOMAIN_FILTER: 'web-analytics-live-domain-filter', // owner: @jordanm-posthog #team-web-analyticsWEB_ANALYTICS_LIVE_EDIT_LAYOUT: 'web-analytics-live-edit-layout', // owner: @jordanm-posthog #team-web-analyticsWEB_ANALYTICS_LIVE_FILTERS: 'web-analytics-live-filters', // owner: @jordanm-posthog #team-web-analyticsWEB_ANALYTICS_LIVE_MAP: 'web-analytics-live-map', // owner: @jordanm-posthog #team-web-analyticsdiff --git a/frontend/src/scenes/web-analytics/LiveMetricsDashboard/LiveWebAnalyticsMetrics.tsx b/frontend/src/scenes/web-analytics/LiveMetricsDashboard/LiveWebAnalyticsMetrics.tsxindex 158ee05b0dfa..3a7085939e15 100644--- a/frontend/src/scenes/web-analytics/LiveMetricsDashboard/LiveWebAnalyticsMetrics.tsx+++ b/frontend/src/scenes/web-analytics/LiveMetricsDashboard/LiveWebAnalyticsMetrics.tsx@@ -77,28 +77,19 @@ const LiveDashboardFilterRow = (): JSX.Element | null => {const { countryFilter, referrerFilter, deviceTypeFilter, validatedDomainFilter } = useValues(webAnalyticsLogic)const { setCountryFilter, setReferrerFilter, setDeviceTypeFilter, setDomainFilter } = useActions(webAnalyticsLogic)- const showDomainFilter = !!featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_LIVE_DOMAIN_FILTER]const showLiveFilters = !!featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_LIVE_FILTERS]- if (!showDomainFilter && !showLiveFilters) {- return null- }-if (!showLiveFilters) {- return (- <div className="mb-4">- <WebAnalyticsDomainSelector />- </div>- )+ return null}const referrerSuggestions = topReferrers.map((r: { referrer: string }) => r.referrer).filter(Boolean)- const hasDomainFilter = showDomainFilter && !!validatedDomainFilter && validatedDomainFilter !== 'all'+ const hasDomainFilter = !!validatedDomainFilter && validatedDomainFilter !== 'all'const hasFilters = !!(countryFilter || referrerFilter || deviceTypeFilter || hasDomainFilter)return (<div className="mb-4 flex flex-wrap items-center gap-2">- {showDomainFilter && <WebAnalyticsDomainSelector />}+ <WebAnalyticsDomainSelector /><WebAnalyticsLiveCountrySelector /><WebAnalyticsLiveDeviceToggle /><WebAnalyticsLiveReferrerSelector suggestions={referrerSuggestions} />diff --git a/frontend/src/scenes/web-analytics/LiveMetricsDashboard/liveWebAnalyticsMetricsLogic.tsx b/frontend/src/scenes/web-analytics/LiveMetricsDashboard/liveWebAnalyticsMetricsLogic.tsxindex dc62d4fbf8db..ba18fc991498 100644--- a/frontend/src/scenes/web-analytics/LiveMetricsDashboard/liveWebAnalyticsMetricsLogic.tsx+++ b/frontend/src/scenes/web-analytics/LiveMetricsDashboard/liveWebAnalyticsMetricsLogic.tsx@@ -374,7 +374,7 @@ export const liveWebAnalyticsMetricsLogic = kea<liveWebAnalyticsMetricsLogicTypeif (productTab === ProductTab.BOT_ANALYTICS) {return null}- return featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_LIVE_DOMAIN_FILTER] ? rawSelectedHost : null+ return featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_LIVE_FILTERS] ? rawSelectedHost : null},],liveFilters: [@@ -383,13 +383,7 @@ export const liveWebAnalyticsMetricsLogic = kea<liveWebAnalyticsMetricsLogicTyperawLiveFilters: WebAnalyticsPropertyFilter[],featureFlags: FeatureFlagsSet): WebAnalyticsPropertyFilter[] => {- if (featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_LIVE_FILTERS]) {- return rawLiveFilters- }- if (featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_LIVE_DOMAIN_FILTER]) {- return rawLiveFilters.filter((f) => f.key === '$host')- }- return []+ return featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_LIVE_FILTERS] ? rawLiveFilters : []},],hasActiveFilters: [@@ -449,12 +443,13 @@ export const liveWebAnalyticsMetricsLogic = kea<liveWebAnalyticsMetricsLogicTyperecentUsersResponse,botResponse,cityResponse,- ] = await loadQueryData(+ ] = await loadQueryData({dateFrom,- handoff,- values.liveFilters,- !!values.featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_LIVE_CITY_BREAKDOWN]- )+ dateTo: handoff,+ filters: values.liveFilters,+ includeCity: !!values.featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_LIVE_CITY_BREAKDOWN],+ filtersEnabled: !!values.featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_LIVE_FILTERS],+ })const bucketMap = new Map<number, SlidingWindowBucket>()@@ -672,12 +667,19 @@ const startFlushInterval = (cache: FlushCache, actions: FlushActions): void => {}, FLUSH_INTERVAL_MS)}-const loadQueryData = async (- dateFrom: Date,- dateTo: Date,- filters: WebAnalyticsPropertyFilter[],+const loadQueryData = async ({+ dateFrom,+ dateTo,+ filters,+ includeCity,+ filtersEnabled,+}: {+ dateFrom: Date+ dateTo: Date+ filters: WebAnalyticsPropertyFilter[]includeCity: boolean-): Promise<+ filtersEnabled: boolean+}): Promise<[HogQLQueryResponse,HogQLQueryResponse,@@ -690,12 +692,17 @@ const loadQueryData = async (HogQLQueryResponse | null,]> => {- // The {filters} placeholder is expanded by HogQL into the property + date predicates.- // See HogQLFilters in queries/schema/schema-general.ts.- const hogQLFilters = {- properties: filters,- dateRange: { date_from: dateFrom.toISOString(), date_to: dateTo.toISOString() },- }+ const whereClause = filtersEnabled+ ? '{filters}'+ : 'timestamp >= toDateTime({dateFrom}) AND timestamp <= toDateTime({dateTo})'+ const queryParams: Pick<HogQLQuery, 'values' | 'filters'> = filtersEnabled+ ? {+ filters: {+ properties: filters,+ dateRange: { date_from: dateFrom.toISOString(), date_to: dateTo.toISOString() },+ },+ }+ : { values: { dateFrom: dateFrom.toISOString(), dateTo: dateTo.toISOString() } }const botEligibleEventsTuple = `(${BOT_ELIGIBLE_EVENTS.map((e) => `'${e}'`).join(', ')})`@@ -707,12 +714,12 @@ const loadQueryData = async (countIf(event = '$pageview') AS pageviews,countIf(event IN ${botEligibleEventsTuple}) AS bot_eligible_eventsFROM events- WHERE {filters}+ WHERE ${whereClause}GROUP BYminute_bucketORDER BYminute_bucket ASC`,- filters: hogQLFilters,+ ...queryParams,}const createBreakdownQuery = (property: string, alias: string): HogQLQuery => ({@@ -741,7 +748,7 @@ const loadQueryData = async ())) AS device_idsFROM events- WHERE {filters}+ WHERE ${whereClause}GROUP BYminute_bucket,${alias}@@ -750,7 +757,7 @@ const loadQueryData = async (minute_bucketORDER BYminute_bucket ASC`,- filters: hogQLFilters,+ ...queryParams,})const deviceQuery = createBreakdownQuery('$device_type', 'device_type')@@ -770,7 +777,7 @@ const loadQueryData = async (date_from: dateFrom.toISOString(),date_to: dateTo.toISOString(),},- properties: filters,+ properties: filtersEnabled ? filters : [],}const referrerQuery: HogQLQuery = {@@ -780,11 +787,11 @@ const loadQueryData = async (if(isNotNull(properties.$referring_domain) AND properties.$referring_domain != '', properties.$referring_domain, '$direct') AS referring_domain,count() AS view_countFROM events- WHERE {filters}+ WHERE ${whereClause}AND event = '$pageview'GROUP BY minute_bucket, referring_domainORDER BY minute_bucket ASC`,- filters: hogQLFilters,+ ...queryParams,}const geoQuery: HogQLQuery = {@@ -802,7 +809,7 @@ const loadQueryData = async (properties.$geoip_country_code AS country_code,arrayDistinct(groupArray(distinct_id)) AS distinct_idsFROM events- WHERE {filters}+ WHERE ${whereClause}AND properties.$geoip_country_code IS NOT NULLAND properties.$geoip_country_code != ''GROUP BY@@ -811,7 +818,7 @@ const loadQueryData = async ()GROUP BY minute_bucketORDER BY minute_bucket ASC`,- filters: hogQLFilters,+ ...queryParams,}// Aggregate per-minute first then re-group so the response is bounded by the@@ -831,12 +838,12 @@ const loadQueryData = async (toStartOfMinute(timestamp) AS minute_bucket,concat(\`$virt_bot_name\`,- {botSeparator},+ '${BOT_KEY_SEPARATOR}',ifNull(\`$virt_traffic_category\`, '')) AS bot_key,count() AS event_countFROM events- WHERE {filters}+ WHERE ${whereClause}AND \`$virt_is_bot\` = trueAND \`$virt_bot_name\` != ''AND event IN ${botEligibleEventsTuple}@@ -846,10 +853,7 @@ const loadQueryData = async ()GROUP BY minute_bucketORDER BY minute_bucket ASC`,- values: {- botSeparator: BOT_KEY_SEPARATOR,- },- filters: hogQLFilters,+ ...queryParams,}const cityQuery: HogQLQuery | null = includeCity@@ -867,12 +871,12 @@ const loadQueryData = async (toStartOfMinute(timestamp) AS minute_bucket,concat(properties.$geoip_city_name,- {citySeparator},+ '${CITY_KEY_SEPARATOR}',ifNull(properties.$geoip_country_code, '')) AS city_key,arrayDistinct(groupArray(distinct_id)) AS distinct_idsFROM events- WHERE {filters}+ WHERE ${whereClause}AND properties.$geoip_city_name IS NOT NULLAND properties.$geoip_city_name != ''GROUP BY@@ -881,18 +885,12 @@ const loadQueryData = async ()GROUP BY minute_bucketORDER BY minute_bucket ASC`,- values: {- citySeparator: CITY_KEY_SEPARATOR,- },- filters: hogQLFilters,+ ...queryParams,}: null- // Custom 60-second window for "Users online" — narrower than the dashboard's 30 min,- // so we can't reuse hogQLFilters' dateRange. We pass only the property filters and keep- // the explicit timestamp predicate. Loaded whenever any filter is active.const recentUsersQuery: HogQLQuery | null =- filters.length > 0+ filtersEnabled && filters.length > 0? {kind: NodeKind.HogQLQuery,query: `SELECT@@ -900,13 +898,16 @@ const loadQueryData = async (toUnixTimestamp(max(timestamp)) AS last_seenFROM eventsWHERE {filters}- AND timestamp > toDateTime({dateTo}) - INTERVAL ${FILTERED_LIVE_USER_WINDOW_SECONDS} SECOND- AND timestamp <= toDateTime({dateTo})GROUP BY distinct_id`,- values: {- dateTo: dateTo.toISOString(),+ filters: {+ properties: filters,+ dateRange: {+ date_from: new Date(+ dateTo.getTime() - FILTERED_LIVE_USER_WINDOW_SECONDS * 1000+ ).toISOString(),+ date_to: dateTo.toISOString(),+ },},- filters: { properties: filters },}: null