Skip to content

: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.

feat(insights): clearer data checks copy, loading state and analytics (#121511)

Sam Pennington222a7205c3a0
diff --git a/products/product_analytics/frontend/insights/dataChecks/DataChecksPopover.tsx b/products/product_analytics/frontend/insights/dataChecks/DataChecksPopover.tsx
index c65a2be83ac7..6252c415a2de 100644
--- a/products/product_analytics/frontend/insights/dataChecks/DataChecksPopover.tsx
+++ b/products/product_analytics/frontend/insights/dataChecks/DataChecksPopover.tsx
@@ -1,7 +1,7 @@
import { useActions, useMountedLogic, useValues } from 'kea'
import { useId } from 'react'
-import { Accordion, Button, Dot, Popover, PopoverContent, PopoverTrigger, Text } from '@posthog/quill'
+import { Accordion, Button, Popover, PopoverContent, PopoverTrigger, Skeleton, Spinner, Text } from '@posthog/quill'
import { humanFriendlyNumber } from 'lib/utils/numbers'
import { pluralize } from 'lib/utils/strings'
@@ -47,7 +47,7 @@ export interface DataChecksPopoverProps {
export function DataChecksPopover({ insightProps, trigger, children }: DataChecksPopoverProps): JSX.Element {
const logic = insightDataChecksLogic(insightProps)
const { visibleChecks, checkedQuery, result, status } = useValues(logic)
- const { loadDataChecks, reportDataChecksViewed } = useActions(logic)
+ const { loadDataChecks, reportButtonClicked, reportDataChecksViewed } = useActions(logic)
const { user } = useValues(userLogic)
const userId = user?.uuid ?? ''
// Mounted outside the popover content, so a half-written note survives the popover closing.
@@ -86,11 +86,16 @@ export function DataChecksPopover({ insightProps, trigger, children }: DataCheck
{Object.entries(DATA_CHECK_NAMES).map(([key, name]) => (
<li key={key} className="flex items-start gap-2 px-2 py-1">
<span className="flex h-5 w-4 shrink-0 items-center justify-center">
- <Dot variant="default" pulse />
+ <Spinner aria-hidden className="text-(--muted-foreground)" />
+ </span>
+ <span className="flex flex-col">
+ <Text size={null} weight="medium" render={<span />}>
+ {name}
+ </Text>
+ <span className="flex h-4 items-center">
+ <Skeleton className="h-2.5 w-28" />
+ </span>
</span>
- <Text size={null} variant="muted" render={<span />}>
- {name}
- </Text>
</li>
))}
</ul>
@@ -104,7 +109,12 @@ export function DataChecksPopover({ insightProps, trigger, children }: DataCheck
variant="outline"
size="sm"
className="self-start"
- onClick={() => checkedQuery && loadDataChecks(checkedQuery)}
+ onClick={() => {
+ reportButtonClicked('retry')
+ if (checkedQuery) {
+ loadDataChecks(checkedQuery)
+ }
+ }}
data-attr="insight-data-checks-retry"
>
Try again
diff --git a/products/product_analytics/frontend/insights/dataChecks/DuplicateEventsDetails.tsx b/products/product_analytics/frontend/insights/dataChecks/DuplicateEventsDetails.tsx
index 559ca674e0cb..3054949fd42b 100644
--- a/products/product_analytics/frontend/insights/dataChecks/DuplicateEventsDetails.tsx
+++ b/products/product_analytics/frontend/insights/dataChecks/DuplicateEventsDetails.tsx
@@ -1,4 +1,4 @@
-import { useValues } from 'kea'
+import { useActions, useValues } from 'kea'
import { Button, Text } from '@posthog/quill'
@@ -21,7 +21,9 @@ export function DuplicateEventsDetails({
insightProps: InsightLogicProps
check: InsightDataCheckApi
}): JSX.Element {
- const { lastResult } = useValues(insightDataChecksLogic(insightProps))
+ const logic = insightDataChecksLogic(insightProps)
+ const { lastResult } = useValues(logic)
+ const { reportButtonClicked } = useActions(logic)
const coverage = lastResult?.coverage
const text = repeatedEventsTextOf(check)
const repeatedEventsUrl =
@@ -35,13 +37,15 @@ export function DuplicateEventsDetails({
}),
})
return (
- <div className="flex flex-col items-start gap-1.5">
- <Text size="xs" variant="muted">
- {text.found}
- </Text>
- <Text size="xs" variant="muted">
- {text.causes}
- </Text>
+ <div className="flex flex-col items-start gap-3">
+ <div className="flex flex-col gap-1.5">
+ <Text size="xs" variant="muted">
+ {text.found}
+ </Text>
+ <Text size="xs" variant="muted">
+ {text.causes}
+ </Text>
+ </div>
<div className="flex flex-wrap gap-2">
{repeatedEventsUrl && (
<Button
@@ -49,6 +53,7 @@ export function DuplicateEventsDetails({
size="sm"
className="no-underline"
render={<LinkPrimitive to={repeatedEventsUrl} target="_blank" />}
+ onClick={() => reportButtonClicked('see_repeated_events', check.key)}
data-attr="insight-data-check-see-repeated-events"
>
See these events
diff --git a/products/product_analytics/frontend/insights/dataChecks/ExcludeFromFilterButton.tsx b/products/product_analytics/frontend/insights/dataChecks/ExcludeFromFilterButton.tsx
index 2359d9a58e91..d82e2456eaaf 100644
--- a/products/product_analytics/frontend/insights/dataChecks/ExcludeFromFilterButton.tsx
+++ b/products/product_analytics/frontend/insights/dataChecks/ExcludeFromFilterButton.tsx
@@ -10,6 +10,7 @@ import {
AlertDialogTitle,
AlertDialogTrigger,
Button,
+ Text,
} from '@posthog/quill'
import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
@@ -34,7 +35,7 @@ export function ExcludeFromFilterButton({
}): JSX.Element {
const logic = insightDataChecksLogic(insightProps)
const { currentTeamLoading } = useValues(logic)
- const { addFilterRule } = useActions(logic)
+ const { addFilterRule, reportButtonClicked } = useActions(logic)
const rule = check.filter_to_add
if (!rule) {
@@ -49,6 +50,7 @@ export function ExcludeFromFilterButton({
target="_blank"
/>
}
+ onClick={() => reportButtonClicked('edit_filter', check.key)}
data-attr="insight-data-check-filter-settings"
>
Edit filter
@@ -73,6 +75,7 @@ export function ExcludeFromFilterButton({
? undefined
: 'Only project admins can change the internal and test users filter.'
}
+ onClick={() => reportButtonClicked('add_filter_rule', check.key)}
data-attr="insight-data-check-add-filter-rule"
/>
}
@@ -91,10 +94,21 @@ export function ExcludeFromFilterButton({
<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>
<AlertDialogClose
- render={<Button variant="primary" onClick={() => addFilterRule(check)} />}
+ render={
+ <Button
+ variant="primary"
+ onClick={() => {
+ reportButtonClicked('add_filter_rule_confirm', check.key)
+ addFilterRule(check)
+ }}
+ />
+ }
data-attr="insight-data-check-add-filter-rule-confirm"
>
Add rule
diff --git a/products/product_analytics/frontend/insights/dataChecks/ExcludeFromInsightButton.tsx b/products/product_analytics/frontend/insights/dataChecks/ExcludeFromInsightButton.tsx
index fe3bd658a42f..153c7caa218c 100644
--- a/products/product_analytics/frontend/insights/dataChecks/ExcludeFromInsightButton.tsx
+++ b/products/product_analytics/frontend/insights/dataChecks/ExcludeFromInsightButton.tsx
@@ -18,7 +18,7 @@ export function ExcludeFromInsightButton({
}): JSX.Element | null {
const logic = insightDataChecksLogic(insightProps)
const { querySource, status } = useValues(logic)
- const { excludeFromInsight } = useActions(logic)
+ const { excludeFromInsight, reportButtonClicked } = useActions(logic)
if (!check.filter_to_add) {
return null
@@ -35,7 +35,10 @@ export function ExcludeFromInsightButton({
? undefined
: "This insight's filters use OR groups. Add the rule in the insight's filters instead."
}
- onClick={() => excludeFromInsight(check)}
+ onClick={() => {
+ reportButtonClicked('exclude_from_insight', check.key)
+ excludeFromInsight(check)
+ }}
data-attr="insight-data-check-exclude-from-insight"
>
Exclude from this insight
diff --git a/products/product_analytics/frontend/insights/dataChecks/FilterCheckDetails.tsx b/products/product_analytics/frontend/insights/dataChecks/FilterCheckDetails.tsx
index 3729ea9898ac..4955a03b1b43 100644
--- a/products/product_analytics/frontend/insights/dataChecks/FilterCheckDetails.tsx
+++ b/products/product_analytics/frontend/insights/dataChecks/FilterCheckDetails.tsx
@@ -26,7 +26,7 @@ export function FilterCheckDetails({
}): JSX.Element {
const logic = insightDataChecksLogic(insightProps)
const { filtersTestAccounts, filterRemovesBots, queryFiltersTestAccounts } = useValues(logic)
- const { setFiltersTestAccounts } = useActions(logic)
+ const { setFiltersTestAccounts, reportButtonClicked } = useActions(logic)
const { caught, missed } = filterCheckParts(check, filtersTestAccounts, filterRemovesBots)
const canEditFilter = !useRestrictedArea({
scope: RestrictionScope.Project,
@@ -46,18 +46,26 @@ export function FilterCheckDetails({
id="insight-data-check-test-account-filter"
size="small"
checked={queryFiltersTestAccounts}
- onChange={(checked) => setFiltersTestAccounts(checked, check.key)}
+ onChange={(checked) => {
+ reportButtonClicked(
+ checked ? 'filter_internal_users_on' : 'filter_internal_users_off',
+ check.key
+ )
+ setFiltersTestAccounts(checked, check.key)
+ }}
settingsLinkIcon="new-tab"
data-attr="insight-data-check-filter-internal-users"
/>
</div>
{missed && (
- <div className="flex flex-col items-start gap-1.5">
+ <div className="flex flex-col items-start gap-3">
<NotCaughtByFilter
count={missed.count}
noun={missed.noun}
examples={missed.examples}
fallback={missed.fallback}
+ predicate={missed.predicate}
+ explanation={missed.explanation}
/>
<div className="flex flex-wrap gap-2">
<ExcludeFromFilterButton
diff --git a/products/product_analytics/frontend/insights/dataChecks/FixWithPostHogAIButton.tsx b/products/product_analytics/frontend/insights/dataChecks/FixWithPostHogAIButton.tsx
index b44e679313c7..79f0556451aa 100644
--- a/products/product_analytics/frontend/insights/dataChecks/FixWithPostHogAIButton.tsx
+++ b/products/product_analytics/frontend/insights/dataChecks/FixWithPostHogAIButton.tsx
@@ -18,13 +18,16 @@ export function FixWithPostHogAIButton({
}): JSX.Element {
const logic = insightDataChecksLogic(insightProps)
const { postHogAIOpen } = useValues(logic)
- const { fixWithPostHogAI } = useActions(logic)
+ const { fixWithPostHogAI, reportButtonClicked } = useActions(logic)
return (
<Button
variant="outline"
size="sm"
disabledReason={postHogAIOpen ? 'PostHog AI is already open' : undefined}
- onClick={() => fixWithPostHogAI(check)}
+ onClick={() => {
+ reportButtonClicked('fix_with_posthog_ai', check.key)
+ fixWithPostHogAI(check)
+ }}
data-attr="insight-data-check-fix-with-ai"
>
<IconSparkles />
diff --git a/products/product_analytics/frontend/insights/dataChecks/InsightDataCheckRow.tsx b/products/product_analytics/frontend/insights/dataChecks/InsightDataCheckRow.tsx
index 89f9d8659608..dec76377d1b7 100644
--- a/products/product_analytics/frontend/insights/dataChecks/InsightDataCheckRow.tsx
+++ b/products/product_analytics/frontend/insights/dataChecks/InsightDataCheckRow.tsx
@@ -1,7 +1,7 @@
-import { useValues } from 'kea'
+import { useActions, useValues } from 'kea'
import { IconCheck, IconWarning } from '@posthog/icons'
-import { AccordionContent, AccordionItem, AccordionTrigger, Dot, Text } from '@posthog/quill'
+import { AccordionContent, AccordionItem, AccordionTrigger, Dot, Skeleton, Spinner, Text } from '@posthog/quill'
import type { InsightLogicProps } from '~/types'
@@ -47,7 +47,10 @@ export function InsightDataCheckRow({
insightProps: InsightLogicProps
check: InsightDataCheckApi
}): JSX.Element {
- const { filtersTestAccounts, status } = useValues(insightDataChecksLogic(insightProps))
+ const logic = insightDataChecksLogic(insightProps)
+ const { filtersTestAccounts, status } = useValues(logic)
+ const { reportCheckExpanded } = useActions(logic)
+ const checking = status === 'checking'
const text = dataCheckText(check, filtersTestAccounts)
const dependsOnFilter = FILTER_CHECK_KEYS.includes(check.key)
const foundRepeats = check.key === 'duplicate_events' && isFinding(check)
@@ -56,22 +59,23 @@ 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">
- <LevelIcon check={check} />
+ {checking ? <Spinner aria-hidden className="text-(--muted-foreground)" /> : <LevelIcon check={check} />}
</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">{`: ${LEVEL_LABELS[check.level]}`}</span>
- </Text>
- <Text
- size="xs"
- variant="muted"
- className={status === 'checking' ? 'animate-pulse motion-reduce:animate-none' : undefined}
- render={<span />}
- >
- {text.result}
+ <span className="sr-only">{`: ${checking ? 'Checking' : LEVEL_LABELS[check.level]}`}</span>
</Text>
+ {checking ? (
+ <span className="flex h-4 items-center">
+ <Skeleton className="h-2.5 w-28" />
+ </span>
+ ) : (
+ <Text size="xs" variant="muted" render={<span />}>
+ {text.result}
+ </Text>
+ )}
</span>
</span>
)
@@ -92,6 +96,11 @@ export function InsightDataCheckRow({
return (
<AccordionItem
value={check.key}
+ onOpenChange={(open) => {
+ if (open) {
+ reportCheckExpanded(check)
+ }
+ }}
data-attr="insight-data-check"
data-check={check.key}
data-level={check.level}
diff --git a/products/product_analytics/frontend/insights/dataChecks/NotCaughtByFilter.tsx b/products/product_analytics/frontend/insights/dataChecks/NotCaughtByFilter.tsx
index be21fbaa4c29..a7572dbdfa5d 100644
--- a/products/product_analytics/frontend/insights/dataChecks/NotCaughtByFilter.tsx
+++ b/products/product_analytics/frontend/insights/dataChecks/NotCaughtByFilter.tsx
@@ -7,42 +7,53 @@ export function NotCaughtByFilter({
noun,
examples,
fallback,
+ predicate,
+ explanation,
}: {
count: number
noun: string
examples: string[]
- /** The subject when no example can be named. */
+ /** The subject when no count is known. */
fallback: string
+ predicate: string
+ explanation: string | null
}): JSX.Element {
const others = Math.max(count - examples.length, 0)
return (
- <Text size="xs" variant="muted">
- {count > 0 && examples.length > 0 ? (
- <Tooltip>
- <TooltipTrigger
- render={
- <button
- type="button"
- className="cursor-default border-0 bg-transparent p-0 text-inherit underline decoration-dotted underline-offset-2"
- data-attr={`insight-data-check-${noun}-examples`}
- />
- }
- >
- {pluralize(count, noun)}
- </TooltipTrigger>
- <TooltipContent>
- <span className="flex flex-col">
- {examples.map((example) => (
- <span key={example}>{example}</span>
- ))}
- {others > 0 && <span>{`and ${pluralize(others, 'other')}`}</span>}
- </span>
- </TooltipContent>
- </Tooltip>
- ) : (
- <span>{fallback}</span>
+ <div className="flex flex-col gap-1.5">
+ <Text size="xs" variant="muted">
+ {count > 0 && examples.length > 0 ? (
+ <Tooltip>
+ <TooltipTrigger
+ render={
+ <button
+ type="button"
+ className="cursor-default border-0 bg-transparent p-0 text-inherit underline decoration-dotted underline-offset-2"
+ data-attr={`insight-data-check-${noun}-examples`}
+ />
+ }
+ >
+ {pluralize(count, noun)}
+ </TooltipTrigger>
+ <TooltipContent>
+ <span className="flex flex-col">
+ {examples.map((example) => (
+ <span key={example}>{example}</span>
+ ))}
+ {others > 0 && <span>{`and ${pluralize(others, 'other')}`}</span>}
+ </span>
+ </TooltipContent>
+ </Tooltip>
+ ) : (
+ <span>{count > 0 ? pluralize(count, noun) : fallback}</span>
+ )}
+ <span>{` ${predicate}`}</span>
+ </Text>
+ {explanation && (
+ <Text size="xs" variant="muted">
+ {explanation}
+ </Text>
)}
- <span>{` ${count === 1 ? "isn't" : "aren't"} caught by your internal and test users filter.`}</span>
- </Text>
+ </div>
)
}
diff --git a/products/product_analytics/frontend/insights/dataChecks/dataCheckText.test.ts b/products/product_analytics/frontend/insights/dataChecks/dataCheckText.test.ts
index 2db2c76afffd..590b69e05f24 100644
--- a/products/product_analytics/frontend/insights/dataChecks/dataCheckText.test.ts
+++ b/products/product_analytics/frontend/insights/dataChecks/dataCheckText.test.ts
@@ -46,6 +46,12 @@ describe('dataCheckText', () => {
true,
'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,
+ 'Filtered out, except 32 users',
+ ],
[
'a finding from a sample',
{ level: 'problem', events: 4000, share: 0.4, scaled: true },
@@ -84,7 +90,11 @@ describe('dataCheckText', () => {
count: 14,
noun: 'user',
- fallback: "Your team's emails",
+ fallback: 'Some users',
+ predicate: "have emails that match your team, but none of your filter's rules remove them.",
+ explanation:
+ "An email matches your team when it's on the same domain as someone in your organization, " +
+ 'or looks like a test account, such as test@ or name+qa@.',
},
},
],
@@ -121,6 +131,8 @@ describe('dataCheckText', () => {
noun: 'bot',
examples: ['Googlebot', 'Ahrefs'],
fallback: 'Bot events',
+ predicate: "aren't caught by your internal and test users filter.",
+ explanation: null,
},
},
],
diff --git a/products/product_analytics/frontend/insights/dataChecks/dataCheckText.ts b/products/product_analytics/frontend/insights/dataChecks/dataCheckText.ts
index 5b36e34208d1..c55928284b1a 100644
--- a/products/product_analytics/frontend/insights/dataChecks/dataCheckText.ts
+++ b/products/product_analytics/frontend/insights/dataChecks/dataCheckText.ts
@@ -75,7 +75,14 @@ function shareOf(check: InsightDataCheckApi, part: number): string | null {
export interface FilterCheckParts {
/** Set when the project's filter catches these events but the insight leaves the filter off. */
caught: string | null
- missed: { count: number; noun: string; examples: string[]; fallback: string } | null
+ missed: {
+ count: number
+ noun: string
+ examples: string[]
+ fallback: string
+ predicate: string
+ explanation: string | null
+ } | null
}
const NOTHING: FilterCheckParts = { caught: null, missed: null }
@@ -84,10 +91,19 @@ export function isFinding(check: InsightDataCheckApi): boolean {
return check.level === 'warning' || check.level === 'problem'
}
+function notCaught(count: number): string {
+ return `${count === 1 ? "isn't" : "aren't"} caught by your internal and test users filter.`
+}
+
+function missedUserCount(check: InsightDataCheckApi): number {
+ return check.distinct_emails ?? check.top_emails.length
+}
+
function internalUsersParts(check: InsightDataCheckApi, filtersTestAccounts: boolean): FilterCheckParts {
const removed = check.removed_by_filter
const removedPercent = removed ? shareOf(check, removed) : null
const caughtAmount = removedPercent ? `${removedPercent} of these events` : pluralize(removed ?? 0, 'event')
+ const count = missedUserCount(check)
return {
caught:
removed && !filtersTestAccounts
@@ -95,10 +111,14 @@ function internalUsersParts(check: InsightDataCheckApi, filtersTestAccounts: boo
: null,
missed: check.missed_by_filter
? {
- count: check.distinct_emails ?? check.top_emails.length,
+ count,
noun: 'user',
examples: check.top_emails,
- fallback: "Your team's emails",
+ fallback: 'Some users',
+ predicate: `${count === 1 ? 'has an email that matches' : 'have emails that match'} your team, but none of your filter's rules remove them.`,
+ explanation:
+ "An email matches your team when it's on the same domain as someone in your organization, " +
+ 'or looks like a test account, such as test@ or name+qa@.',
}
: null,
}
@@ -108,13 +128,16 @@ function localHostParts(check: InsightDataCheckApi): FilterCheckParts {
if (!isFinding(check) || !check.filter_to_add) {
return NOTHING
}
+ const count = check.distinct_hosts ?? check.top_hosts.length
return {
caught: null,
missed: {
- count: check.distinct_hosts ?? check.top_hosts.length,
+ count,
noun: 'host',
examples: check.top_hosts,
fallback: 'Localhost events',
+ predicate: notCaught(count),
+ explanation: null,
},
}
}
@@ -130,13 +153,16 @@ function botTrafficParts(
if (filterRemovesBots && !filtersTestAccounts) {
return { caught: "Your filter catches this bot traffic, but it's off for this insight.", missed: null }
}
+ const count = check.distinct_bots ?? check.top_bots.length
return {
caught: null,
missed: {
- count: check.distinct_bots ?? check.top_bots.length,
+ count,
noun: 'bot',
examples: check.top_bots,
fallback: 'Bot events',
+ predicate: notCaught(count),
+ explanation: null,
},
}
}
@@ -214,7 +240,11 @@ export function dataCheckText(check: InsightDataCheckApi, filtersTestAccounts: b
}
if (check.level === 'passed') {
if (check.key === 'internal_users' && filtersTestAccounts) {
- return { name, result: 'Filtered out' }
+ if (!check.missed_by_filter) {
+ return { name, result: 'Filtered out' }
+ }
+ const missed = missedUserCount(check)
+ return { name, result: `Filtered out, except ${missed ? pluralize(missed, 'user') : 'some users'}` }
}
return { name, result: check.events ? `Almost none (${eventCount(check)} events)` : 'None found' }
}
diff --git a/products/product_analytics/frontend/insights/dataChecks/insightDataChecksLogic.test.ts b/products/product_analytics/frontend/insights/dataChecks/insightDataChecksLogic.test.ts
index 682fa8dd5a40..b2d053791405 100644
--- a/products/product_analytics/frontend/insights/dataChecks/insightDataChecksLogic.test.ts
+++ b/products/product_analytics/frontend/insights/dataChecks/insightDataChecksLogic.test.ts
@@ -1,4 +1,5 @@
import { expectLogic } from 'kea-test-utils'
+import posthog from 'posthog-js'
import { FEATURE_FLAGS } from 'lib/constants'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
@@ -31,6 +32,12 @@ describe('insightDataChecksLogic', () => {
const cancelledQueryIds: string[] = []
let sentSources: Record<string, unknown>[]
let savedFilters: unknown[]
+ let capture: jest.SpyInstance
+
+ const loadedEvents = (): Record<string, unknown>[] =>
+ capture.mock.calls
+ .filter(([event]) => event === 'insight data checks loaded')
+ .map(([, properties]) => properties as Record<string, unknown>)
const answer =
(response: [number, Record<string, unknown>], held?: Promise<void>, onSent?: () => void) =>
@@ -50,6 +57,7 @@ describe('insightDataChecksLogic', () => {
beforeEach(() => {
dataChecks.mockReset()
+ capture = jest.spyOn(posthog, 'capture').mockImplementation(() => undefined)
sentSources = []
savedFilters = []
cancelledQueryIds.length = 0
@@ -294,6 +302,24 @@ describe('insightDataChecksLogic', () => {
expect(cancelledQueryIds).toEqual([clientQueryId])
expect(dataChecks).toHaveBeenCalledTimes(2)
expect(logic.values.status).toBe('passed')
+ expect(loadedEvents().map((properties) => properties.status)).toEqual(['cancelled', 'passed'])
+ })
+
+ it.each([
+ [
+ 'a run with findings',
+ 200,
+ { ...checksOf('warning'), checks: [{ key: 'bot_traffic', level: 'warning' }] },
+ { status: 'warning', findings: ['bot_traffic'] },
+ ],
+ ['a run the server could not finish', 500, { detail: 'No.' }, { status: 'failed', findings: [] }],
+ ['a run the person may not see', 403, { detail: 'No.' }, { status: 'unavailable', findings: [] }],
+ ])('reports how %s ended', async (_name, responseStatus, response, expected) => {
+ dataChecks.mockImplementation(answer([responseStatus, response]))
+
+ await expectLogic(logic, turnTheFlagOn).toFinishAllListeners()
+
+ expect(loadedEvents()).toEqual([{ ...expected, duration_ms: expect.any(Number) }])
})
it('turns the filter on for the insight from the checks, then checks the filtered chart', async () => {
diff --git a/products/product_analytics/frontend/insights/dataChecks/insightDataChecksLogic.ts b/products/product_analytics/frontend/insights/dataChecks/insightDataChecksLogic.ts
index 31611fd00da0..174e4351123b 100644
--- a/products/product_analytics/frontend/insights/dataChecks/insightDataChecksLogic.ts
+++ b/products/product_analytics/frontend/insights/dataChecks/insightDataChecksLogic.ts
@@ -64,6 +64,24 @@ export type DataChecksRun = { ok: true; result: InsightDataChecksApi } | { ok: f
/** `unavailable`: the checks do not apply here. `checking`: the chart or the checks are still loading. */
export type InsightDataChecksStatus = 'unavailable' | 'checking' | 'failed' | InsightDataChecksStatusEnumApi
+export type DataChecksButton =
+ | 'filter_internal_users_on'
+ | 'filter_internal_users_off'
+ | 'add_filter_rule'
+ | 'add_filter_rule_confirm'
+ | 'edit_filter'
+ | 'exclude_from_insight'
+ | 'fix_with_posthog_ai'
+ | 'see_repeated_events'
+ | 'retry'
+
+function statusOfRun(run: DataChecksRun): InsightDataChecksStatus {
+ if (run.ok) {
+ return run.result.status
+ }
+ return run.denied ? 'unavailable' : 'failed'
+}
+
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface insightDataChecksLogicValues {
featureFlags: FeatureFlagsSet // featureFlagLogic
@@ -220,6 +238,16 @@ export interface insightDataChecksLogicActions {
dataChecksRun: DataChecksRun | null
payload?: DataChecksQuery
}
+ reportButtonClicked: (
+ button: DataChecksButton,
+ check?: InsightDataCheckKeyEnumApi | null
+ ) => {
+ button: DataChecksButton
+ check: InsightDataCheckKeyEnumApi | null
+ }
+ reportCheckExpanded: (check: InsightDataCheckApi) => {
+ check: InsightDataCheckApi
+ }
reportDataChecksViewed: () => {
value: true
}
@@ -315,6 +343,11 @@ export const insightDataChecksLogic: LogicWrapper<insightDataChecksLogicType> =
}),
fixWithPostHogAI: (check: InsightDataCheckApi) => ({ check }),
excludeFromInsight: (check: InsightDataCheckApi) => ({ check }),
+ reportButtonClicked: (button: DataChecksButton, check: InsightDataCheckKeyEnumApi | null = null) => ({
+ button,
+ check,
+ }),
+ reportCheckExpanded: (check: InsightDataCheckApi) => ({ check }),
reportDataChecksViewed: true,
}),
loaders(({ cache }) => ({
@@ -444,10 +477,7 @@ export const insightDataChecksLogic: LogicWrapper<insightDataChecksLogicType> =
if (dataChecksRunLoading || !dataChecksRun || requestedQuery !== checkedQuery) {
return 'checking'
}
- if (dataChecksRun.ok) {
- return dataChecksRun.result.status
- }
- return dataChecksRun.denied ? 'unavailable' : 'failed'
+ return statusOfRun(dataChecksRun)
},
],
result: [
@@ -497,8 +527,20 @@ export const insightDataChecksLogic: LogicWrapper<insightDataChecksLogicType> =
actions.loadDataChecks(query)
}
},
+ loadDataChecks: () => {
+ cache.dataChecksStartedAt = performance.now()
+ posthog.capture('insight data checks loading')
+ },
// The query can change during a run. The chart for the new query can finish before that run does.
- loadDataChecksSuccess: async (_, breakpoint) => {
+ loadDataChecksSuccess: async ({ dataChecksRun }, breakpoint) => {
+ posthog.capture('insight data checks loaded', {
+ // A run with no result gave its slot to the chart, which checks again after it loads.
+ status: dataChecksRun ? statusOfRun(dataChecksRun) : 'cancelled',
+ duration_ms: Math.round(performance.now() - cache.dataChecksStartedAt),
+ findings: dataChecksRun?.ok
+ ? dataChecksRun.result.checks.filter(isFinding).map((check) => check.key)
+ : [],
+ })
if (!values.insightDataLoading) {
actions.checkData()
}
@@ -583,6 +625,16 @@ export const insightDataChecksLogic: LogicWrapper<insightDataChecksLogicType> =
findings: values.findings.map((check) => check.key),
})
},
+ reportCheckExpanded: ({ check }) => {
+ posthog.capture('insight data check expanded', {
+ check: check.key,
+ level: check.level,
+ status: values.status,
+ })
+ },
+ reportButtonClicked: ({ button, check }) => {
+ posthog.capture('insight data check button clicked', { button, check, status: values.status })
+ },
})),
// Also on mount, because the chart can finish loading before this logic mounts. A change such as the chart
// type can reuse the chart's result, so no chart load follows it.