: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 live tiles to bot tab (#58074)
Lucas Ricoy4e135c3be63d
diff --git a/frontend/src/scenes/web-analytics/LiveMetricsDashboard/LiveBotTiles.tsx b/frontend/src/scenes/web-analytics/LiveMetricsDashboard/LiveBotTiles.tsxnew file mode 100644index 000000000000..08af7521b8e1--- /dev/null+++ b/frontend/src/scenes/web-analytics/LiveMetricsDashboard/LiveBotTiles.tsx@@ -0,0 +1,58 @@+import { useActions, useValues } from 'kea'+import { useEffect, useMemo } from 'react'++import { usePageVisibility } from 'lib/hooks/usePageVisibility'++import { LiveBotTrafficCard } from './LiveBotTrafficCard'+import { LiveChartCard } from './LiveChartCard'+import { LiveStatCard, LiveStatDivider } from './LiveStatCard'+import { BotEventsPerMinuteChart } from './liveWebAnalyticsMetricsCharts'+import { liveWebAnalyticsMetricsLogic } from './liveWebAnalyticsMetricsLogic'++export const LiveBotTiles = (): JSX.Element => {+ const { chartData, botBreakdown, totalBotEvents, totalBotEligibleEvents, isLoading } =+ useValues(liveWebAnalyticsMetricsLogic)+ const { pauseStream, resumeStream } = useActions(liveWebAnalyticsMetricsLogic)++ const { isVisible } = usePageVisibility()+ useEffect(() => {+ if (isVisible) {+ resumeStream()+ } else {+ pauseStream()+ }+ }, [isVisible, resumeStream, pauseStream])++ const timezone = useMemo(() => Intl.DateTimeFormat().resolvedOptions().timeZone, [])+ const botShare = totalBotEligibleEvents > 0 ? Math.round((totalBotEvents / totalBotEligibleEvents) * 100) : null++ return (+ <div className="mb-6">+ <div className="flex flex-wrap items-center gap-4 md:gap-6 mb-6">+ <LiveStatCard label="Bot events" value={totalBotEvents} isLoading={isLoading} />+ <LiveStatDivider />+ <LiveStatCard label="Total events" value={totalBotEligibleEvents} isLoading={isLoading} />+ <LiveStatDivider />+ <LiveStatCard label="Bot share %" value={botShare} isLoading={isLoading} />+ </div>++ <div className="grid grid-cols-1 md:grid-cols-2 gap-6">+ <LiveChartCard+ title="Bot requests per minute"+ subtitle={timezone}+ subtitleTooltip="Metrics are shown in your local timezone"+ isLoading={isLoading}+ contentClassName="h-64 md:h-80"+ >+ <BotEventsPerMinuteChart data={chartData} />+ </LiveChartCard>+ <LiveBotTrafficCard+ data={botBreakdown}+ totalBotEvents={totalBotEvents}+ totalEvents={totalBotEligibleEvents}+ isLoading={isLoading}+ />+ </div>+ </div>+ )+}diff --git a/frontend/src/scenes/web-analytics/LiveMetricsDashboard/liveWebAnalyticsMetricsLogic.tsx b/frontend/src/scenes/web-analytics/LiveMetricsDashboard/liveWebAnalyticsMetricsLogic.tsxindex f7a5ff00cff6..18d6a9a8134f 100644--- a/frontend/src/scenes/web-analytics/LiveMetricsDashboard/liveWebAnalyticsMetricsLogic.tsx+++ b/frontend/src/scenes/web-analytics/LiveMetricsDashboard/liveWebAnalyticsMetricsLogic.tsx@@ -12,7 +12,9 @@ import { liveEventsHostOrigin } from 'lib/utils/apiHost'import { CATEGORY_LABELS } from 'lib/utils/botDetection'import { deduplicateEvents } from 'scenes/activity/live/deduplicateEvents'import { teamLogic } from 'scenes/teamLogic'+import { ProductTab } from 'scenes/web-analytics/common'import { webAnalyticsFilterLogic } from 'scenes/web-analytics/webAnalyticsFilterLogic'+import { webAnalyticsLogic } from 'scenes/web-analytics/webAnalyticsLogic'import { performQuery } from '~/queries/query'import {@@ -91,6 +93,8 @@ export const liveWebAnalyticsMetricsLogic = kea<liveWebAnalyticsMetricsLogicType['featureFlags'],webAnalyticsFilterLogic,['selectedHost as rawSelectedHost'],+ webAnalyticsLogic,+ ['productTab'],],})),actions(() => ({@@ -362,9 +366,15 @@ export const liveWebAnalyticsMetricsLogic = kea<liveWebAnalyticsMetricsLogicType(recentUsersByLastSeen: Map<string, number>): number => recentUsersByLastSeen.size,],selectedHost: [- (s) => [s.rawSelectedHost, s.featureFlags],- (rawSelectedHost: string | null, featureFlags: FeatureFlagsSet): string | null =>- featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_LIVE_DOMAIN_FILTER] ? rawSelectedHost : null,+ (s) => [s.rawSelectedHost, s.featureFlags, s.productTab],+ (rawSelectedHost: string | null, featureFlags: FeatureFlagsSet, productTab: ProductTab): string | null => {+ // The bot tab streams traffic across all hosts, so ignore any host filter+ // a sibling tab may have set on the shared filter logic.+ if (productTab === ProductTab.BOT_ANALYTICS) {+ return null+ }+ return featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_LIVE_DOMAIN_FILTER] ? rawSelectedHost : null+ },],}),listeners(({ actions, values, cache }) => ({diff --git a/frontend/src/scenes/web-analytics/WebAnalyticsDashboard.tsx b/frontend/src/scenes/web-analytics/WebAnalyticsDashboard.tsxindex 66e6d1eaa5c3..39d8e56dfbbb 100644--- a/frontend/src/scenes/web-analytics/WebAnalyticsDashboard.tsx+++ b/frontend/src/scenes/web-analytics/WebAnalyticsDashboard.tsx@@ -54,6 +54,7 @@ import { InsightLogicProps, OnboardingStepKey, TeamPublicType, TeamType } from 'import { BotAnalyticsFilters } from './BotAnalyticsFilters'import { botAnalyticsLogic } from './botAnalyticsLogic'import { HealthStatusTab, webAnalyticsHealthLogic } from './health'+import { LiveBotTiles } from './LiveMetricsDashboard/LiveBotTiles'import { LiveWebAnalyticsMetrics } from './LiveMetricsDashboard/LiveWebAnalyticsMetrics'import { WebAnalyticsExport } from './WebAnalyticsExport'import { WebAnalyticsFilters } from './WebAnalyticsFilters'@@ -450,6 +451,8 @@ const BotAnalyticsTiles = (): JSX.Element => {// Drives bot tab off its own logic so bot filters don't pollute the regular Analytics tab.useMountedLogic(botAnalyticsLogic)const { tiles } = useValues(botAnalyticsLogic)+ const { featureFlags } = useValues(featureFlagLogic)+ const showLiveTiles = !!featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_LIVE_METRICS]return (<>@@ -458,6 +461,7 @@ const BotAnalyticsTiles = (): JSX.Element => {results. For better coverage, send server-side HTTP logs as <code>$http_log</code> events — most botsdon't execute JavaScript, so client-side tracking alone misses the majority of crawler traffic.</LemonBanner>+ {showLiveTiles && <LiveBotTiles />}<Tiles tiles={tiles} /></>)