: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
fix(web-analytics): page performance overview and leaderboard never load (#83320)
Jordan Mryyancbc88fd3e1e8
diff --git a/frontend/src/scenes/web-analytics/PagePerformance.tsx b/frontend/src/scenes/web-analytics/PagePerformance.tsxindex 72879e0d58d7..5b7fb782ed0b 100644--- a/frontend/src/scenes/web-analytics/PagePerformance.tsx+++ b/frontend/src/scenes/web-analytics/PagePerformance.tsx@@ -240,14 +240,15 @@ export const PagePerformance = (): JSX.Element => {const {pageTableQuery,pageCandidates,- pageDataError,- pageDataLoading,+ candidatesError,+ candidatesLoading,overviewCards,+ overviewError,overviewLoading,footerText,aiSectionQueries,} = useValues(pagePerformanceLogic)- const { loadPageData } = useActions(pagePerformanceLogic)+ const { loadOverview, loadCandidates } = useActions(pagePerformanceLogic)const context = useMemo((): QueryContext => ({@@ -292,21 +293,31 @@ export const PagePerformance = (): JSX.Element => {site. AI referrals are a lower bound: some assistants strip the referrer, so those visits land inDirect.</LemonBanner>- <OverviewGrid- items={overviewCards}- loading={overviewLoading && overviewCards.length === 0}- numSkeletons={4}- labelFromKey={(key) => OVERVIEW_CARD_LABELS[key] ?? key}- />+ {overviewError ? (+ <LemonBanner type="error" className="mb-4" action={{ children: 'Try again', onClick: loadOverview }}>+ Could not load the summary metrics. Try again to reload.+ </LemonBanner>+ ) : (+ <OverviewGrid+ items={overviewCards}+ loading={overviewLoading && overviewCards.length === 0}+ numSkeletons={4}+ labelFromKey={(key) => OVERVIEW_CARD_LABELS[key] ?? key}+ />+ )}<div className="border rounded bg-surface-primary flex flex-col mt-4"><div className="flex items-baseline justify-between gap-2 px-3 pt-3"><h3 className="font-semibold m-0">Pages ranked by visitors</h3></div>- {pageDataError ? (- <LemonBanner type="error" className="m-3" action={{ children: 'Try again', onClick: loadPageData }}>+ {candidatesError ? (+ <LemonBanner+ type="error"+ className="m-3"+ action={{ children: 'Try again', onClick: loadCandidates }}+ >Could not load page performance. Try again to reload the leaderboard.</LemonBanner>- ) : pageDataLoading && pageCandidates === null ? (+ ) : candidatesLoading && pageCandidates === null ? (<div className="flex items-center justify-center py-12"><Spinner className="text-2xl" /></div>diff --git a/frontend/src/scenes/web-analytics/PagePerformanceFilters.tsx b/frontend/src/scenes/web-analytics/PagePerformanceFilters.tsxindex 375e076f7c1c..6394a24ec1f1 100644--- a/frontend/src/scenes/web-analytics/PagePerformanceFilters.tsx+++ b/frontend/src/scenes/web-analytics/PagePerformanceFilters.tsx@@ -26,8 +26,8 @@ export const PagePerformanceFilters = ({ tabs }: { tabs: JSX.Element }): JSX.Eleconst { setDates, setCompareFilter, setConversionGoal, setIsPathCleaningEnabled } = useActions(webAnalyticsLogic)const { areAnyLoading } = useValues(dataNodeCollectionLogic({ key: WEB_ANALYTICS_DATA_COLLECTION_NODE_ID }))const { reloadAll } = useActions(dataNodeCollectionLogic({ key: WEB_ANALYTICS_DATA_COLLECTION_NODE_ID }))- const { pageDataLoading } = useValues(pagePerformanceLogic)- const isReloading = areAnyLoading || pageDataLoading+ const { overviewLoading, candidatesLoading } = useValues(pagePerformanceLogic)+ const isReloading = areAnyLoading || overviewLoading || candidatesLoadingreturn (<FilterBardiff --git a/frontend/src/scenes/web-analytics/pagePerformanceLogic.ts b/frontend/src/scenes/web-analytics/pagePerformanceLogic.tsindex 7dfd0c08d1ef..77199a0cbacb 100644--- a/frontend/src/scenes/web-analytics/pagePerformanceLogic.ts+++ b/frontend/src/scenes/web-analytics/pagePerformanceLogic.ts@@ -66,6 +66,8 @@ import type { DateFilterState } from './webAnalyticsLogic'const PAGE_PERFORMANCE_EVENTS = "('$pageview', '$screen', '$http_log')"+const HUMAN_EVENTS = "('$pageview', '$screen')"+const PAGE_TABLE_LIMIT = 20const PAGE_CANDIDATE_LIMIT = 200@@ -293,7 +295,7 @@ LIMIT ${PAGE_TABLE_LIMIT}`}-const buildOverviewQuery = (window: PagePerformanceWindow, pathExpr: string): string => {+const buildOverviewHumanQuery = (window: PagePerformanceWindow, pathExpr: string): string => {const { cur, prev, full } = windowPredicates(window)const pageKey = pageKeyExpr(pathExpr)@@ -305,10 +307,26 @@ SELECTuniqIf(person_id, (${GOOGLE_VIEW}) AND ${prev}) AS google_previous,uniqIf(person_id, (${AI_VIEW}) AND ${cur}) AS llm,uniqIf(person_id, (${AI_VIEW}) AND ${prev}) AS llm_previous,- countIf((${CRAWLER}) AND ${cur}) AS crawls,- countIf((${CRAWLER}) AND ${prev}) AS crawls_previous,uniqIf(${pageKey}, (${HUMAN_VIEW}) AND ${cur}) AS pagesFROM events+WHERE and(+ event IN ${HUMAN_EVENTS},+ properties.$pathname IS NOT NULL,+ properties.$pathname != '',+ (${full}),+ {filters}+)+`+}++const buildOverviewCrawlerQuery = (window: PagePerformanceWindow): string => {+ const { cur, prev, full } = windowPredicates(window)++ return `+SELECT+ countIf((${CRAWLER}) AND ${cur}) AS crawls,+ countIf((${CRAWLER}) AND ${prev}) AS crawls_previous+FROM eventsWHERE and(event IN ${PAGE_PERFORMANCE_EVENTS},properties.$pathname IS NOT NULL,@@ -391,18 +409,21 @@ export interface pagePerformanceLogicValues {aiSectionQueries: AiSectionQueriesbreakdownModal: PagePerformanceBreakdownState | nullbreakdownQuery: DataTableNode | null+ candidatesError: string | null+ candidatesInput: string+ candidatesLoading: booleanfooterText: stringgoalLabel: string | nullorderBy: PagePerformanceOrderByoverviewCards: OverviewItem[]+ overviewCrawlerQuery: string+ overviewError: string | null+ overviewHumanQuery: string+ overviewInput: stringoverviewLoading: boolean- overviewQuery: stringoverviewTotals: OverviewTotals | nullpageCandidateQuery: WebStatsTableQuerypageCandidates: string[] | null- pageDataError: string | null- pageDataInput: string- pageDataLoading: booleanpageTableQuery: DataTableNodepathExpr: stringpreviousPathExpr: string@@ -414,17 +435,22 @@ export interface pagePerformanceLogicActions {closeBreakdown: () => {value: true}- loadPageData: () => {+ loadOverview: () => {value: true}- loadPageDataFailure: (error: string) => {+ loadOverviewFailure: (error: string) => {error: string}- loadPageDataSuccess: (- overviewTotals: OverviewTotals,- pageCandidates: string[]- ) => {+ loadOverviewSuccess: (overviewTotals: OverviewTotals) => {overviewTotals: OverviewTotals+ }+ loadCandidates: () => {+ value: true+ }+ loadCandidatesFailure: (error: string) => {+ error: string+ }+ loadCandidatesSuccess: (pageCandidates: string[]) => {pageCandidates: string[]}openBreakdown: (breakdown: PagePerformanceBreakdownState) => {@@ -464,8 +490,10 @@ export interface pagePerformanceLogicMeta {conversionGoal: WebAnalyticsConversionGoal | null,compareFilter: CompareFilter) => AiSectionQueries- overviewQuery: (window: PagePerformanceWindow, pathExpr: string) => string- pageDataInput: (overviewQuery: string, pageCandidateQuery: WebStatsTableQuery) => string+ overviewHumanQuery: (window: PagePerformanceWindow, pathExpr: string) => string+ overviewCrawlerQuery: (window: PagePerformanceWindow) => string+ overviewInput: (overviewHumanQuery: string, overviewCrawlerQuery: string, filterTestAccounts: boolean) => string+ candidatesInput: (pageCandidateQuery: WebStatsTableQuery) => stringbreakdownQuery: (breakdownModal: PagePerformanceBreakdownState | null,window: PagePerformanceWindow,@@ -512,12 +540,12 @@ export const pagePerformanceLogic = kea<pagePerformanceLogicType>([setOrderBy: (column: string, direction: 'ASC' | 'DESC') => ({ column, direction }),openBreakdown: (breakdown: PagePerformanceBreakdownState) => ({ breakdown }),closeBreakdown: true,- loadPageData: true,- loadPageDataFailure: (error: string) => ({ error }),- loadPageDataSuccess: (overviewTotals: OverviewTotals, pageCandidates: string[]) => ({- overviewTotals,- pageCandidates,- }),+ loadOverview: true,+ loadOverviewFailure: (error: string) => ({ error }),+ loadOverviewSuccess: (overviewTotals: OverviewTotals) => ({ overviewTotals }),+ loadCandidates: true,+ loadCandidatesFailure: (error: string) => ({ error }),+ loadCandidatesSuccess: (pageCandidates: string[]) => ({ pageCandidates }),}),reducers({orderBy: [@@ -536,38 +564,45 @@ export const pagePerformanceLogic = kea<pagePerformanceLogicType>([overviewTotals: [null as OverviewTotals | null,{- loadPageData: () => null,- loadPageDataSuccess: (_, { overviewTotals }) => overviewTotals,+ loadOverview: () => null,+ loadOverviewSuccess: (_, { overviewTotals }) => overviewTotals,},],- pageCandidates: [- null as string[] | null,+ overviewError: [+ null as string | null,{- loadPageData: () => null,- loadPageDataSuccess: (_, { pageCandidates }) => pageCandidates,+ loadOverview: () => null,+ loadOverviewFailure: (_, { error }) => error,},],- pageDataError: [- null as string | null,+ overviewLoading: [+ false,{- loadPageData: () => null,- loadPageDataFailure: (_, { error }) => error,+ loadOverview: () => true,+ loadOverviewSuccess: () => false,+ loadOverviewFailure: () => false,},],- pageDataLoading: [- false,+ pageCandidates: [+ null as string[] | null,{- loadPageData: () => true,- loadPageDataSuccess: () => false,- loadPageDataFailure: () => false,+ loadCandidates: () => null,+ loadCandidatesSuccess: (_, { pageCandidates }) => pageCandidates,},],- overviewLoading: [+ candidatesError: [+ null as string | null,+ {+ loadCandidates: () => null,+ loadCandidatesFailure: (_, { error }) => error,+ },+ ],+ candidatesLoading: [false,{- loadPageData: () => true,- loadPageDataSuccess: () => false,- loadPageDataFailure: () => false,+ loadCandidates: () => true,+ loadCandidatesSuccess: () => false,+ loadCandidatesFailure: () => false,},],}),@@ -808,14 +843,22 @@ export const pagePerformanceLogic = kea<pagePerformanceLogicType>([}},],- overviewQuery: [+ overviewHumanQuery: [(s) => [s.window, s.pathExpr],- (window: PagePerformanceWindow, pathExpr: string): string => buildOverviewQuery(window, pathExpr),+ (window: PagePerformanceWindow, pathExpr: string): string => buildOverviewHumanQuery(window, pathExpr),+ ],+ overviewCrawlerQuery: [+ (s) => [s.window],+ (window: PagePerformanceWindow): string => buildOverviewCrawlerQuery(window),],- pageDataInput: [- (s) => [s.overviewQuery, s.pageCandidateQuery],- (overviewQuery: string, pageCandidateQuery: WebStatsTableQuery): string =>- JSON.stringify([overviewQuery, pageCandidateQuery]),+ overviewInput: [+ (s) => [s.overviewHumanQuery, s.overviewCrawlerQuery, s.filterTestAccounts],+ (overviewHumanQuery: string, overviewCrawlerQuery: string, filterTestAccounts: boolean): string =>+ JSON.stringify([overviewHumanQuery, overviewCrawlerQuery, filterTestAccounts]),+ ],+ candidatesInput: [+ (s) => [s.pageCandidateQuery],+ (pageCandidateQuery: WebStatsTableQuery): string => JSON.stringify(pageCandidateQuery),],breakdownQuery: [(s) => [s.breakdownModal, s.window, s.filterTestAccounts, s.pathExpr],@@ -898,68 +941,104 @@ export const pagePerformanceLogic = kea<pagePerformanceLogicType>([],})),listeners(({ values, actions, cache }) => ({- loadPageData: async (_, breakpoint) => {+ loadOverview: async (_, breakpoint) => {await breakpoint(300)- cache.disposables.dispose('pageDataRequest')+ cache.disposables.dispose('overviewRequest')const abortController = new AbortController()- cache.disposables.add(() => abortController.abort(), 'pageDataRequest')+ cache.disposables.add(() => () => abortController.abort(), 'overviewRequest', {+ pauseOnPageHidden: false,+ })- const overviewNode: HogQLQuery = {+ const humanNode: HogQLQuery = {+ kind: NodeKind.HogQLQuery,+ query: values.overviewHumanQuery,+ filters: { filterTestAccounts: values.filterTestAccounts },+ tags: WEB_ANALYTICS_DEFAULT_QUERY_TAGS,+ }+ const crawlerNode: HogQLQuery = {kind: NodeKind.HogQLQuery,- query: values.overviewQuery,+ query: values.overviewCrawlerQuery,filters: { filterTestAccounts: values.filterTestAccounts },tags: WEB_ANALYTICS_DEFAULT_QUERY_TAGS,}try {- const [overviewResponse, candidatesResponse] = await Promise.all([- performQuery(overviewNode, { signal: abortController.signal }),- performQuery(values.pageCandidateQuery, { signal: abortController.signal }),+ const [humanResponse, crawlerResponse] = await Promise.all([+ performQuery(humanNode, { signal: abortController.signal }),+ performQuery(crawlerNode, { signal: abortController.signal }),])breakpoint()- const row = overviewResponse.results?.[0] ?? []- const columns: string[] = overviewResponse.columns ?? []- const at = (name: string): number => {- const idx = columns.indexOf(name)- return idx >= 0 ? Number(row[idx] ?? 0) : 0+ const readColumn = (response: typeof humanResponse): ((name: string) => number) => {+ const row = response.results?.[0] ?? []+ const columns: string[] = response.columns ?? []+ return (name: string): number => {+ const idx = columns.indexOf(name)+ return idx >= 0 ? Number(row[idx] ?? 0) : 0+ }}+ const human = readColumn(humanResponse)+ const crawler = readColumn(crawlerResponse)+ actions.loadOverviewSuccess({+ visitors: human('visitors'),+ visitorsPrevious: human('visitors_previous'),+ google: human('google'),+ googlePrevious: human('google_previous'),+ llm: human('llm'),+ llmPrevious: human('llm_previous'),+ crawls: crawler('crawls'),+ crawlsPrevious: crawler('crawls_previous'),+ pages: human('pages'),+ })+ } catch (error) {+ if ((error instanceof Error && isBreakpoint(error)) || isAbortedRequest(error)) {+ return+ }+ actions.loadOverviewFailure(error instanceof Error ? error.message : 'Could not load page performance')+ }+ },+ loadCandidates: async (_, breakpoint) => {+ await breakpoint(300)+ cache.disposables.dispose('candidatesRequest')+ const abortController = new AbortController()+ cache.disposables.add(() => () => abortController.abort(), 'candidatesRequest', {+ pauseOnPageHidden: false,+ })+ try {+ const candidatesResponse = await performQuery(values.pageCandidateQuery, {+ signal: abortController.signal,+ })+ breakpoint()const pageCandidates = (candidatesResponse.results ?? []).flatMap((candidate) => {if (!Array.isArray(candidate) || typeof candidate[0] !== 'string' || candidate[0] === '') {return []}return [candidate[0]]})- actions.loadPageDataSuccess(- {- visitors: at('visitors'),- visitorsPrevious: at('visitors_previous'),- google: at('google'),- googlePrevious: at('google_previous'),- llm: at('llm'),- llmPrevious: at('llm_previous'),- crawls: at('crawls'),- crawlsPrevious: at('crawls_previous'),- pages: at('pages'),- },- pageCandidates- )+ actions.loadCandidatesSuccess(pageCandidates)} catch (error) {if ((error instanceof Error && isBreakpoint(error)) || isAbortedRequest(error)) {return}- actions.loadPageDataFailure(error instanceof Error ? error.message : 'Could not load page performance')+ actions.loadCandidatesFailure(+ error instanceof Error ? error.message : 'Could not load page performance'+ )}},reloadAll: () => {- actions.loadPageData()+ actions.loadOverview()+ actions.loadCandidates()},})),subscriptions(({ actions }) => ({- pageDataInput: () => {- actions.loadPageData()+ overviewInput: () => {+ actions.loadOverview()+ },+ candidatesInput: () => {+ actions.loadCandidates()},})),afterMount(({ actions }) => {- actions.loadPageData()+ actions.loadOverview()+ actions.loadCandidates()}),])