: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
feat(today): send the details a pulse tile needs for its hover card (#119028)
Shy Alter9aaf50b4c32e
diff --git a/frontend/src/scenes/project-homepage/today/Today.stories.tsx b/frontend/src/scenes/project-homepage/today/Today.stories.tsxindex 4ae3fa981933..87f0f87e38f7 100644--- a/frontend/src/scenes/project-homepage/today/Today.stories.tsx+++ b/frontend/src/scenes/project-homepage/today/Today.stories.tsx@@ -577,9 +577,19 @@ const HIGHLIGHTS: HighlightsApi = {change_pct: 6.4,series: [3100, 3250, 3300, 3420, 3380, 3600, 3710, 3690, 3850, 3920, 3956, 4210],interval: 'week',- url: '/insights/wKu1pSx2',+ url: '/dashboard/41',value_format: null,period_starts: PERIOD_STARTS(12, 'week'),+ reason: 'dashboard',+ dashboard_name: 'Growth',+ opened_days: 9,+ last_opened: '2026-09-27',+ previous_value: 3956,+ movers: [+ { label: 'Paid plans', value: 2610, change_pct: 9.2 },+ { label: 'Free plan', value: 1420, change_pct: 1.8 },+ { label: 'Trials', value: 180, change_pct: -4.8 },+ ],},{key: 'signup_event',@@ -592,6 +602,12 @@ const HIGHLIGHTS: HighlightsApi = {url: KEY_METRIC_URL('$signup'),value_format: null,period_starts: PERIOD_STARTS(28, 'day'),+ reason: 'key_metric',+ dashboard_name: null,+ opened_days: null,+ last_opened: null,+ previous_value: 1017,+ movers: [],},{key: 'payment_event',@@ -604,6 +620,12 @@ const HIGHLIGHTS: HighlightsApi = {url: KEY_METRIC_URL('payment_succeeded'),value_format: null,period_starts: PERIOD_STARTS(28, 'day'),+ reason: 'key_metric',+ dashboard_name: null,+ opened_days: null,+ last_opened: null,+ previous_value: 353,+ movers: [],},{key: 'activity_event',@@ -616,6 +638,12 @@ const HIGHLIGHTS: HighlightsApi = {url: KEY_METRIC_URL('$pageview'),value_format: null,period_starts: PERIOD_STARTS(28, 'day'),+ reason: 'key_metric',+ dashboard_name: null,+ opened_days: null,+ last_opened: null,+ previous_value: 18012,+ movers: [],},],items: [diff --git a/products/today/backend/facade/contracts.py b/products/today/backend/facade/contracts.pyindex ed722409ccd4..9091ae298b23 100644--- a/products/today/backend/facade/contracts.py+++ b/products/today/backend/facade/contracts.py@@ -15,6 +15,7 @@ from .enums import (FigureText,HighlightInterval,HighlightLabel,+ HighlightMetricReason,HighlightPriority,HighlightsStatus,HighlightUnit,@@ -164,6 +165,13 @@ class HighlightValueFormat:decimal_places: int | None+@dataclass(frozen=True)+class HighlightMover:+ label: str+ value: float+ change_pct: float | None++@dataclass(frozen=True)class HighlightMetric:key: str@@ -176,6 +184,12 @@ class HighlightMetric:url: str | None = Nonevalue_format: HighlightValueFormat | None = Noneperiod_starts: list[date] = field(default_factory=list)+ reason: HighlightMetricReason | None = None+ dashboard_name: str | None = None+ opened_days: int | None = None+ last_opened: date | None = None+ movers: list[HighlightMover] = field(default_factory=list)+ previous_value: float | None = None@dataclass(frozen=True)diff --git a/products/today/backend/facade/enums.py b/products/today/backend/facade/enums.pyindex 71d61d391157..c977520a276a 100644--- a/products/today/backend/facade/enums.py+++ b/products/today/backend/facade/enums.py@@ -53,6 +53,12 @@ class HighlightUnit(LabeledStrEnum):NUMBER = "number", "Number"+class HighlightMetricReason(LabeledStrEnum):+ ROUTINE = "routine", "You open this often"+ DASHBOARD = "dashboard", "On a dashboard you open often"+ KEY_METRIC = "key_metric", "Project key metric"++class HighlightInterval(LabeledStrEnum):DAY = "day", "Day"WEEK = "week", "Week"diff --git a/products/today/backend/logic/highlight_sources/key_metrics.py b/products/today/backend/logic/highlight_sources/key_metrics.pyindex e4b2f372eafd..dd42846a1de6 100644--- a/products/today/backend/logic/highlight_sources/key_metrics.py+++ b/products/today/backend/logic/highlight_sources/key_metrics.py@@ -5,7 +5,7 @@ from products.customer_analytics.backend.facade.api import get_key_metricsfrom products.customer_analytics.backend.facade.contracts import KeyMetricfrom ...facade import contracts-from ...facade.enums import HighlightLabel, HighlightUnit+from ...facade.enums import HighlightLabel, HighlightMetricReason, HighlightUnitfrom ..highlight_rules import exactfrom ..highlight_trends import detectfrom ..highlight_types import Candidate, Context, DailyValueNotReady, Found, Source@@ -37,6 +37,8 @@ def _tile(metric: KeyMetric) -> contracts.HighlightMetric:change_pct=round((metric.this_week / metric.last_week - 1) * 100, 1) if metric.last_week else None,series=[v for _, v in metric.daily[-PULSE_DAYS:]],url=_url(metric),+ reason=HighlightMetricReason.KEY_METRIC,+ previous_value=metric.last_week,)diff --git a/products/today/backend/logic/highlight_sources/routine.py b/products/today/backend/logic/highlight_sources/routine.pyindex b8f36d20e749..c1175e63b7fd 100644--- a/products/today/backend/logic/highlight_sources/routine.py+++ b/products/today/backend/logic/highlight_sources/routine.py@@ -13,7 +13,7 @@ from products.product_analytics.backend.facade.api import get_insight_seriesfrom products.product_analytics.backend.facade.contracts import InsightDashboardContextfrom ...facade import contracts-from ...facade.enums import HighlightInterval, HighlightUnit+from ...facade.enums import HighlightInterval, HighlightMetricReason, HighlightUnitfrom ...feature_flags import FRECENCY_RANKING, pulse_rankingfrom ..highlight_rules import shortfrom ..highlight_series import pretty, usable_series@@ -33,6 +33,8 @@ FRECENCY_LOOKBACK_DAYS = VIEW_DAYS_KEPTFRECENCY_CANDIDATES = 8FRECENCY_TILES = 4DASHBOARD_TILES_TRIED = 6+OPENED_DAYS_WINDOW = 14+MOVERS_SHOWN = 4@frozen@@ -47,7 +49,7 @@ def find(context: Context) -> Found:return Found(pulse=tuple(_frecent_metrics(context)))metrics: list[contracts.HighlightMetric] = []for item in _routine_insights(context):- metric = context.guard(f"routine {item.ref}", partial(_metric, context, item.ref), None)+ metric = context.guard(f"routine {item.ref}", partial(_metric, context, item.ref, viewed=item), None)if metric is not None:metrics.append(metric)if len(metrics) == ROUTINE_TILES:@@ -128,7 +130,7 @@ def _frecent_views(context: Context) -> list[ViewedItem]:def _frecent_metric(context: Context, item: ViewedItem, shown: frozenset[str]) -> contracts.HighlightMetric | None:if item.kind == "insight":- return None if f"insight:{item.ref}" in shown else _metric(context, item.ref)+ return None if f"insight:{item.ref}" in shown else _metric(context, item.ref, viewed=item)if not item.ref.isdigit():return Nonedashboard = dashboard_insights(@@ -148,7 +150,9 @@ def _frecent_metric(context: Context, item: ViewedItem, shown: frozenset[str]) -dashboard=InsightDashboardContext(filters=dashboard.filters, tile_filters=tile.filters_overrides, variables=dashboard.variables),+ viewed=item,url=f"/dashboard/{dashboard.dashboard_id}",+ dashboard_name=dashboard.name,),None,)@@ -161,8 +165,10 @@ def _metric(context: Context,short_id: str,*,+ viewed: ViewedItem | None = None,dashboard: InsightDashboardContext | None = None,url: str | None = None,+ dashboard_name: str | None = None,) -> contracts.HighlightMetric | None:insight = get_insight_series(team=context.team, user=context.user, short_id=short_id, dashboard=dashboard)if insight is None:@@ -207,7 +213,38 @@ def _metric(interval=HighlightInterval(period),url=url or f"/insights/{short_id}",value_format=value_format,+ reason=HighlightMetricReason.ROUTINE if dashboard is None else HighlightMetricReason.DASHBOARD,+ dashboard_name=dashboard_name,+ opened_days=_opened_days(viewed, context.today) if viewed else None,+ last_opened=max(viewed.days) if viewed and viewed.days else None,+ movers=_movers(series, insight.averaged_series, period, context.today),+ previous_value=values[-2],)+def _movers(+ series: dict[str, list[tuple[date, float]]], averaged: Sequence[str], period: str, today: date+) -> list[contracts.HighlightMover]:+ if len(series) < 2:+ return []+ moves: list[tuple[float, contracts.HighlightMover]] = []+ for name, points in series.items():+ _, values = detect(points, period, today, period == "day" and name in averaged)+ if len(values) < 2:+ continue+ now, before = values[-1], values[-2]+ mover = contracts.HighlightMover(+ label=short(pretty(name), 32),+ value=now,+ change_pct=round((now - before) / abs(before) * 100, 1) if before else None,+ )+ moves.append((abs(now - before), mover))+ moves.sort(key=lambda move: move[0], reverse=True)+ return [mover for _, mover in moves[:MOVERS_SHOWN]] if len(moves) > 1 else []+++def _opened_days(viewed: ViewedItem, today: date) -> int:+ return sum(1 for day in viewed.days if 0 <= (today - day).days < OPENED_DAYS_WINDOW)++SOURCE = Source(name="routine", find=find, scopes=("insight:read",), pulse_order=1)diff --git a/products/today/backend/presentation/serializers.py b/products/today/backend/presentation/serializers.pyindex d6d2d0867c15..efa0a26c9e8f 100644--- a/products/today/backend/presentation/serializers.py+++ b/products/today/backend/presentation/serializers.py@@ -9,6 +9,7 @@ from ..facade.contracts import (FigureQuote,HighlightItem,HighlightMetric,+ HighlightMover,Highlights,HighlightValueFormat,ImpactNumber,@@ -29,6 +30,7 @@ from ..facade.enums import (FigureText,HighlightInterval,HighlightLabel,+ HighlightMetricReason,HighlightPriority,HighlightsStatus,HighlightUnit,@@ -270,6 +272,20 @@ class HighlightValueFormatSerializer(DataclassSerializer):dataclass = HighlightValueFormat+class HighlightMoverSerializer(DataclassSerializer):+ label = serializers.CharField( # type: ignore[assignment]+ help_text="Name of one series of the insight, for example a breakdown value."+ )+ value = serializers.FloatField(help_text="Value of the series for the last complete period.")+ change_pct = serializers.FloatField(+ allow_null=True,+ help_text="Change of the series against the period before, in percent. Null when the period before is 0.",+ )++ class Meta:+ dataclass = HighlightMover++class HighlightMetricSerializer(DataclassSerializer):key = serializers.CharField(help_text="Stable key of the metric: a key metric setting such as signup_event, or insight:<short_id>."@@ -305,6 +321,31 @@ class HighlightMetricSerializer(DataclassSerializer):child=serializers.DateField(),help_text="The first day of the period each value in `series` covers, in the project's timezone. Same length and order as `series`.",)+ reason = serializers.ChoiceField(+ choices=HighlightMetricReason.choices,+ allow_null=True,+ help_text="Why the pulse shows the metric: `routine` for an insight the person opens often, `dashboard` for a tile of a dashboard they open often, `key_metric` for a key metric of the project. Null for metrics computed before this field existed.",+ )+ dashboard_name = serializers.CharField(+ allow_null=True,+ help_text="Name of the dashboard the tile comes from when `reason` is `dashboard`, else null.",+ )+ opened_days = serializers.IntegerField(+ allow_null=True,+ help_text="On how many of the last 14 days the person opened the insight, or the dashboard of the tile. Null for a key metric.",+ )+ last_opened = serializers.DateField(+ allow_null=True,+ help_text="The last day the person opened the insight, or the dashboard of the tile, in the project's timezone. Null for a key metric.",+ )+ previous_value = serializers.FloatField(+ allow_null=True,+ help_text="Value for the period before the last complete one, the base of `change_pct`. Null when unknown.",+ )+ movers = HighlightMoverSerializer(+ many=True,+ help_text="For an insight with several series, the series that changed most last period, biggest change first. Empty otherwise.",+ )class Meta:dataclass = HighlightMetricdiff --git a/products/today/backend/tests/test_highlight_insights.py b/products/today/backend/tests/test_highlight_insights.pyindex b1a0501b20de..6d1e9b358c4b 100644--- a/products/today/backend/tests/test_highlight_insights.py+++ b/products/today/backend/tests/test_highlight_insights.py@@ -274,10 +274,36 @@ class TestRoutineInsights(BaseTest):self.assertEqual([- (m.name, m.value, m.change_pct, m.interval, m.url, m.value_format and m.value_format.format)+ (+ m.name,+ m.value,+ m.change_pct,+ m.interval,+ m.url,+ m.value_format and m.value_format.format,+ m.reason,+ m.opened_days,+ m.last_opened,+ [(mover.label, mover.value, mover.change_pct) for mover in m.movers],+ m.previous_value,+ )for m in pulse],- [("Files opened (Exported report)", 14.0, 100.0, "day", "/insights/abc", "currency")],+ [+ (+ "Files opened (Exported report)",+ 14.0,+ 100.0,+ "day",+ "/insights/abc",+ "currency",+ "routine",+ 10,+ TODAY,+ [("Exported report", 14.0, 100.0), ("Pageview", 7.0, 100.0)],+ 7.0,+ )+ ],)@parameterized.expand(@@ -285,18 +311,21 @@ class TestRoutineInsights(BaseTest):("a session",None,- [("insight:signups", "/dashboard/7"), ("insight:old", "/insights/old")],+ [+ ("insight:signups", "/dashboard/7", "Growth", 2, TODAY - timedelta(days=1)),+ ("insight:old", "/insights/old", None, 0, TODAY - timedelta(days=20)),+ ],),("a key without dashboard access",frozenset({"insight:read"}),- [("insight:old", "/insights/old")],+ [("insight:old", "/insights/old", None, 0, TODAY - timedelta(days=20))],),])@time_machine.travel("2026-10-13T12:00:00Z", tick=False)def test_the_frecency_ranking_shows_a_dashboard_opened_often_as_its_first_working_tile(- self, _name: str, scopes: frozenset[str] | None, expected: list[tuple[str, str]]+ self, _name: str, scopes: frozenset[str] | None, expected: list[tuple[str, str, str | None, int, date]]) -> None:for kind, ref, ages in (("insight", "old", (20,)), ("dashboard", "7", (1, 2))):FileSystemViewLog.objects.create(@@ -336,4 +365,5 @@ class TestRoutineInsights(BaseTest):):pulse = routine.find(Context(self.team, self.user, TODAY, scopes)).pulse- self.assertEqual([(m.key, m.url) for m in pulse], expected)+ self.assertEqual([(m.key, m.url, m.dashboard_name, m.opened_days, m.last_opened) for m in pulse], expected)+ self.assertEqual([m.movers for m in pulse], [[]] * len(expected))diff --git a/products/today/backend/tests/test_highlight_key_metrics.py b/products/today/backend/tests/test_highlight_key_metrics.pyindex 455659419a62..2ec2ac1dc9da 100644--- a/products/today/backend/tests/test_highlight_key_metrics.py+++ b/products/today/backend/tests/test_highlight_key_metrics.py@@ -71,12 +71,15 @@ class TestKeyMetrics(SimpleTestCase):self.assertEqual((- [(m.key, m.value, m.unit, m.change_pct, len(m.series)) for m in found.pulse],+ [(m.key, m.value, m.unit, m.change_pct, m.previous_value, len(m.series)) for m in found.pulse],[(c.title, c.detail, c.label) for c in found.items],[_query(m.url) for m in found.pulse],),(- [("signup_event", 6500.0, "events", -7.1, 28), ("activity_event", 140.0, "people", 0.0, 28)],+ [+ ("signup_event", 6500.0, "events", -7.1, 7000.0, 28),+ ("activity_event", 140.0, "people", 0.0, 140.0, 28),+ ],[("‘Signup event’ decreased by 50% yesterday", "500 yesterday · 1,000 on an average Monday", "risk")],[_trend({"kind": "EventsNode", "event": "signup_event", "math": "total"}),diff --git a/products/today/frontend/generated/api.schemas.ts b/products/today/frontend/generated/api.schemas.tsindex 3bf8886c4373..c45dda59877a 100644--- a/products/today/frontend/generated/api.schemas.ts+++ b/products/today/frontend/generated/api.schemas.ts@@ -92,6 +92,32 @@ export interface HighlightValueFormatApi {decimal_places: number | null}+/**+ * * `routine` - You open this often+ * * `dashboard` - On a dashboard you open often+ * * `key_metric` - Project key metric+ */+export type HighlightMetricReasonEnumApi =+ (typeof HighlightMetricReasonEnumApi)[keyof typeof HighlightMetricReasonEnumApi]++export const HighlightMetricReasonEnumApi = {+ Routine: 'routine',+ Dashboard: 'dashboard',+ KeyMetric: 'key_metric',+} as const++export interface HighlightMoverApi {+ /** Name of one series of the insight, for example a breakdown value. */+ label: string+ /** Value of the series for the last complete period. */+ value: number+ /**+ * Change of the series against the period before, in percent. Null when the period before is 0.+ * @nullable+ */+ change_pct: number | null+}+export interface HighlightMetricApi {/** Stable key of the metric: a key metric setting such as signup_event, or insight:<short_id>. */key: string@@ -127,6 +153,34 @@ export interface HighlightMetricApi {value_format: HighlightValueFormatApi | null/** The first day of the period each value in `series` covers, in the project's timezone. Same length and order as `series`. */period_starts: string[]+ /** Why the pulse shows the metric: `routine` for an insight the person opens often, `dashboard` for a tile of a dashboard they open often, `key_metric` for a key metric of the project. Null for metrics computed before this field existed.+ *+ * * `routine` - You open this often+ * * `dashboard` - On a dashboard you open often+ * * `key_metric` - Project key metric */+ reason: HighlightMetricReasonEnumApi | null+ /**+ * Name of the dashboard the tile comes from when `reason` is `dashboard`, else null.+ * @nullable+ */+ dashboard_name: string | null+ /**+ * On how many of the last 14 days the person opened the insight, or the dashboard of the tile. Null for a key metric.+ * @nullable+ */+ opened_days: number | null+ /**+ * The last day the person opened the insight, or the dashboard of the tile, in the project's timezone. Null for a key metric.+ * @nullable+ */+ last_opened: string | null+ /**+ * Value for the period before the last complete one, the base of `change_pct`. Null when unknown.+ * @nullable+ */+ previous_value: number | null+ /** For an insight with several series, the series that changed most last period, biggest change first. Empty otherwise. */+ movers: HighlightMoverApi[]}/**diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 88b78779b6df..ee097d65f6ff 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -55324,6 +55324,32 @@ export namespace Schemas {decimal_places: number | null;}+ /**+ * * `routine` - You open this often+ * * `dashboard` - On a dashboard you open often+ * * `key_metric` - Project key metric+ */+ export type HighlightMetricReasonEnum = typeof HighlightMetricReasonEnum[keyof typeof HighlightMetricReasonEnum];+++ export const HighlightMetricReasonEnum = {+ Routine: 'routine',+ Dashboard: 'dashboard',+ KeyMetric: 'key_metric',+ } as const;++ export interface HighlightMover {+ /** Name of one series of the insight, for example a breakdown value. */+ label: string;+ /** Value of the series for the last complete period. */+ value: number;+ /**+ * Change of the series against the period before, in percent. Null when the period before is 0.+ * @nullable+ */+ change_pct: number | null;+ }+export interface HighlightMetric {/** Stable key of the metric: a key metric setting such as signup_event, or insight:<short_id>. */key: string;@@ -55359,6 +55385,34 @@ export namespace Schemas {value_format: HighlightValueFormat | null;/** The first day of the period each value in `series` covers, in the project's timezone. Same length and order as `series`. */period_starts: string[];+ /** Why the pulse shows the metric: `routine` for an insight the person opens often, `dashboard` for a tile of a dashboard they open often, `key_metric` for a key metric of the project. Null for metrics computed before this field existed.+ *+ * * `routine` - You open this often+ * * `dashboard` - On a dashboard you open often+ * * `key_metric` - Project key metric */+ reason: HighlightMetricReasonEnum | null;+ /**+ * Name of the dashboard the tile comes from when `reason` is `dashboard`, else null.+ * @nullable+ */+ dashboard_name: string | null;+ /**+ * On how many of the last 14 days the person opened the insight, or the dashboard of the tile. Null for a key metric.+ * @nullable+ */+ opened_days: number | null;+ /**+ * The last day the person opened the insight, or the dashboard of the tile, in the project's timezone. Null for a key metric.+ * @nullable+ */+ last_opened: string | null;+ /**+ * Value for the period before the last complete one, the base of `change_pct`. Null when unknown.+ * @nullable+ */+ previous_value: number | null;+ /** For an insight with several series, the series that changed most last period, biggest change first. Empty otherwise. */+ movers: HighlightMover[];}/**