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(alerts): test a visual empty state for insight alerts (#117890)

Matt Pua935158451bd2
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 5658bd71f847..286b465bc4dd 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -6526,6 +6526,26 @@ snapshots:
hash: v1.k794b7964.a40d931748bcafd0f7c04fc6c49b822be8354406f51a94a8dacf611bac3d2427.HPAk17TcKxsIPc0G2y4gKdrKfvDF-ZxS4UWiWi_RLSY
products-alerts-alerts-scene--log-alerts--light:
hash: v1.k794b7964.202760c4cc733d6ef4fee0ad7bee733d15f170e87ef01e64d481a954dcf5a0d3.8Wx10_cUTwP4fwGP183w2k8FTU7NsmgyvkPL_6_Eotg
+ products-alerts-insight-alerts-modal--empty--dark:
+ hash: v1.k794b7964.0f0c0778c21da73508d841a2f4e09f01422b1d94982a4a60ae102d302f96ac97.D1q5bt4FrGqQE6OUfMO5F4nNaDiG_Vxu_oEjvhzzb14
+ products-alerts-insight-alerts-modal--empty--light:
+ hash: v1.k794b7964.3722b2b509c00ee3f96f6a35aa9ad15e20ec42c3be80ee8410f2e2fd3650129b.IFh208FrgVDwBKT0EBP-3B_KzMg-8Q1SHm6VNCTXuQI
+ products-alerts-insight-alerts-modal--empty-control--dark:
+ hash: v1.k794b7964.fff1d6db3e25a8b6fa89c4f396b0dca40579b6eba1085c9d5924297586b64320.EVf_rkUtlNNsV7fYNxCoK1s1zGELwzjyYzSdzvjDwrM
+ products-alerts-insight-alerts-modal--empty-control--light:
+ hash: v1.k794b7964.c4d18625f5c5e2f797870c5cbb50e65da88a3e6e8075bef8aaa4649fc78fb1e3._n8dnxCdDvBtrUwN6-2EJvV_IOjV2AOHcLmdLUQ9wic
+ products-alerts-insight-alerts-modal--empty-flag-off--dark:
+ hash: v1.k794b7964.fff1d6db3e25a8b6fa89c4f396b0dca40579b6eba1085c9d5924297586b64320.Tpt9-L2R2_Y5cl-iVxsOES-Df8JLEVN4OtgyOaB8H8U
+ products-alerts-insight-alerts-modal--empty-flag-off--light:
+ hash: v1.k794b7964.c4d18625f5c5e2f797870c5cbb50e65da88a3e6e8075bef8aaa4649fc78fb1e3.yYFLbZw1G0MeoAaXhYSSXj6-JcBDpzpL6M5u_Sqo2P8
+ products-alerts-insight-alerts-modal--empty-narrow--dark:
+ hash: v1.k794b7964.efce5ffbb6f7f80fea4dc6e3a4d512eba095344f1318b56accdb819f6b6ed8c6.jSjUnUvdZtbepmI32kI7L53FA3DQXTucHsvd7y_ZMME
+ products-alerts-insight-alerts-modal--empty-narrow--light:
+ hash: v1.k794b7964.e56a1bc4d682f0b4e3f84b7e9504353499a4ea429645e007f2525fe914ba5d10.7cfQoYu9-ro1Mf-N9fA-_f8x-jskMQWSRAq6E1eNfDk
+ products-alerts-insight-alerts-modal--empty-unsupported--dark:
+ hash: v1.k794b7964.1814935f8e4879f6056f7d19c4754e6d79a99325639c7eec9c059ec91c6a08ba.Es8a_KuDgrfZdaL9k_xw7W56iHVCrSPc6uyU5Fbq-58
+ products-alerts-insight-alerts-modal--empty-unsupported--light:
+ hash: v1.k794b7964.97364191b9e9d18e7a7352b01d42f11e49c94aa921dfc4286284a684990ebbbb.kdwi90l7mCL-a_e_Mgmh2LTLN_CnyOdN-6N4Bkc2Msk
products-alerts-insight-alerts-modal--with-alerts--dark:
hash: v1.k794b7964.58e1c24a162fa9e4fa4c8040adc4a298d0d4275a27aa96f7e4a9e84a2cd5e6b8.9JDfMApDsxe7KaTt42TDrSuqjvHOURRf64Bp3lWHCNc
products-alerts-insight-alerts-modal--with-alerts--light:
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx
index 8b0b0c917dd4..97be953b9e45 100644
--- a/frontend/src/lib/constants.tsx
+++ b/frontend/src/lib/constants.tsx
@@ -381,6 +381,7 @@ export const FEATURE_FLAGS = {
INBOX_SELF_DRIVING_EMPTY_STATE: 'inbox-self-driving-empty-state',
INBOX_SLACK_NOTIFICATIONS: 'inbox-slack-notifications', // owner: #team-self-driving, gates the Slack notifications config card in the inbox
INBOX_TIME_WINDOW: 'inbox-time-window', // owner: #team-self-driving, gates the created-in window filter on the inbox report list
+ INSIGHT_ALERTS_EMPTY_STATE_EXPERIMENT: 'insight-alerts-empty-state',
INSIGHT_DRAG_TO_ZOOM: 'insight-drag-to-zoom', // owner: @sampennington #team-product-analytics, gates x-axis drag-to-zoom on insight charts (trends today, SQL to follow)
INSIGHT_EXPORT_NUDGE: 'insight-export-nudge', // owner: #team-analytics-platform multivariate=control,test, nudges people who just exported an insight toward a recurring subscription
INSIGHT_SUBSCRIBE_PROMINENT_BUTTON: 'insight-subscribe-prominent-button', // owner: @mattp #team-analytics-platform multivariate=control,test
diff --git a/products/alerts/frontend/views/InsightAlertPreview.tsx b/products/alerts/frontend/views/InsightAlertPreview.tsx
new file mode 100644
index 000000000000..93c5f7808e78
--- /dev/null
+++ b/products/alerts/frontend/views/InsightAlertPreview.tsx
@@ -0,0 +1,50 @@
+import { IconSlack } from 'lib/lemon-ui/icons'
+import { LemonCard } from 'lib/lemon-ui/LemonCard'
+import { cn } from 'lib/utils/css-classes'
+
+export function InsightAlertPreview({ className }: { className?: string }): JSX.Element {
+ return (
+ <div className={cn('text-left', className)}>
+ <LemonCard hoverEffect={false} className="p-4">
+ <div className="text-sm mb-3">
+ <div className="font-semibold">Daily signups</div>
+ <div className="text-xs text-muted">Example insight</div>
+ </div>
+ <svg
+ viewBox="0 0 400 120"
+ className="w-full h-20"
+ role="img"
+ aria-label="Example: daily signups fall below a threshold of 100 and trigger an alert."
+ >
+ <path d="M0 20H400 M0 60H400 M0 100H400" fill="none" className="stroke-border" />
+ <path d="M0 72H400" fill="none" className="stroke-warning" strokeDasharray="6 5" />
+ <text x="4" y="65" className="fill-muted" fontSize="11">
+ Threshold: 100
+ </text>
+ <path
+ d="M0 38L28 32L56 42L84 24L112 33L140 28L168 41L196 30L224 38L252 25L280 35L308 43L336 85L364 91L392 98"
+ fill="none"
+ className="stroke-accent"
+ strokeWidth="3"
+ strokeLinejoin="round"
+ strokeLinecap="round"
+ />
+ <circle cx="336" cy="85" r="6" className="fill-warning stroke-surface-primary" strokeWidth="3" />
+ </svg>
+ <div className="border-t pt-3 mt-2">
+ <div className="text-sm space-y-2">
+ <div className="flex items-center gap-2 font-semibold">
+ <IconSlack className="w-4 h-4 shrink-0" />
+ <span>PostHog</span>
+ </div>
+ <div className="border-l-2 border-warning pl-3 space-y-1">
+ <div className="font-semibold">Signups fell below 100</div>
+ <div>72 signups (lower threshold: 100)</div>
+ <div className="text-link">View insight →</div>
+ </div>
+ </div>
+ </div>
+ </LemonCard>
+ </div>
+ )
+}
diff --git a/products/alerts/frontend/views/ManageAlertsModal.stories.tsx b/products/alerts/frontend/views/ManageAlertsModal.stories.tsx
index 32965f26164e..a54d960de530 100644
--- a/products/alerts/frontend/views/ManageAlertsModal.stories.tsx
+++ b/products/alerts/frontend/views/ManageAlertsModal.stories.tsx
@@ -1,5 +1,7 @@
import type { Meta, StoryObj } from '@storybook/react'
+import { FEATURE_FLAGS } from 'lib/constants'
+
import {
AlertCalculationInterval,
AlertConditionType,
@@ -96,6 +98,7 @@ const meta: Meta<typeof ManageAlertsModal> = {
layout: 'fullscreen',
viewMode: 'story',
mockDate: '2026-07-16',
+ featureFlags: { [FEATURE_FLAGS.INSIGHT_ALERTS_EMPTY_STATE_EXPERIMENT]: 'test' },
testOptions: { viewport: { width: 1000, height: 700 } },
},
args: {
@@ -125,3 +128,32 @@ export default meta
type Story = StoryObj<typeof meta>
export const WithAlerts: Story = {}
+
+export const Empty: Story = {
+ args: {
+ insightLogicProps: {
+ ...meta.args!.insightLogicProps!,
+ cachedInsight: { ...meta.args!.insightLogicProps!.cachedInsight!, alerts: [] },
+ },
+ },
+}
+
+export const EmptyUnsupported: Story = {
+ ...Empty,
+ args: { ...Empty.args, canCreateAlertForInsight: false },
+}
+
+export const EmptyNarrow: Story = {
+ ...Empty,
+ parameters: { testOptions: { viewport: { width: 560, height: 800 } } },
+}
+
+export const EmptyControl: Story = {
+ ...Empty,
+ parameters: { featureFlags: { [FEATURE_FLAGS.INSIGHT_ALERTS_EMPTY_STATE_EXPERIMENT]: 'control' } },
+}
+
+export const EmptyFlagOff: Story = {
+ ...Empty,
+ parameters: { featureFlags: { [FEATURE_FLAGS.INSIGHT_ALERTS_EMPTY_STATE_EXPERIMENT]: false } },
+}
diff --git a/products/alerts/frontend/views/ManageAlertsModal.test.tsx b/products/alerts/frontend/views/ManageAlertsModal.test.tsx
new file mode 100644
index 000000000000..a0ca389496f6
--- /dev/null
+++ b/products/alerts/frontend/views/ManageAlertsModal.test.tsx
@@ -0,0 +1,66 @@
+import '@testing-library/jest-dom'
+
+import { cleanup, fireEvent, render, screen } from '@testing-library/react'
+import { Provider } from 'kea'
+import posthog from 'posthog-js'
+
+import { FEATURE_FLAGS } from 'lib/constants'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+import { createEmptyInsight } from 'scenes/insights/insightLogic'
+
+import { InsightVizNode, NodeKind } from '~/queries/schema/schema-general'
+import { initKeaTests } from '~/test/init'
+import { InsightShortId } from '~/types'
+
+import { ManageAlertsModal } from './ManageAlertsModal'
+
+describe('ManageAlertsModal', () => {
+ afterEach(() => {
+ cleanup()
+ jest.restoreAllMocks()
+ })
+
+ it('allows alert creation before feature flags arrive without recording experiment exposure', () => {
+ jest.spyOn(posthog, 'onFeatureFlags').mockImplementation(() => () => {})
+ initKeaTests()
+ const capture = jest.spyOn(posthog, 'capture')
+ const onCreateAlert = jest.fn()
+ const insightShortId = 'alert-qa' as InsightShortId
+ const query: InsightVizNode = {
+ kind: NodeKind.InsightVizNode,
+ source: { kind: NodeKind.TrendsQuery, series: [] },
+ }
+
+ render(
+ <Provider>
+ <ManageAlertsModal
+ isOpen
+ insightId={42}
+ insightShortId={insightShortId}
+ canCreateAlertForInsight
+ onCreateAlert={onCreateAlert}
+ insightLogicProps={{
+ dashboardItemId: insightShortId,
+ cachedInsight: {
+ ...createEmptyInsight(insightShortId),
+ id: 42,
+ alerts: [],
+ query,
+ },
+ }}
+ />
+ </Provider>
+ )
+
+ expect(featureFlagLogic.values.receivedFeatureFlags).toBe(false)
+ expect(screen.getByText('There are no alerts for this insight')).toBeInTheDocument()
+ const createButton = screen.getByText('New alert')
+ expect(createButton.closest('button')).toBeEnabled()
+ fireEvent.click(createButton)
+ expect(onCreateAlert).toHaveBeenCalledTimes(1)
+ expect(capture).not.toHaveBeenCalledWith(
+ '$feature_flag_called',
+ expect.objectContaining({ $feature_flag: FEATURE_FLAGS.INSIGHT_ALERTS_EMPTY_STATE_EXPERIMENT })
+ )
+ })
+})
diff --git a/products/alerts/frontend/views/ManageAlertsModal.tsx b/products/alerts/frontend/views/ManageAlertsModal.tsx
index 2d9256c9ce69..c0967d35d61b 100644
--- a/products/alerts/frontend/views/ManageAlertsModal.tsx
+++ b/products/alerts/frontend/views/ManageAlertsModal.tsx
@@ -3,10 +3,13 @@ import { router } from 'kea-router'
import { Link } from '@posthog/lemon-ui'
+import { ProductIntroduction } from 'lib/components/ProductIntroduction/ProductIntroduction'
import { UserActivityIndicator } from 'lib/components/UserActivityIndicator/UserActivityIndicator'
+import { FEATURE_FLAGS } from 'lib/constants'
import { LemonButton } from 'lib/lemon-ui/LemonButton'
import { LemonModal } from 'lib/lemon-ui/LemonModal'
import { Spinner } from 'lib/lemon-ui/Spinner'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { pluralize } from 'lib/utils/strings'
import { urls } from 'scenes/urls'
@@ -17,6 +20,7 @@ import { buildAlertSummary } from '../components/alertSummary'
import { AlertSummaryBanner } from '../components/AlertSummaryBanner'
import { InsightAlertsLogicProps, alertsUnsupportedReason, insightAlertsLogic } from '../logic/insightAlertsLogic'
import { AlertType } from '../types'
+import { InsightAlertPreview } from './InsightAlertPreview'
interface AlertListItemProps {
alert: AlertType
@@ -69,7 +73,17 @@ export function ManageAlertsModal(props: ManageAlertsModalProps): JSX.Element {
const { alerts, alertsLoading, alertDestinationCounts, alertDestinationCountsLoading } = useValues(logic)
- const showDeferredListSpinner = props.deferInitialAlertsLoad && props.isOpen && alertsLoading
+ const { featureFlags, receivedFeatureFlags } = useValues(featureFlagLogic)
+ const isEmpty = alerts.length === 0
+ const isExperimentEligible = props.isOpen && !alertsLoading && isEmpty && props.canCreateAlertForInsight
+ const showListSpinner = props.isOpen && alertsLoading
+ const showVisualEmptyState =
+ isExperimentEligible &&
+ receivedFeatureFlags &&
+ featureFlags[FEATURE_FLAGS.INSIGHT_ALERTS_EMPTY_STATE_EXPERIMENT] === 'test'
+ const createAlertDisabledReason = !props.canCreateAlertForInsight
+ ? alertsUnsupportedReason({}, props.insightQuery)
+ : undefined
const openAlert = (alertId: AlertType['id']): void => {
if (props.onEditAlert) {
props.onClose?.()
@@ -92,23 +106,26 @@ export function ManageAlertsModal(props: ManageAlertsModalProps): JSX.Element {
return (
<LemonModal onClose={props.onClose} isOpen={props.isOpen} width={600} simple title="">
<LemonModal.Header>
- <h3 className="!m-0">Manage Alerts</h3>
+ <h3 className="!m-0">Manage alerts</h3>
</LemonModal.Header>
<LemonModal.Content>
- <div className="mb-4">
- With alerts, PostHog monitors your insight at a recurring interval and notifies you when conditions
- are met.
- <br />
- <Link to={urls.alerts()} target="_blank">
- View all your alerts here
- </Link>
- </div>
-
- {showDeferredListSpinner ? (
+ {!showVisualEmptyState && (
+ <div className="mb-4">
+ With alerts, PostHog monitors your insight at a recurring interval and notifies you when
+ conditions are met.
+ <br />
+ <Link to={urls.alerts()} target="_blank">
+ View all your alerts here
+ </Link>
+ </div>
+ )}
+
+ {showListSpinner ? (
<div className="flex justify-center p-8">
<Spinner />
</div>
- ) : alerts.length ? (
+ ) : null}
+ {!showListSpinner && alerts.length > 0 && (
<div className="deprecated-space-y-2">
<div>
<strong>{alerts?.length}</strong> {pluralize(alerts.length || 0, 'alert', 'alerts', false)}
@@ -124,28 +141,58 @@ export function ManageAlertsModal(props: ManageAlertsModalProps): JSX.Element {
/>
))}
</div>
- ) : (
+ )}
+ {!showListSpinner && isEmpty && !showVisualEmptyState && (
<div className="flex flex-col p-4 items-center text-center">
<h3>There are no alerts for this insight</h3>
-
- <p>Once alerts are created they will display here. </p>
+ <p>Once alerts are created they will display here.</p>
</div>
)}
+ {showVisualEmptyState && (
+ <ProductIntroduction
+ thingName="alert"
+ titleOverride="Get notified when it matters"
+ description="Catch drops in signups, conversion, or usage."
+ customHog={InsightAlertPreview}
+ hogLayout="vertical"
+ hogClassName="w-full sm:w-full lg:w-full max-w-96 mb-0"
+ className="border-0 p-0 m-0"
+ contentClassName="max-w-full"
+ actionElementOverride={
+ <LemonButton
+ type="primary"
+ onClick={createAlert}
+ disabledReason={createAlertDisabledReason}
+ data-attr="insight-empty-state-new-alert"
+ >
+ New alert
+ </LemonButton>
+ }
+ docsURL="https://posthog.com/docs/alerts"
+ />
+ )}
</LemonModal.Content>
<LemonModal.Footer>
+ {showVisualEmptyState && (
+ <LemonButton type="tertiary" to={urls.alerts()} targetBlank className="mr-auto">
+ View all alerts
+ </LemonButton>
+ )}
<LemonButton type="secondary" onClick={props.onClose}>
Close
</LemonButton>
- <LemonButton
- type="primary"
- onClick={createAlert}
- disabledReason={
- !props.canCreateAlertForInsight ? alertsUnsupportedReason({}, props.insightQuery) : undefined
- }
- >
- New alert
- </LemonButton>
+ {!showVisualEmptyState && (
+ <LemonButton
+ type="primary"
+ onClick={createAlert}
+ disabledReason={createAlertDisabledReason}
+ loading={showListSpinner}
+ data-attr={isEmpty ? 'insight-empty-state-new-alert' : undefined}
+ >
+ New alert
+ </LemonButton>
+ )}
</LemonModal.Footer>
</LemonModal>
)