: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(insights): show bots as filtered out when the project filter removes them (#122509)
Sam Pennington15457b49dca8
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex f83f345c2b7a..622b902f992b 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -13539,7 +13539,7 @@ snapshots:scenes-app-mcp-analytics--dashboard-narrow--light:hash: v1.k794b7964.36ba141b42b99daff96b384b02c0ef7ce0109fdef489bed6e22d387886383828.-igCYOpf2GyR_HwHn6iAxfW0kOnMH_YSJKQj3gx_DxUscenes-app-mcp-analytics--dashboard-with-menu-bar--dark:- hash: v1.k794b7964.3ef307c15c975d54cb85d8ead4ccce542b4dee24c7996c8c8a1309d8d70f56be.claHClKWdFbsyT2bhAUCZ6EYJQodQnj_M7LyLvhhxS8+ hash: v1.k794b7964.18c750b7bf1048e67b1f40853e6901737da009c60e24ca0308f1dccdeadc7bf2.W-i3aLu0CUPi06k_iDnZ_KqcE2GMjKb_QGpF75NOb1Uscenes-app-mcp-analytics--dashboard-with-menu-bar--light:hash: v1.k794b7964.3e6469ebbcef8b7d2599c5c7360e49229a10ba1e9cae7fdde074109bbb03b267.iAMb6riQVQgxMSVzxXelhES4Hl5fZzzuVEHoriK9wnYscenes-app-mcp-analytics--intent-clustering--dark:diff --git a/products/product_analytics/frontend/insights/dataChecks/ExcludeFromFilterButton.tsx b/products/product_analytics/frontend/insights/dataChecks/ExcludeFromFilterButton.tsxindex d82e2456eaaf..79635e8c1a3e 100644--- a/products/product_analytics/frontend/insights/dataChecks/ExcludeFromFilterButton.tsx+++ b/products/product_analytics/frontend/insights/dataChecks/ExcludeFromFilterButton.tsx@@ -88,15 +88,15 @@ export function ExcludeFromFilterButton({<AlertDialogDescription>{`Every insight that filters out internal and test users will also leave out events where ${property} is one of these:`}</AlertDialogDescription>+ <ul className="my-1 flex max-h-48 list-disc flex-col gap-1 overflow-y-auto ps-4 text-xs">+ {rule.value.map((value) => (+ <li key={value}>{value}</li>+ ))}+ </ul>+ <Text size="xs" variant="muted">+ You can change the rule later in project settings.+ </Text></AlertDialogHeader>- <ul className="m-0 flex max-h-48 flex-col gap-1 overflow-y-auto ps-4 text-xs">- {rule.value.map((value) => (- <li key={value}>{value}</li>- ))}- </ul>- <Text size="xs" variant="muted">- You can change the rule later in project settings.- </Text><AlertDialogFooter><AlertDialogClose render={<Button variant="outline" />}>Cancel</AlertDialogClose><AlertDialogClosediff --git a/products/product_analytics/frontend/insights/dataChecks/InsightDataCheckRow.tsx b/products/product_analytics/frontend/insights/dataChecks/InsightDataCheckRow.tsxindex dec76377d1b7..c516ca9e792b 100644--- a/products/product_analytics/frontend/insights/dataChecks/InsightDataCheckRow.tsx+++ b/products/product_analytics/frontend/insights/dataChecks/InsightDataCheckRow.tsx@@ -10,7 +10,7 @@ import type {InsightDataCheckLevelEnumApi,} from 'products/product_analytics/frontend/generated/api.schemas'-import { FILTER_CHECK_KEYS, dataCheckText, isFinding } from './dataCheckText'+import { FILTER_CHECK_KEYS, botsFilteredOut, dataCheckText, isFinding } from './dataCheckText'import { DuplicateEventsDetails } from './DuplicateEventsDetails'import { FilterCheckDetails } from './FilterCheckDetails'import { insightDataChecksLogic } from './insightDataChecksLogic'@@ -22,15 +22,15 @@ const LEVEL_LABELS: Record<InsightDataCheckLevelEnumApi, string> = {skipped: 'Not checked',}-function LevelIcon({ check }: { check: InsightDataCheckApi }): JSX.Element {- if (check.level === 'passed') {+function LevelIcon({ level }: { level: InsightDataCheckLevelEnumApi }): JSX.Element {+ if (level === 'passed') {return <IconCheck className="size-4 text-(--success-foreground)" />}- if (isFinding(check)) {+ if (level === 'warning' || level === 'problem') {return (<IconWarningclassName={- check.level === 'problem'+ level === 'problem'? 'size-4 text-(--destructive-foreground)': 'size-4 text-(--warning-foreground)'}@@ -48,10 +48,11 @@ export function InsightDataCheckRow({check: InsightDataCheckApi}): JSX.Element {const logic = insightDataChecksLogic(insightProps)- const { filtersTestAccounts, status } = useValues(logic)+ const { filtersTestAccounts, filterRemovesBots, status } = useValues(logic)const { reportCheckExpanded } = useActions(logic)const checking = status === 'checking'- const text = dataCheckText(check, filtersTestAccounts)+ const text = dataCheckText(check, filtersTestAccounts, filterRemovesBots)+ const level = botsFilteredOut(check, filtersTestAccounts, filterRemovesBots) ? 'passed' : check.levelconst dependsOnFilter = FILTER_CHECK_KEYS.includes(check.key)const foundRepeats = check.key === 'duplicate_events' && isFinding(check)const hasDetails = dependsOnFilter || foundRepeats@@ -59,13 +60,13 @@ export function InsightDataCheckRow({const header = (<span className="flex items-start gap-2"><span className="flex h-5 w-4 shrink-0 items-center justify-center">- {checking ? <Spinner aria-hidden className="text-(--muted-foreground)" /> : <LevelIcon check={check} />}+ {checking ? <Spinner aria-hidden className="text-(--muted-foreground)" /> : <LevelIcon level={level} />}</span><span className="flex flex-col">{/* No size of its own, so the name takes the text size that quill gives a popover. */}<Text size={null} weight="medium" render={<span />}>{text.name}- <span className="sr-only">{`: ${checking ? 'Checking' : LEVEL_LABELS[check.level]}`}</span>+ <span className="sr-only">{`: ${checking ? 'Checking' : LEVEL_LABELS[level]}`}</span></Text>{checking ? (<span className="flex h-4 items-center">diff --git a/products/product_analytics/frontend/insights/dataChecks/dataCheckText.test.ts b/products/product_analytics/frontend/insights/dataChecks/dataCheckText.test.tsindex 590b69e05f24..6500a21d5210 100644--- a/products/product_analytics/frontend/insights/dataChecks/dataCheckText.test.ts+++ b/products/product_analytics/frontend/insights/dataChecks/dataCheckText.test.ts@@ -27,45 +27,65 @@ const passed: InsightDataCheckApi = {const BOT_RULE = { key: '$virt_traffic_type', type: 'event', operator: 'is_not', value: ['AI Agent', 'Bot'] }describe('dataCheckText', () => {- it.each<[string, Partial<InsightDataCheckApi>, boolean, string]>([+ it.each<[string, Partial<InsightDataCheckApi>, boolean, boolean, string]>([['a skipped check with its reason',{ level: 'skipped', skip_reason: 'read_limit', events: null, share: null },false,+ false,'Not checked, because it would read more data than it is allowed',],['a passed check that found a few events, from a sample',{ events: 1234, share: 0.001, scaled: true },false,+ false,'Almost none (about 1,234 events)',],['internal users on an insight that filters them out',{ key: 'internal_users', method: 'counted' },true,+ false,'Filtered out',],['internal users on an insight that filters them out, with team emails the filter misses',{ key: 'internal_users', method: 'counted', missed_by_filter: 40, distinct_emails: 32 },true,+ false,'Filtered out, except 32 users',],['a finding from a sample',{ level: 'problem', events: 4000, share: 0.4, scaled: true },false,+ false,'About 40% of these events',],['a finding too small for a share',{ key: 'local_development', level: 'warning', method: 'counted', events: 60, share: 0.001 },false,+ false,'60 of these events',],- ])('words the result of %s', (_name, check, filtersTestAccounts, expected) => {- expect(dataCheckText({ ...passed, ...check }, filtersTestAccounts).result).toEqual(expected)+ [+ 'bots on an insight whose internal and test users filter removes them',+ { level: 'skipped', skip_reason: 'filtered_by_traffic_type', events: null, share: null },+ true,+ true,+ 'Filtered out',+ ],+ [+ 'bots on an insight with its own traffic type filter',+ { level: 'skipped', skip_reason: 'filtered_by_traffic_type', events: null, share: null },+ true,+ false,+ "Not checked, because this insight's filters already choose which traffic types to keep",+ ],+ ])('words the result of %s', (_name, check, filtersTestAccounts, filterRemovesBots, expected) => {+ expect(dataCheckText({ ...passed, ...check }, filtersTestAccounts, filterRemovesBots).result).toEqual(expected)})it.each<[string, Partial<InsightDataCheckApi>, boolean, boolean, FilterCheckParts]>([diff --git a/products/product_analytics/frontend/insights/dataChecks/dataCheckText.ts b/products/product_analytics/frontend/insights/dataChecks/dataCheckText.tsindex d806832dcdfe..028385dc9888 100644--- a/products/product_analytics/frontend/insights/dataChecks/dataCheckText.ts+++ b/products/product_analytics/frontend/insights/dataChecks/dataCheckText.ts@@ -53,7 +53,7 @@ const SKIP_REASONS: Record<InsightDataCheckSkipReasonEnumApi, string> = {time_limit: 'it took longer than it is allowed',memory_limit: 'it needed more memory than it is allowed',too_few_sampled_events: 'the sample has too few events',- filtered_by_traffic_type: 'this insight already filters on traffic type',+ filtered_by_traffic_type: "this insight's filters already choose which traffic types to keep",hidden_property: 'a property it reads is hidden from you',invalid_filter: "the project's internal and test users filter cannot run",on_request: 'it would read a lot of data, so it runs only in a full check',@@ -234,8 +234,25 @@ function skippedResult(check: InsightDataCheckApi): string {return reason ? `Not checked, because ${reason}` : 'Not checked'}-export function dataCheckText(check: InsightDataCheckApi, filtersTestAccounts: boolean): DataCheckText {+// The server skips the bot check whenever the insight's filters read traffic type, and cannot tell when the rule+// comes from the project's filter.+export function botsFilteredOut(+ check: InsightDataCheckApi,+ filtersTestAccounts: boolean,+ filterRemovesBots: boolean+): boolean {+ return check.skip_reason === 'filtered_by_traffic_type' && filtersTestAccounts && filterRemovesBots+}++export function dataCheckText(+ check: InsightDataCheckApi,+ filtersTestAccounts: boolean,+ filterRemovesBots: boolean+): DataCheckText {const name = DATA_CHECK_NAMES[check.key]+ if (botsFilteredOut(check, filtersTestAccounts, filterRemovesBots)) {+ return { name, result: 'Filtered out' }+ }if (check.level === 'skipped') {return { name, result: skippedResult(check) }}