: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(signals): send tab badge counts on every cloud inbox viewed event (#85716)
Andrew Maguire101286343989
diff --git a/products/desktop/packages/core/src/inbox/engagement.test.ts b/products/desktop/packages/core/src/inbox/engagement.test.tsindex c405ee2621a6..2efa31dc8cd7 100644--- a/products/desktop/packages/core/src/inbox/engagement.test.ts+++ b/products/desktop/packages/core/src/inbox/engagement.test.ts@@ -113,8 +113,8 @@ describe("buildInboxViewedProperties", () => {expect(props.report_count).toBe(2);expect(props.total_count).toBe(65);expect(props.ready_count).toBe(2);- expect(props.pulls_count).toBe(38);- expect(props.reports_count).toBe(62);+ expect(props.pulls_tab_count).toBe(38);+ expect(props.reports_tab_count).toBe(62);expect(props.is_empty).toBe(false);expect(props.status_filter_count).toBe(0);});diff --git a/products/desktop/packages/core/src/inbox/engagement.ts b/products/desktop/packages/core/src/inbox/engagement.tsindex 4cc82b7ea545..b60fedbb284e 100644--- a/products/desktop/packages/core/src/inbox/engagement.ts+++ b/products/desktop/packages/core/src/inbox/engagement.ts@@ -299,7 +299,7 @@ export function buildInboxViewedProperties(actionabilityCounts.requires_human_input,actionability_not_actionable_count: actionabilityCounts.not_actionable,actionability_unknown_count: actionabilityCounts.unknown,- pulls_count: tabCounts.pulls,- reports_count: tabCounts.reports,+ pulls_tab_count: tabCounts.pulls,+ reports_tab_count: tabCounts.reports,};}diff --git a/products/desktop/packages/shared/src/analytics-events.ts b/products/desktop/packages/shared/src/analytics-events.tsindex b97d86a86084..159a0683ccb1 100644--- a/products/desktop/packages/shared/src/analytics-events.ts+++ b/products/desktop/packages/shared/src/analytics-events.ts@@ -680,12 +680,13 @@ export interface InboxViewedProperties {actionability_not_actionable_count: number;actionability_unknown_count: number;/**- * Tab badge counts shown in the v2 inbox header on load — the actual numbers- * the user sees (Pull requests / Reports / Runs). Optional: only the desktop- * v2 shell populates these; the mobile event omits them.+ * Tab badge counts shown in the inbox header on load — the actual numbers+ * the user sees (Pull requests / Reports), sent whatever tab is open. Distinct+ * from `report_count`, which is only the loaded rows of the active tab.+ * Optional: the mobile event omits them.*/- pulls_count?: number;- reports_count?: number;+ pulls_tab_count?: number;+ reports_tab_count?: number;}export interface InboxReportOpenedProperties {diff --git a/products/signals/frontend/inbox/components/InboxReportList.tsx b/products/signals/frontend/inbox/components/InboxReportList.tsxindex 5e330fe940cb..00d00656f3da 100644--- a/products/signals/frontend/inbox/components/InboxReportList.tsx+++ b/products/signals/frontend/inbox/components/InboxReportList.tsx@@ -4,7 +4,7 @@ import { ComponentType, JSX, useEffect, useRef } from 'react'import { captureInboxReportsImpressed, captureInboxViewed } from '../inboxAnalytics'import { inboxSceneLogic } from '../inboxSceneLogic'import { inboxFiltersLogic } from '../logics/inboxFiltersLogic'-import { reportListLogic, ReportListLogicProps } from '../logics/reportListLogic'+import { INBOX_FLAT_TAB_LIST_PARAMS, reportListLogic, ReportListLogicProps } from '../logics/reportListLogic'import { InboxFlatListTabKey, SignalReport } from '../types'import { DismissalReasonValue } from '../utils/dismissalReasons'import { CardSkeleton } from './cards/CardSkeleton'@@ -55,22 +55,52 @@ function InboxReportListInner({ tabKey, Card, emptyState }: InboxReportListPropsconst listVisible = !selectedReportId && !selectedScoutSkillName && !isScratchpadOpen && !isFindingsOpenconst sentinelRef = useRef<HTMLDivElement>(null)- // Fire `Inbox viewed` once per tab mount, the first time its list settles while visible.+ // The Pull requests / Reports badge counts go on every `Inbox viewed`, whatever tab is open: the+ // active tab's `total_count` alone says nothing about a user who lands on Pull requests and has+ // 200 reports waiting. These share the tab bar's keyed instances, so no extra requests.+ const { count: pullsTabCount, countLoading: pullsTabCountLoading } = useValues(+ reportListLogic({ tabKey: 'pulls', listParams: INBOX_FLAT_TAB_LIST_PARAMS.pulls })+ )+ const { count: reportsTabCount, countLoading: reportsTabCountLoading } = useValues(+ reportListLogic({ tabKey: 'reports', listParams: INBOX_FLAT_TAB_LIST_PARAMS.reports })+ )+ // A badge count is settled once its request is no longer in flight: loaded, refreshed, or failed+ // (count stays null). Waiting on the loading flags rather than non-null values means a scope or+ // filter refresh in progress doesn't fire the event with the previous query's counts.+ const badgeCountsSettled = !pullsTabCountLoading && !reportsTabCountLoading++ // Fire `Inbox viewed` once per tab mount, the first time its list and the badge counts settle+ // while visible.const viewedFiredRef = useRef(false)useEffect(() => {- if (listVisible && isLoaded && count !== null && !viewedFiredRef.current) {+ if (listVisible && isLoaded && count !== null && badgeCountsSettled && !viewedFiredRef.current) {viewedFiredRef.current = truecaptureInboxViewed({tab: tabKey,reports,totalCount: count,+ pullsTabCount,+ reportsTabCount,hasActiveFilters,sourceProductFilter,priorityFilter,scope,})}- }, [listVisible, isLoaded, count, reports, tabKey, hasActiveFilters, sourceProductFilter, priorityFilter, scope])+ }, [+ listVisible,+ isLoaded,+ count,+ badgeCountsSettled,+ pullsTabCount,+ reportsTabCount,+ reports,+ tabKey,+ hasActiveFilters,+ sourceProductFilter,+ priorityFilter,+ scope,+ ])// Impression log for ranking-model training: record each report the first time it appears in// the visible list (initial page, pagination, refresh), with its rank at that moment. Dedupeddiff --git a/products/signals/frontend/inbox/inboxAnalytics.test.ts b/products/signals/frontend/inbox/inboxAnalytics.test.tsindex 22601be1383e..1e74fa805cb7 100644--- a/products/signals/frontend/inbox/inboxAnalytics.test.ts+++ b/products/signals/frontend/inbox/inboxAnalytics.test.ts@@ -50,6 +50,8 @@ describe('inboxAnalytics', () => {tab: 'reports',reports: [],totalCount: 0,+ pullsTabCount: 3,+ reportsTabCount: 212,hasActiveFilters: false,sourceProductFilter: [],priorityFilter: [],@@ -58,6 +60,26 @@ describe('inboxAnalytics', () => {expect(lastCapture(INBOX_EVENTS.VIEWED)?.inbox_client).toBe('cloud')})+ it('carries the tab badge counts regardless of the active tab', () => {+ captureInboxViewed({+ tab: 'pulls',+ reports: [],+ totalCount: 0,+ pullsTabCount: 0,+ reportsTabCount: 212,+ hasActiveFilters: false,+ sourceProductFilter: [],+ priorityFilter: [],+ scope: 'for-you',+ })+ expect(lastCapture(INBOX_EVENTS.VIEWED)).toMatchObject({+ tab: 'pulls',+ total_count: 0,+ pulls_tab_count: 0,+ reports_tab_count: 212,+ })+ })+it('breaks the visible reports down by priority and actionability', () => {captureInboxViewed({tab: 'reports',@@ -67,6 +89,8 @@ describe('inboxAnalytics', () => {makeReport({ id: 'c', priority: null, actionability: null }),],totalCount: 3,+ pullsTabCount: 1,+ reportsTabCount: 3,hasActiveFilters: true,sourceProductFilter: ['error_tracking'],priorityFilter: ['P0'],diff --git a/products/signals/frontend/inbox/inboxAnalytics.ts b/products/signals/frontend/inbox/inboxAnalytics.tsindex 8d0ede8ba782..48442fc53fb5 100644--- a/products/signals/frontend/inbox/inboxAnalytics.ts+++ b/products/signals/frontend/inbox/inboxAnalytics.ts@@ -226,10 +226,19 @@ export function captureInboxWelcomeCommandCopied(params: {})}+/**+ * The report list settled for the first time in a tab mount. `report_count` / `total_count` describe+ * the active tab's list only (and `report_count` is capped at the loaded page), so the headline+ * "how many reports does this user have" numbers are `pulls_tab_count` / `reports_tab_count`: the tab badge+ * counts, sent on every view regardless of which tab is open (same shape as the desktop event).+ * A badge count is null only if its request failed.+ */export function captureInboxViewed(params: {tab: stringreports: SignalReport[]totalCount: number+ pullsTabCount: number | null+ reportsTabCount: number | nullhasActiveFilters: booleansourceProductFilter: string[]priorityFilter: string[]@@ -239,6 +248,8 @@ export function captureInboxViewed(params: {tab: params.tab,report_count: params.reports.length,total_count: params.totalCount,+ pulls_tab_count: params.pullsTabCount,+ reports_tab_count: params.reportsTabCount,is_empty: params.totalCount === 0,has_active_filters: params.hasActiveFilters,source_product_filter: params.sourceProductFilter,