: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): unify precompute badge tooltip and gate on flag (#62571)
Lucas Ricoy22c1ea95649f
diff --git a/frontend/src/lib/components/PreAggregatedBadge/PreAggregatedBadge.tsx b/frontend/src/lib/components/PreAggregatedBadge/PreAggregatedBadge.tsxindex d2b0311b31cf..fa90f225104c 100644--- a/frontend/src/lib/components/PreAggregatedBadge/PreAggregatedBadge.tsx+++ b/frontend/src/lib/components/PreAggregatedBadge/PreAggregatedBadge.tsx@@ -1,15 +1,25 @@import clsx from 'clsx'+import { useValues } from 'kea'import { IconBolt, IconDatabaseBolt } from '@posthog/icons'+import { FEATURE_FLAGS } from 'lib/constants'+import { Link } from 'lib/lemon-ui/Link'import { Tooltip } from 'lib/lemon-ui/Tooltip'+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'export type PreAggregatedBadgeVariant = 'preagg' | 'precomputed'export type PreAggregatedBadgePosition = 'top-right' | 'bottom-right'+// FAQ answer explaining what the pre-computed badge means.+const QUERY_ENGINE_DOCS_URL = 'https://posthog.com/docs/web-analytics/faq#what-does-the-pre-computed-badge-mean'+interface PreAggregatedBadgeProps {variant?: PreAggregatedBadgeVariantposition?: PreAggregatedBadgePosition+ // Optional opt-out wired by the host (the web analytics page). Keeps this component scene-agnostic:+ // when omitted, the tooltip just drops the "always query live data" shortcut.+ onDisable?: () => void}const POSITION_CLASS: Record<PreAggregatedBadgePosition, string> = {@@ -17,29 +27,54 @@ const POSITION_CLASS: Record<PreAggregatedBadgePosition, string> = {'bottom-right': 'bottom-2 right-2',}-const VARIANT_CONFIG: Record<- PreAggregatedBadgeVariant,- { tooltip: string; iconClassName: string; Icon: typeof IconBolt }-> = {- preagg: {- tooltip: 'Optimized with new query engine',- iconClassName: 'text-warning w-4 h-4',- Icon: IconBolt,- },- precomputed: {- tooltip: 'Loaded from a pre-computed dataset',- iconClassName: 'text-muted w-4 h-4',- Icon: IconDatabaseBolt,- },+function PreAggregatedTooltip(): JSX.Element {+ return (+ <span>+ Optimized with our new query engine. <Link to={QUERY_ENGINE_DOCS_URL}>Learn more</Link>+ </span>+ )+}++function PrecomputedTooltip({ onDisable }: { onDisable?: () => void }): JSX.Element {+ return (+ <div className="flex flex-col gap-1 max-w-xs">+ <span>Loaded from a pre-computed state instead of running a live query against all events.</span>+ <span>It should be very close to live data, but isn't guaranteed to be exact.</span>+ <span>+ <Link to={QUERY_ENGINE_DOCS_URL}>Learn more</Link>+ {onDisable && (+ <>+ {' · '}+ <Link onClick={onDisable}>Always query live data</Link>+ </>+ )}+ </span>+ </div>+ )}export function PreAggregatedBadge({variant = 'preagg',position = 'top-right',-}: PreAggregatedBadgeProps = {}): JSX.Element {- const { tooltip, iconClassName, Icon } = VARIANT_CONFIG[variant]+ onDisable,+}: PreAggregatedBadgeProps = {}): JSX.Element | null {+ const { featureFlags } = useValues(featureFlagLogic)+ const isPrecomputed = variant === 'precomputed'++ // The precompute kill switch only governs the pre-computed roll-up indicator. The pre-aggregated+ // ("new query engine") badge is controlled upstream by its own settings flag and must stay visible.+ if (isPrecomputed && !featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_PRECOMPUTE_TOGGLE]) {+ return null+ }++ const Icon = isPrecomputed ? IconDatabaseBolt : IconBolt+ const iconClassName = isPrecomputed ? 'text-muted w-4 h-4' : 'text-warning w-4 h-4'+return (- <Tooltip title={tooltip}>+ <Tooltip+ interactive+ title={isPrecomputed ? <PrecomputedTooltip onDisable={onDisable} /> : <PreAggregatedTooltip />}+ ><div className={clsx('absolute z-10', POSITION_CLASS[position])}><Icon className={iconClassName} /></div>diff --git a/frontend/src/queries/nodes/DataTable/DataTable.tsx b/frontend/src/queries/nodes/DataTable/DataTable.tsxindex 56ffcbd3f627..9574bdc2a2af 100644--- a/frontend/src/queries/nodes/DataTable/DataTable.tsx+++ b/frontend/src/queries/nodes/DataTable/DataTable.tsx@@ -893,7 +893,10 @@ export function DataTable({{showResultsTable && (<div className="relative">{usedWebAnalyticsLazyPrecompute ? (- <PreAggregatedBadge variant="precomputed" />+ <PreAggregatedBadge+ variant="precomputed"+ onDisable={context?.onDisableWebAnalyticsPrecompute}+ />) : usedWebAnalyticsPreAggregatedTables ? (<PreAggregatedBadge variant="preagg" />) : null}diff --git a/frontend/src/queries/nodes/OverviewGrid/OverviewGrid.tsx b/frontend/src/queries/nodes/OverviewGrid/OverviewGrid.tsxindex 52ee60af1f56..e4ee90c2e32d 100644--- a/frontend/src/queries/nodes/OverviewGrid/OverviewGrid.tsx+++ b/frontend/src/queries/nodes/OverviewGrid/OverviewGrid.tsx@@ -56,6 +56,7 @@ interface OverviewGridProps {samplingRate?: SamplingRateusedPreAggregatedTables?: booleanusedLazyPrecompute?: boolean+ onDisablePrecompute?: () => voidlabelFromKey: (key: string) => stringfilterEmptyItems?: (item: OverviewItem) => booleancompact?: boolean@@ -68,6 +69,7 @@ export function OverviewGrid({samplingRate,usedPreAggregatedTables = false,usedLazyPrecompute = false,+ onDisablePrecompute,labelFromKey,filterEmptyItems = () => true,compact = false,@@ -93,6 +95,7 @@ export function OverviewGrid({item={item}usedPreAggregatedTables={usedPreAggregatedTables}usedLazyPrecompute={usedLazyPrecompute}+ onDisablePrecompute={onDisablePrecompute}labelFromKey={labelFromKey}compact={compact}/>@@ -145,6 +148,7 @@ interface OverviewItemCellProps {item: OverviewItemusedPreAggregatedTables: booleanusedLazyPrecompute: boolean+ onDisablePrecompute?: () => voidlabelFromKey: (key: string) => stringcompact: boolean}@@ -153,6 +157,7 @@ const OverviewItemCell = ({item,usedPreAggregatedTables,usedLazyPrecompute,+ onDisablePrecompute,labelFromKey,compact,}: OverviewItemCellProps): JSX.Element => {@@ -234,7 +239,7 @@ const OverviewItemCell = ({{/* Rendered as a sibling of the Tooltip trigger so hovering the badgedoes not also surface the cell's metric tooltip. */}{usedLazyPrecompute ? (- <PreAggregatedBadge variant="precomputed" />+ <PreAggregatedBadge variant="precomputed" onDisable={onDisablePrecompute} />) : usedPreAggregatedTables ? (<PreAggregatedBadge variant="preagg" />) : null}diff --git a/frontend/src/queries/nodes/OverviewGrid/OverviewMetricCardGrid.tsx b/frontend/src/queries/nodes/OverviewGrid/OverviewMetricCardGrid.tsxindex c1bc959c3fcc..fa150887517c 100644--- a/frontend/src/queries/nodes/OverviewGrid/OverviewMetricCardGrid.tsx+++ b/frontend/src/queries/nodes/OverviewGrid/OverviewMetricCardGrid.tsx@@ -25,6 +25,7 @@ interface OverviewMetricCardGridProps {samplingRate?: SamplingRateusedPreAggregatedTables?: booleanusedLazyPrecompute?: boolean+ onDisablePrecompute?: () => voidlabelFromKey: (key: string) => string}@@ -35,6 +36,7 @@ export function OverviewMetricCardGrid({samplingRate,usedPreAggregatedTables = false,usedLazyPrecompute = false,+ onDisablePrecompute,labelFromKey,}: OverviewMetricCardGridProps): JSX.Element {return (@@ -48,6 +50,7 @@ export function OverviewMetricCardGrid({item={item}usedPreAggregatedTables={usedPreAggregatedTables}usedLazyPrecompute={usedLazyPrecompute}+ onDisablePrecompute={onDisablePrecompute}labelFromKey={labelFromKey}/>))}@@ -61,11 +64,13 @@ function MetricCardCell({item,usedPreAggregatedTables,usedLazyPrecompute,+ onDisablePrecompute,labelFromKey,}: {item: OverviewMetricCardItemusedPreAggregatedTables: booleanusedLazyPrecompute: boolean+ onDisablePrecompute?: () => voidlabelFromKey: (key: string) => string}): JSX.Element {const { baseCurrency } = useValues(teamLogic)@@ -103,7 +108,7 @@ function MetricCardCell({aria-pressed={clickable ? !!item.selected : undefined}>{usedLazyPrecompute ? (- <PreAggregatedBadge variant="precomputed" position="bottom-right" />+ <PreAggregatedBadge variant="precomputed" position="bottom-right" onDisable={onDisablePrecompute} />) : usedPreAggregatedTables ? (<PreAggregatedBadge variant="preagg" position="bottom-right" />) : null}diff --git a/frontend/src/queries/nodes/WebOverview/WebOverview.tsx b/frontend/src/queries/nodes/WebOverview/WebOverview.tsxindex 78170462cd0a..5558ec836ef9 100644--- a/frontend/src/queries/nodes/WebOverview/WebOverview.tsx+++ b/frontend/src/queries/nodes/WebOverview/WebOverview.tsx@@ -78,6 +78,7 @@ export function WebOverview(props: {samplingRate={samplingRate}usedPreAggregatedTables={usedWebAnalyticsPreAggregatedTables}usedLazyPrecompute={usedWebAnalyticsLazyPrecompute}+ onDisablePrecompute={props.context.onDisableWebAnalyticsPrecompute}labelFromKey={labelFromKey}/>)@@ -91,6 +92,7 @@ export function WebOverview(props: {samplingRate={samplingRate}usedPreAggregatedTables={usedWebAnalyticsPreAggregatedTables}usedLazyPrecompute={usedWebAnalyticsLazyPrecompute}+ onDisablePrecompute={props.context.onDisableWebAnalyticsPrecompute}labelFromKey={labelFromKey}/>)diff --git a/frontend/src/queries/nodes/WebVitals/WebVitalsPathBreakdown.tsx b/frontend/src/queries/nodes/WebVitals/WebVitalsPathBreakdown.tsxindex 56815021b926..427e66bc5ae5 100644--- a/frontend/src/queries/nodes/WebVitals/WebVitalsPathBreakdown.tsx+++ b/frontend/src/queries/nodes/WebVitals/WebVitalsPathBreakdown.tsx@@ -54,7 +54,9 @@ export function WebVitalsPathBreakdown(props: {return (<div className="relative border rounded bg-surface-primary grid grid-cols-1 md:grid-cols-3 divide-y md:divide-y-0 md:divide-x min-h-60 h-full">- {webVitalsQueryResponse?.usedLazyPrecompute && <PreAggregatedBadge variant="precomputed" />}+ {webVitalsQueryResponse?.usedLazyPrecompute && (+ <PreAggregatedBadge variant="precomputed" onDisable={props.context.onDisableWebAnalyticsPrecompute} />+ )}<div className="p-4"><Header band="good" label="Good" /><Content band="good" response={webVitalsQueryResponse} responseLoading={responseLoading} />diff --git a/frontend/src/queries/types.ts b/frontend/src/queries/types.tsindex cbf4b8be127f..2b862c6f6980 100644--- a/frontend/src/queries/types.ts+++ b/frontend/src/queries/types.ts@@ -69,6 +69,8 @@ export interface QueryContext<Q extends QuerySchema = QuerySchema> {customActions?: JSX.Element | JSX.Element[]/** Callback for drag-to-zoom on time series charts. Enables x-axis drag selection when set. */onDateRangeZoom?: (dateFrom: string, dateTo: string) => void+ /** Wired by the web analytics scene so a pre-computed tile's badge can offer "always query live data". */+ onDisableWebAnalyticsPrecompute?: () => void}export type QueryContextColumnTitleComponent = ComponentType<{diff --git a/frontend/src/scenes/web-analytics/tiles/WebAnalyticsTile.tsx b/frontend/src/scenes/web-analytics/tiles/WebAnalyticsTile.tsxindex a3947de9d9fe..164a6dc47e28 100644--- a/frontend/src/scenes/web-analytics/tiles/WebAnalyticsTile.tsx+++ b/frontend/src/scenes/web-analytics/tiles/WebAnalyticsTile.tsx@@ -526,6 +526,9 @@ const SortableCell = (}export const webAnalyticsDataTableQueryContext: QueryContext = {+ // findMounted() keeps this scene-agnostic: it only acts when webAnalyticsLogic is actually mounted+ // (i.e. inside the web analytics scene), so reusing this context in product analytics is a no-op.+ onDisableWebAnalyticsPrecompute: () => webAnalyticsLogic.findMounted()?.actions.setUseWebAnalyticsPrecompute(false),columns: {breakdown_value: {renderTitle: BreakdownValueTitle,diff --git a/frontend/src/scenes/web-analytics/webAnalyticsLogic.tsx b/frontend/src/scenes/web-analytics/webAnalyticsLogic.tsxindex 79eeb983ff2e..2baaeee0b4f3 100644--- a/frontend/src/scenes/web-analytics/webAnalyticsLogic.tsx+++ b/frontend/src/scenes/web-analytics/webAnalyticsLogic.tsx@@ -839,7 +839,10 @@ export const webAnalyticsLogic = kea<webAnalyticsLogicType>([filterTestAccounts,shouldStripQueryParams,includeHostPath: !!featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_INCLUDE_HOST] && includeHostPath,- useWebAnalyticsPrecompute,+ // Gate the persisted opt-in on the flag so killing the flag can never send a stale `true`+ // to the backend for a team that had it enabled — belt-and-suspenders, not a backend guard.+ useWebAnalyticsPrecompute:+ useWebAnalyticsPrecompute && !!featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_PRECOMPUTE_TOGGLE],}),],filters: [