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(today): show a pulse tile's details in one hover card (#119029)

Shy Alter968dad8c80a1
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx
index ecc1597cd53e..32ec6e0b9ccb 100644
--- a/frontend/src/lib/constants.tsx
+++ b/frontend/src/lib/constants.tsx
@@ -572,6 +572,7 @@ export const FEATURE_FLAGS = {
TAXONOMIC_FILTER_VALUE_SEARCH_GATING: 'taxonomic-filter-value-search-gating', // owner: @pauldambra
TEXT_CARD_WORD_ART: 'text-card-word-art', // owner: @jonmcwest, gates the word art insert button in dashboard text cards
TODAY_RAIL_NAV: 'today-rail-nav', // owner: @k11kirky, replaces the left navigation with a rail (Home, Spaces, Library, Tools) and makes the Today page the homepage
+ TODAY_PULSE_RANKING: 'today-pulse-ranking',
TODAY_REPORT_JEV: 'today-report-jev', // owner: @puemos, asks the decision model to label the problem, cause and fix in a Today report, to mark the numbers a source states, and to pick the code excerpt a finding describes
TOOLBAR_PAID_HEATMAPS: 'toolbar-paid-heatmaps', // owner: #team-web-analytics
TRACING: 'tracing', // owner: #team-apm (@jonmcwest, @frankh)
diff --git a/frontend/src/scenes/project-homepage/today/Today.scss b/frontend/src/scenes/project-homepage/today/Today.scss
index fc768898731a..cfc50bd7ad69 100644
--- a/frontend/src/scenes/project-homepage/today/Today.scss
+++ b/frontend/src/scenes/project-homepage/today/Today.scss
@@ -201,6 +201,13 @@ html[data-today-transition]::view-transition-new(root) {
white-space: nowrap;
}
+.TodayPulse__trigger {
+ display: flex;
+ flex-direction: column;
+ min-width: 0;
+ outline: none;
+}
+
.TodayPulse__link {
display: flex;
flex-direction: column;
@@ -216,9 +223,9 @@ html[data-today-transition]::view-transition-new(root) {
.TodayPulse__row {
display: flex;
- flex-wrap: wrap;
gap: 8px;
align-items: baseline;
+ min-width: 0;
}
.TodayPulse__value {
@@ -238,11 +245,10 @@ html[data-today-transition]::view-transition-new(root) {
.TodayPulse__spark {
display: block;
- flex: 0 1 64px;
- align-self: center;
- min-width: 32px;
- height: 20px;
- margin-left: 6px;
+ width: 100%;
+ max-width: 160px;
+ height: 22px;
+ margin-top: 4px;
}
.TodayHome__headingRow {
diff --git a/frontend/src/scenes/project-homepage/today/TodayChange.tsx b/frontend/src/scenes/project-homepage/today/TodayChange.tsx
new file mode 100644
index 000000000000..63095d8dfa53
--- /dev/null
+++ b/frontend/src/scenes/project-homepage/today/TodayChange.tsx
@@ -0,0 +1,19 @@
+import { type TodayTone, useTodayTonePalette } from './TodaySparkline'
+
+export function TodayChange({ change, tone }: { change: number | null; tone: TodayTone }): JSX.Element | null {
+ const palette = useTodayTonePalette()
+ if (change === null) {
+ return null
+ }
+ const rounded = Math.round(change)
+ return (
+ <span
+ className="TodayChange"
+ translate="no"
+ // eslint-disable-next-line react/forbid-dom-props
+ style={tone === 'neutral' ? undefined : { color: palette[tone] }}
+ >
+ {rounded === 0 ? '0%' : `${rounded > 0 ? '+' : '−'}${Math.abs(rounded)}%`}
+ </span>
+ )
+}
diff --git a/frontend/src/scenes/project-homepage/today/TodayPulse.tsx b/frontend/src/scenes/project-homepage/today/TodayPulse.tsx
index 2fb033acebf8..18298298e522 100644
--- a/frontend/src/scenes/project-homepage/today/TodayPulse.tsx
+++ b/frontend/src/scenes/project-homepage/today/TodayPulse.tsx
@@ -1,4 +1,4 @@
-import { useValues } from 'kea'
+import { useActions, useValues } from 'kea'
import { dayjs } from 'lib/dayjs'
import { LinkPrimitive } from 'lib/lemon-ui/Link'
@@ -10,8 +10,13 @@ import type { CurrencyCode, TrendsFilter } from '~/queries/schema/schema-general
import type { HighlightMetricApi } from 'products/today/frontend/generated/api.schemas'
+import { TodayChange } from './TodayChange'
+import { todayHighlightsLogic } from './todayHighlightsLogic'
import { todayNumber } from './todayNumbers'
-import { TodaySparkline, type TodayTone, useTodayTonePalette } from './TodaySparkline'
+import { TodayPulseCard } from './TodayPulseCard'
+import { TodayPulseHoverCard } from './TodayPulseHoverCard'
+import { pulseOpenHandlers } from './todayPulseOpenHandlers'
+import { TodaySparkline, type TodayTone } from './TodaySparkline'
const CHANGE_THRESHOLD = 3
const MIN_ABSOLUTE_CHANGE = 5
@@ -51,66 +56,60 @@ function metricFormatter(metric: HighlightMetricApi, currency: CurrencyCode): (v
return (value) => formatAggregationAxisValue(trendsFilter, value, currency)
}
-function TodayChange({ change, tone }: { change: number | null; tone: TodayTone }): JSX.Element | null {
- const palette = useTodayTonePalette()
- if (change === null) {
- return null
- }
- const rounded = Math.round(change)
- return (
- <span
- className="TodayChange"
- translate="no"
- // eslint-disable-next-line react/forbid-dom-props
- style={tone === 'neutral' ? undefined : { color: palette[tone] }}
- >
- {rounded === 0 ? '0%' : `${rounded > 0 ? '+' : '−'}${Math.abs(rounded)}%`}
- </span>
- )
-}
-
export function TodayPulse({ metrics }: { metrics: HighlightMetricApi[] }): JSX.Element {
const { baseCurrency } = useValues(teamLogic)
+ const { pulseMetricOpened, pulseMetricPreviewed } = useActions(todayHighlightsLogic)
return (
<ul className="TodayPulse" aria-label="Key numbers, against the period before">
- {metrics.map((metric) => {
+ {metrics.map((metric, position) => {
const isInsight = metric.key.startsWith('insight:')
const tone = isInsight ? 'neutral' : metricTone(metric.change_pct, metric.value)
- const formatValue = metricFormatter(metric, baseCurrency)
+ const formatValue = metric.value_format ? metricFormatter(metric, baseCurrency) : todayNumber
const content = (
<>
<span className="TodayPulse__name">{metric.name}</span>
<span className="TodayPulse__row">
<span className="TodayPulse__value" translate="no">
- {metric.value_format ? formatValue(metric.value) : todayNumber(metric.value)}
+ {formatValue(metric.value)}
</span>
<TodayChange change={metric.change_pct} tone={tone} />
- <span className="TodayPulse__spark">
- <TodaySparkline
- values={metric.series}
- labels={seriesLabels(metric)}
- emphasizeLast={metric.interval === 'day' ? 7 : 1}
- tone={tone}
- formatValue={formatValue}
- />
- </span>
+ </span>
+ <span className="TodayPulse__spark">
+ <TodaySparkline
+ values={metric.series}
+ labels={seriesLabels(metric)}
+ emphasizeLast={metric.interval === 'day' ? 7 : 1}
+ tone={tone}
+ />
</span>
</>
)
return (
<li key={metric.key} className="TodayPulse__metric">
- {metric.url ? (
- <LinkPrimitive
- to={metric.url}
- className="TodayPulse__link"
- title={metric.name}
- data-attr={isInsight ? 'today-pulse-insight' : 'today-pulse-key-metric'}
- >
- {content}
- </LinkPrimitive>
- ) : (
- content
- )}
+ <TodayPulseHoverCard
+ onOpen={() => pulseMetricPreviewed(metric, position)}
+ card={
+ <TodayPulseCard
+ metric={metric}
+ tone={tone}
+ formatValue={metric.value_format ? formatValue : humanFriendlyNumber}
+ onOpen={() => pulseMetricOpened(metric, position)}
+ />
+ }
+ >
+ {metric.url ? (
+ <LinkPrimitive
+ to={metric.url}
+ className="TodayPulse__link"
+ data-attr={isInsight ? 'today-pulse-insight' : 'today-pulse-key-metric'}
+ {...pulseOpenHandlers(() => pulseMetricOpened(metric, position))}
+ >
+ {content}
+ </LinkPrimitive>
+ ) : (
+ content
+ )}
+ </TodayPulseHoverCard>
</li>
)
})}
diff --git a/frontend/src/scenes/project-homepage/today/TodayPulseCard.tsx b/frontend/src/scenes/project-homepage/today/TodayPulseCard.tsx
new file mode 100644
index 000000000000..c37c0f732bf6
--- /dev/null
+++ b/frontend/src/scenes/project-homepage/today/TodayPulseCard.tsx
@@ -0,0 +1,153 @@
+import { useState } from 'react'
+
+import { IconArrowRight, IconInfo } from '@posthog/icons'
+import {
+ Button,
+ Collapsible,
+ CollapsibleContent,
+ CollapsibleTrigger,
+ Heading,
+ Text,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+} from '@posthog/quill'
+
+import { dayjs } from 'lib/dayjs'
+import { LinkPrimitive } from 'lib/lemon-ui/Link'
+
+import { TodayHoverCardFact } from '~/layout/today/TodayHoverCardFact'
+
+import type { HighlightMetricApi } from 'products/today/frontend/generated/api.schemas'
+
+import { TodayChange } from './TodayChange'
+import { pulsePeak, pulsePeriodCaption, pulseWhy } from './todayPulseFacts'
+import { TodayPulseMovers } from './TodayPulseMovers'
+import { pulseOpenHandlers } from './todayPulseOpenHandlers'
+import type { TodayTone } from './TodaySparkline'
+
+const PERIOD_FORMATS: Record<HighlightMetricApi['interval'], string> = {
+ day: 'ddd, D MMM',
+ week: '[week of] D MMM',
+ month: 'MMMM YYYY',
+}
+
+function openLabel(metric: HighlightMetricApi): string {
+ if (metric.reason === 'dashboard') {
+ return metric.dashboard_name ? `Open ${metric.dashboard_name}` : 'Open dashboard'
+ }
+ return metric.key.startsWith('insight:') ? 'Open insight' : 'Open as a trend'
+}
+
+export function TodayPulseCard({
+ metric,
+ tone,
+ formatValue,
+ onOpen,
+}: {
+ metric: HighlightMetricApi
+ tone: TodayTone
+ formatValue: (value: number) => string
+ onOpen: () => void
+}): JSX.Element {
+ const [whyOpen, setWhyOpen] = useState(false)
+ const previous = metric.previous_value
+ const peak = pulsePeak(metric)
+ const why = pulseWhy(metric)
+ return (
+ <div className="flex flex-col gap-3 p-3" data-attr="today-pulse-card">
+ <div className="flex flex-col gap-0.5">
+ <Text size="sm" weight="semibold" render={<span />} className="truncate">
+ {metric.name}
+ </Text>
+ <div className="flex items-baseline gap-2">
+ <Heading size="xl" render={<span />} className="tabular-nums" translate="no">
+ {formatValue(metric.value)}
+ </Heading>
+ <span className="text-sm text-muted-foreground">
+ <TodayChange change={metric.change_pct} tone={tone} />
+ </span>
+ </div>
+ <Text size="xs" variant="muted" render={<span />}>
+ {pulsePeriodCaption(metric)}
+ </Text>
+ </div>
+ {(previous !== null || peak !== null) && (
+ <div className="flex flex-col gap-1">
+ {previous !== null && (
+ <TodayHoverCardFact label="Before">
+ <span className="tabular-nums">{formatValue(previous)}</span>
+ </TodayHoverCardFact>
+ )}
+ {peak !== null && (
+ <TodayHoverCardFact label={peak.label}>
+ <span className="tabular-nums">
+ {formatValue(peak.value)}
+ <span className="text-muted-foreground">
+ {' '}
+ · {peak.latest ?? dayjs(peak.start).format(PERIOD_FORMATS[metric.interval])}
+ </span>
+ </span>
+ </TodayHoverCardFact>
+ )}
+ </div>
+ )}
+ {metric.movers.length > 1 && (
+ <div className="flex flex-col gap-1.5">
+ <Text size="xs" variant="muted" render={<span />}>
+ What changed most
+ </Text>
+ <TodayPulseMovers movers={metric.movers} formatValue={formatValue} />
+ </div>
+ )}
+ <Collapsible
+ variant="folder"
+ open={whyOpen}
+ onOpenChange={setWhyOpen}
+ className="flex flex-col border-t border-border pt-2"
+ >
+ <div className="flex min-h-6 items-center justify-between gap-2">
+ {metric.url ? (
+ <Button
+ size="xs"
+ variant="link-muted"
+ className="-ms-2"
+ render={<LinkPrimitive to={metric.url} />}
+ {...pulseOpenHandlers(onOpen)}
+ data-attr="today-pulse-card-open"
+ >
+ {openLabel(metric)}
+ <IconArrowRight />
+ </Button>
+ ) : (
+ <span />
+ )}
+ {why && (
+ <Tooltip>
+ <TooltipTrigger
+ render={
+ <CollapsibleTrigger
+ iconOnly
+ icon={<IconInfo />}
+ className="-me-1.5 text-muted-foreground"
+ data-attr="today-pulse-card-why"
+ />
+ }
+ >
+ Why you see this
+ </TooltipTrigger>
+ <TooltipContent>Why you see this</TooltipContent>
+ </Tooltip>
+ )}
+ </div>
+ {why && (
+ <CollapsibleContent className="px-0 pb-0">
+ <Text size="xs" variant="muted" className="m-0 pt-1">
+ {why}
+ </Text>
+ </CollapsibleContent>
+ )}
+ </Collapsible>
+ </div>
+ )
+}
diff --git a/frontend/src/scenes/project-homepage/today/TodayPulseHoverCard.tsx b/frontend/src/scenes/project-homepage/today/TodayPulseHoverCard.tsx
new file mode 100644
index 000000000000..87aca3233704
--- /dev/null
+++ b/frontend/src/scenes/project-homepage/today/TodayPulseHoverCard.tsx
@@ -0,0 +1,67 @@
+import { type FocusEvent, type ReactNode, useCallback, useRef, useState } from 'react'
+
+import { Popover, PopoverContent, PopoverTrigger } from '@posthog/quill'
+
+import { pointerMovedRecently, trackPointer } from '~/layout/today/todayPointer'
+
+const OPEN_DELAY_MS = 300
+const CLOSE_DELAY_MS = 150
+
+export function TodayPulseHoverCard({
+ children,
+ card,
+ onOpen,
+}: {
+ children: ReactNode
+ card: ReactNode
+ onOpen: () => void
+}): JSX.Element {
+ const [open, setOpen] = useState(false)
+ const popupRef = useRef<HTMLDivElement>(null)
+ const triggerRef = useCallback((): void => trackPointer(), [])
+ const show = (next: boolean): void => {
+ setOpen(next)
+ if (next) {
+ onOpen()
+ }
+ }
+ return (
+ <Popover
+ open={open}
+ onOpenChange={(next, details) => {
+ if (next && details.reason === 'trigger-hover' && !pointerMovedRecently()) {
+ return
+ }
+ show(next)
+ }}
+ >
+ <PopoverTrigger
+ openOnHover
+ delay={OPEN_DELAY_MS}
+ closeDelay={CLOSE_DELAY_MS}
+ nativeButton={false}
+ ref={triggerRef}
+ render={<div />}
+ className="TodayPulse__trigger"
+ onFocus={() => !open && show(true)}
+ onBlur={(event: FocusEvent) => {
+ if (!popupRef.current?.contains(event.relatedTarget as Node | null)) {
+ setOpen(false)
+ }
+ }}
+ >
+ {children}
+ </PopoverTrigger>
+ <PopoverContent
+ ref={popupRef}
+ side="bottom"
+ align="start"
+ sideOffset={8}
+ initialFocus={false}
+ className="w-85 gap-0 p-0"
+ >
+ {card}
+ </PopoverContent>
+ </Popover>
+ )
+}
diff --git a/frontend/src/scenes/project-homepage/today/TodayPulseMovers.test.tsx b/frontend/src/scenes/project-homepage/today/TodayPulseMovers.test.tsx
new file mode 100644
index 000000000000..91e784712d6e
--- /dev/null
+++ b/frontend/src/scenes/project-homepage/today/TodayPulseMovers.test.tsx
@@ -0,0 +1,28 @@
+import '@testing-library/jest-dom'
+
+import { cleanup, render, screen } from '@testing-library/react'
+
+import { TodayPulseMovers } from './TodayPulseMovers'
+
+describe('TodayPulseMovers', () => {
+ afterEach(() => cleanup())
+
+ it('keeps the ranking it receives and shows a negative series value as it is', () => {
+ render(
+ <TodayPulseMovers
+ movers={[
+ { label: 'Refunds', value: -50, change_pct: -20 },
+ { label: 'Orders', value: 120, change_pct: 10 },
+ ]}
+ formatValue={(value) => `v${value}`}
+ />
+ )
+
+ expect(screen.getByText('v-50')).toBeInTheDocument()
+ expect(screen.getByText('v120')).toBeInTheDocument()
+ expect(screen.getAllByRole('listitem').map((row) => row.textContent?.split(/[+−-]/)[0])).toEqual([
+ 'Refunds',
+ 'Orders',
+ ])
+ })
+})
diff --git a/frontend/src/scenes/project-homepage/today/TodayPulseMovers.tsx b/frontend/src/scenes/project-homepage/today/TodayPulseMovers.tsx
new file mode 100644
index 000000000000..f6ce5dd38f0f
--- /dev/null
+++ b/frontend/src/scenes/project-homepage/today/TodayPulseMovers.tsx
@@ -0,0 +1,68 @@
+import { useMemo } from 'react'
+
+import { BarList, type Series } from '@posthog/quill-charts'
+
+import { useChartTheme } from 'lib/charts/hooks'
+
+import type { HighlightMoverApi } from 'products/today/frontend/generated/api.schemas'
+
+import { TodayChange } from './TodayChange'
+import { useTodayTonePalette } from './TodaySparkline'
+
+export function TodayPulseMovers({
+ movers,
+ formatValue,
+}: {
+ movers: HighlightMoverApi[]
+ formatValue: (value: number) => string
+}): JSX.Element {
+ const theme = useChartTheme()
+ const palette = useTodayTonePalette()
+ const series = useMemo<Series<HighlightMoverApi>[]>(
+ () =>
+ movers.map((mover) => ({
+ key: mover.label,
+ label: mover.label,
+ data: [mover.value],
+ color: palette.line,
+ meta: mover,
+ })),
+ [movers, palette]
+ )
+ if (movers.some((mover) => mover.value < 0)) {
+ return (
+ <ul className="m-0 flex list-none flex-col gap-1 p-0" data-attr="today-pulse-card-movers">
+ {series.map((row) => (
+ <li key={row.key} className="flex min-w-0 items-baseline justify-between gap-3 text-xs">
+ <span className="flex min-w-0 items-baseline gap-1.5">
+ <span className="truncate">{row.label}</span>
+ <span className="shrink-0 text-muted-foreground">
+ <TodayChange change={row.meta?.change_pct ?? null} tone="neutral" />
+ </span>
+ </span>
+ <span className="shrink-0 text-muted-foreground tabular-nums">{formatValue(row.data[0])}</span>
+ </li>
+ ))}
+ </ul>
+ )
+ }
+ return (
+ <BarList
+ series={series}
+ theme={theme}
+ config={{ valueDisplay: 'value', tooltip: { enabled: false } }}
+ valueFormatter={formatValue}
+ renderLabel={(row) => (
+ <span className="flex min-w-0 items-baseline gap-1.5">
+ <span className="truncate">{row.label}</span>
+ {row.meta && (
+ <span className="shrink-0 text-xs text-muted-foreground">
+ <TodayChange change={row.meta.change_pct} tone="neutral" />
+ </span>
+ )}
+ </span>
+ )}
+ dataAttr="today-pulse-card-movers"
+ />
+ )
+}
diff --git a/frontend/src/scenes/project-homepage/today/TodaySparkline.tsx b/frontend/src/scenes/project-homepage/today/TodaySparkline.tsx
index 85c75e8dc165..aa013bbc90c6 100644
--- a/frontend/src/scenes/project-homepage/today/TodaySparkline.tsx
+++ b/frontend/src/scenes/project-homepage/today/TodaySparkline.tsx
@@ -44,7 +44,7 @@ export function TodaySparkline({
labels: string[]
tone: TodayTone
emphasizeLast: number
- formatValue: (value: number) => string
+ formatValue?: (value: number) => string
}): JSX.Element {
const theme = useChartTheme()
const palette = useTodayTonePalette()
@@ -70,18 +70,18 @@ export function TodaySparkline({
showGrid: false,
showAxisLines: false,
showTickMarks: false,
- showCrosshair: true,
+ showCrosshair: !!formatValue,
curve: 'linear',
floatBaseline: true,
margins: { top: 4, right: 4, bottom: 4, left: 1 },
- tooltip: { enabled: true, placement: 'follow-data' },
+ tooltip: { enabled: !!formatValue, placement: 'follow-data' },
}),
- []
+ [formatValue]
)
const tooltip = useCallback(
(context: TooltipContext): JSX.Element | null => {
const value = context.seriesData[0]?.value
- if (value === undefined || Number.isNaN(value)) {
+ if (!formatValue || value === undefined || Number.isNaN(value)) {
return null
}
return (
diff --git a/frontend/src/scenes/project-homepage/today/todayHighlightsLogic.test.ts b/frontend/src/scenes/project-homepage/today/todayHighlightsLogic.test.ts
index b8c9a945bf40..9c93935ad246 100644
--- a/frontend/src/scenes/project-homepage/today/todayHighlightsLogic.test.ts
+++ b/frontend/src/scenes/project-homepage/today/todayHighlightsLogic.test.ts
@@ -1,10 +1,11 @@
import { expectLogic } from 'kea-test-utils'
+import posthog from 'posthog-js'
import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'
import { HIGHLIGHTS_POLL_MS, todayHighlightsLogic } from './todayHighlightsLogic'
-import { makeHighlightItem, makeHighlights } from './todayTestFixtures'
+import { makeHighlightItem, makeHighlights, makePulseMetric } from './todayTestFixtures'
describe('todayHighlightsLogic', () => {
let highlightResponses: [number, any][]
@@ -26,6 +27,38 @@ describe('todayHighlightsLogic', () => {
afterEach(() => {
jest.useRealTimers()
+ jest.restoreAllMocks()
+ })
+
+ it('records which pulse metric was opened, why it was shown and the ranking variant', async () => {
+ const capture = jest.spyOn(posthog, 'capture').mockImplementation(() => undefined)
+ jest.spyOn(posthog, 'getFeatureFlag').mockReturnValue('frecency')
+ const logic = todayHighlightsLogic()
+ logic.mount()
+
+ logic.actions.pulseMetricOpened(makePulseMetric({ reason: 'dashboard', dashboard_name: 'Growth' }), 2)
+
+ expect(capture).toHaveBeenCalledWith('today pulse metric opened', {
+ kind: 'insight',
+ reason: 'dashboard',
+ position: 2,
+ pulse_ranking: 'frecency',
+ })
+ })
+
+ it('records a pulse preview once per metric', async () => {
+ const capture = jest.spyOn(posthog, 'capture').mockImplementation(() => undefined)
+ const logic = todayHighlightsLogic()
+ logic.mount()
+
+ logic.actions.pulseMetricPreviewed(makePulseMetric(), 0)
+ logic.actions.pulseMetricPreviewed(makePulseMetric(), 0)
+ logic.actions.pulseMetricPreviewed(makePulseMetric({ key: 'signup_event', reason: 'key_metric' }), 1)
+
+ expect(capture.mock.calls.filter(([event]) => event === 'today pulse metric previewed')).toEqual([
+ ['today pulse metric previewed', expect.objectContaining({ kind: 'insight', position: 0 })],
+ ['today pulse metric previewed', expect.objectContaining({ kind: 'key_metric', position: 1 })],
+ ])
})
it.each([
diff --git a/frontend/src/scenes/project-homepage/today/todayHighlightsLogic.ts b/frontend/src/scenes/project-homepage/today/todayHighlightsLogic.ts
index a0a1143520a4..1d13085ed034 100644
--- a/frontend/src/scenes/project-homepage/today/todayHighlightsLogic.ts
+++ b/frontend/src/scenes/project-homepage/today/todayHighlightsLogic.ts
@@ -3,10 +3,11 @@ import { loaders } from 'kea-loaders'
import posthog from 'posthog-js'
import { ApiError } from 'lib/api'
+import { FEATURE_FLAGS } from 'lib/constants'
import { teamLogic } from 'scenes/teamLogic'
import { todayHighlightsRetrieve } from 'products/today/frontend/generated/api'
-import type { HighlightItemApi, HighlightsApi } from 'products/today/frontend/generated/api.schemas'
+import type { HighlightItemApi, HighlightMetricApi, HighlightsApi } from 'products/today/frontend/generated/api.schemas'
export const HIGHLIGHTS_POLL_MS = 2_000
const HIGHLIGHTS_WAIT_MS = 2_000
@@ -60,6 +61,20 @@ export interface todayHighlightsLogicActions {
highlights: HighlightsApi | null
payload?: any
}
+ pulseMetricOpened: (
+ metric: HighlightMetricApi,
+ position: number
+ ) => {
+ metric: HighlightMetricApi
+ position: number
+ }
+ pulseMetricPreviewed: (
+ metric: HighlightMetricApi,
+ position: number
+ ) => {
+ metric: HighlightMetricApi
+ position: number
+ }
setHiddenHighlights: (hidden: Record<string, string>) => {
hidden: Record<string, string>
}
@@ -108,6 +123,8 @@ export const todayHighlightsLogic = kea<todayHighlightsLogicType>([
})),
actions({
highlightOpened: (item: HighlightItemApi, position: number) => ({ item, position }),
+ pulseMetricOpened: (metric: HighlightMetricApi, position: number) => ({ metric, position }),
+ pulseMetricPreviewed: (metric: HighlightMetricApi, position: number) => ({ metric, position }),
hideHighlight: (item: HighlightItemApi, position: number) => ({ item, position }),
unhideHighlight: (item: HighlightItemApi, position: number) => ({ item, position }),
setHiddenHighlights: (hidden: Record<string, string>) => ({ hidden }),
@@ -226,6 +243,27 @@ export const todayHighlightsLogic = kea<todayHighlightsLogicType>([
score: item.score,
})
},
+ pulseMetricOpened: ({ metric, position }) => {
+ posthog.capture('today pulse metric opened', {
+ kind: metric.key.startsWith('insight:') ? 'insight' : 'key_metric',
+ reason: metric.reason,
+ position,
+ pulse_ranking: posthog.getFeatureFlag(FEATURE_FLAGS.TODAY_PULSE_RANKING) ?? null,
+ })
+ },
+ pulseMetricPreviewed: ({ metric, position }) => {
+ const previewed: Set<string> = (cache.previewedPulseMetrics ??= new Set<string>())
+ if (previewed.has(metric.key)) {
+ return
+ }
+ previewed.add(metric.key)
+ posthog.capture('today pulse metric previewed', {
+ kind: metric.key.startsWith('insight:') ? 'insight' : 'key_metric',
+ reason: metric.reason,
+ position,
+ pulse_ranking: posthog.getFeatureFlag(FEATURE_FLAGS.TODAY_PULSE_RANKING) ?? null,
+ })
+ },
loadHighlightsSuccess: ({ highlights }) => {
if (!highlights) {
return
@@ -244,6 +282,8 @@ export const todayHighlightsLogic = kea<todayHighlightsLogicType>([
opportunity_count: highlights.items.filter((item) => item.label === 'opportunity').length,
sources: highlights.items.map((item) => item.source),
pulse_count: highlights.pulse.length,
+ pulse_reasons: highlights.pulse.map((metric) => metric.reason),
+ pulse_ranking: posthog.getFeatureFlag(FEATURE_FLAGS.TODAY_PULSE_RANKING) ?? null,
})
},
})),
diff --git a/frontend/src/scenes/project-homepage/today/todayPulseFacts.test.ts b/frontend/src/scenes/project-homepage/today/todayPulseFacts.test.ts
new file mode 100644
index 000000000000..e578e15af070
--- /dev/null
+++ b/frontend/src/scenes/project-homepage/today/todayPulseFacts.test.ts
@@ -0,0 +1,43 @@
+import { dayjs } from 'lib/dayjs'
+
+import { pulsePeak, pulseWhy } from './todayPulseFacts'
+import { makePulseMetric } from './todayTestFixtures'
+
+describe('todayPulseFacts', () => {
+ const today = dayjs('2026-09-30T10:00:00')
+
+ it.each([
+ [
+ 'an insight opened on several days',
+ { reason: 'routine', opened_days: 5, last_opened: '2026-09-29' },
+ 'You opened this insight on 5 of the last 14 days, most recently yesterday.',
+ ],
+ [
+ 'an insight opened once',
+ { reason: 'routine', opened_days: 1, last_opened: '2026-09-21' },
+ 'You last opened this insight on Sep 21.',
+ ],
+ [
+ 'a dashboard tile opened today',
+ { reason: 'dashboard', dashboard_name: 'Growth', opened_days: 9, last_opened: '2026-09-30' },
+ 'You opened the Growth dashboard on 9 of the last 14 days, most recently today. This is the first chart on that dashboard.',
+ ],
+ [
+ 'a key metric',
+ { reason: 'key_metric', opened_days: null, last_opened: null },
+ 'It is a key metric for this project, set in Customer analytics.',
+ ],
+ ['a metric computed before reasons existed', { reason: null }, null],
+ ] as const)('explains %s', (_name, overrides, expected) => {
+ expect(pulseWhy(makePulseMetric(overrides), today)).toBe(expected)
+ })
+
+ it('finds the highest value with the period it belongs to, skipping missing values', () => {
+ const metric = makePulseMetric({
+ interval: 'day',
+ series: [3, NaN, 9, 4],
+ period_starts: ['2026-09-26', '2026-09-27', '2026-09-28', '2026-09-29'],
+ })
+ expect(pulsePeak(metric)).toEqual({ label: 'Top day', value: 9, start: '2026-09-28', latest: null })
+ })
+})
diff --git a/frontend/src/scenes/project-homepage/today/todayPulseFacts.ts b/frontend/src/scenes/project-homepage/today/todayPulseFacts.ts
new file mode 100644
index 000000000000..e9b1e13ded3d
--- /dev/null
+++ b/frontend/src/scenes/project-homepage/today/todayPulseFacts.ts
@@ -0,0 +1,84 @@
+import { dayjs } from 'lib/dayjs'
+
+import type { HighlightMetricApi } from 'products/today/frontend/generated/api.schemas'
+
+const PERIOD_CAPTIONS: Record<HighlightMetricApi['interval'], string> = {
+ day: 'Last 7 days, against the 7 days before',
+ week: 'Last week, against the week before',
+ month: 'Last month, against the month before',
+}
+
+export function pulsePeriodCaption(metric: HighlightMetricApi): string {
+ return PERIOD_CAPTIONS[metric.interval]
+}
+
+const PEAK_LABELS: Record<HighlightMetricApi['interval'], string> = {
+ day: 'Top day',
+ week: 'Top week',
+ month: 'Top month',
+}
+
+const LATEST_PERIODS: Record<HighlightMetricApi['interval'], string> = {
+ day: 'yesterday',
+ week: 'last week',
+ month: 'last month',
+}
+
+export interface PulsePeak {
+ label: string
+ value: number
+ start: string
+ latest: string | null
+}
+
+export function pulsePeak(metric: HighlightMetricApi): PulsePeak | null {
+ let peak: PulsePeak | null = null
+ const lastIndex = metric.series.length - 1
+ for (const [index, value] of metric.series.entries()) {
+ const start = metric.period_starts[index]
+ if (start && !Number.isNaN(value) && (peak === null || value > peak.value)) {
+ peak = {
+ label: PEAK_LABELS[metric.interval],
+ value,
+ start,
+ latest: index === lastIndex ? LATEST_PERIODS[metric.interval] : null,
+ }
+ }
+ }
+ return peak
+}
+
+function openedWhen(day: string, today: dayjs.Dayjs): string {
+ const days = today.startOf('day').diff(dayjs(day).startOf('day'), 'day')
+ if (days <= 0) {
+ return 'today'
+ }
+ if (days === 1) {
+ return 'yesterday'
+ }
+ return `on ${dayjs(day).format('MMM D')}`
+}
+
+export function pulseWhy(metric: HighlightMetricApi, today: dayjs.Dayjs = dayjs()): string | null {
+ if (metric.reason === 'key_metric') {
+ return 'It is a key metric for this project, set in Customer analytics.'
+ }
+ if (metric.reason !== 'routine' && metric.reason !== 'dashboard') {
+ return null
+ }
+ const subject =
+ metric.reason === 'dashboard'
+ ? metric.dashboard_name
+ ? `the ${metric.dashboard_name} dashboard`
+ : 'its dashboard'
+ : 'this insight'
+ const suffix = metric.reason === 'dashboard' ? ' This is the first chart on that dashboard.' : ''
+ if (!metric.last_opened) {
+ return `You open ${subject} often.${suffix}`
+ }
+ const when = openedWhen(metric.last_opened, today)
+ if (!metric.opened_days || metric.opened_days < 2) {
+ return `You last opened ${subject} ${when}.${suffix}`
+ }
+ return `You opened ${subject} on ${metric.opened_days} of the last 14 days, most recently ${when}.${suffix}`
+}
diff --git a/frontend/src/scenes/project-homepage/today/todayPulseOpenHandlers.test.ts b/frontend/src/scenes/project-homepage/today/todayPulseOpenHandlers.test.ts
new file mode 100644
index 000000000000..a09fb5ef2f2f
--- /dev/null
+++ b/frontend/src/scenes/project-homepage/today/todayPulseOpenHandlers.test.ts
@@ -0,0 +1,26 @@
+import type { MouseEvent } from 'react'
+
+import { pulseOpenHandlers } from './todayPulseOpenHandlers'
+
+describe('pulseOpenHandlers', () => {
+ const event = (fields: Partial<MouseEvent<HTMLElement>>): MouseEvent<HTMLElement> =>
+ ({ button: 0, metaKey: false, ctrlKey: false, ...fields }) as MouseEvent<HTMLElement>
+
+ it.each([
+ ['a plain click', 'onClick', event({}), 1],
+ ['a Cmd-click', 'onMouseDown', event({ metaKey: true }), 1],
+ ['a Ctrl-click', 'onMouseDown', event({ ctrlKey: true }), 1],
+ ['a middle click', 'onAuxClick', event({ button: 1 }), 1],
+ ['a plain mouse down, which the click already counts', 'onMouseDown', event({}), 0],
+ ['a right click', 'onAuxClick', event({ button: 2 }), 0],
+ ] as const)('records %s as many times as it opens the link', (_name, handler, mouseEvent, expected) => {
+ const onOpen = jest.fn()
+ const handlers = pulseOpenHandlers(onOpen)
+ if (handler === 'onClick') {
+ handlers.onClick()
+ } else {
+ handlers[handler](mouseEvent)
+ }
+ expect(onOpen).toHaveBeenCalledTimes(expected)
+ })
+})
diff --git a/frontend/src/scenes/project-homepage/today/todayPulseOpenHandlers.ts b/frontend/src/scenes/project-homepage/today/todayPulseOpenHandlers.ts
new file mode 100644
index 000000000000..085c6dcb1527
--- /dev/null
+++ b/frontend/src/scenes/project-homepage/today/todayPulseOpenHandlers.ts
@@ -0,0 +1,23 @@
+import type { MouseEvent } from 'react'
+
+export interface PulseOpenHandlers {
+ onClick: () => void
+ onMouseDown: (event: MouseEvent<HTMLElement>) => void
+ onAuxClick: (event: MouseEvent<HTMLElement>) => void
+}
+
+export function pulseOpenHandlers(onOpen: () => void): PulseOpenHandlers {
+ return {
+ onClick: onOpen,
+ onMouseDown: (event) => {
+ if (event.button === 0 && (event.metaKey || event.ctrlKey)) {
+ onOpen()
+ }
+ },
+ onAuxClick: (event) => {
+ if (event.button === 1) {
+ onOpen()
+ }
+ },
+ }
+}
diff --git a/frontend/src/scenes/project-homepage/today/todayTestFixtures.ts b/frontend/src/scenes/project-homepage/today/todayTestFixtures.ts
index 49c85d5b1309..22fce3c75a6b 100644
--- a/frontend/src/scenes/project-homepage/today/todayTestFixtures.ts
+++ b/frontend/src/scenes/project-homepage/today/todayTestFixtures.ts
@@ -1,4 +1,9 @@
-import type { HighlightItemApi, HighlightsApi, SignalViewApi } from 'products/today/frontend/generated/api.schemas'
+import type {
+ HighlightItemApi,
+ HighlightMetricApi,
+ HighlightsApi,
+ SignalViewApi,
+} from 'products/today/frontend/generated/api.schemas'
export function signal(overrides: Partial<SignalViewApi>): SignalViewApi {
return {
@@ -35,6 +40,28 @@ export function makeHighlightItem(overrides: Partial<HighlightItemApi> = {}): Hi
}
}
+export function makePulseMetric(overrides: Partial<HighlightMetricApi> = {}): HighlightMetricApi {
+ return {
+ key: 'insight:abc',
+ name: 'Sign-ups',
+ value: 120,
+ unit: 'number',
+ change_pct: 4,
+ series: [100, 120],
+ interval: 'week',
+ url: '/insights/abc',
+ value_format: null,
+ period_starts: ['2026-09-21', '2026-09-28'],
+ reason: 'routine',
+ dashboard_name: null,
+ opened_days: 5,
+ last_opened: '2026-09-29',
+ movers: [],
+ previous_value: 100,
+ ...overrides,
+ }
+}
+
export function makeHighlights(overrides: Partial<HighlightsApi> = {}): HighlightsApi {
return {
status: 'ready',