: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.
Live widgets (self-updating tiles)
A live widget seeds once from run_widgets, then self-updates client-side — it does not rely on the dashboard refresh loop for freshness.
This doc is the paved path for building one.
Examples below reference web analytics live widgets, the first consumer of the platform — they show how it is meant to be used rather than code the platform itself ships.
The contract
Backend SSOT is two WidgetSpec fields in widget_specs/registry.py:
is_live: bool— marks the type as live. Flows intowidget-form-fields.json(viahogli build:widget-types), resolved onto the FE catalog asentry.live(read it there, or viaisLiveDashboardWidgetType()where no entry is at hand); also exposed asliveon the REST/MCP widget catalog. Do not hand-maintain FE live-type lists.creation_flag: str | None— adds-only rollout gate, resolved generically inwidget_create.pyviafeature_flags.widget_flag_enabled. Creating a tile requires the flag; already-placed tiles keep rendering when it's off. Not live-specific — any spec may set it — but new live widget families should, as their kill switch.
What is_live buys for free: a pulsing "Live" marker in the tile header (WidgetCardHeader), a "Live" tag on the Add-widget picker card, and the live field agents see in dashboard-widget-catalog-list.
Rules a live type must follow (WidgetSpec enforces rule 3 at construction — a violating spec fails on any import of the registry, so tests, codegen, and web all catch it; rules 1-2 are conventions, with the merge behavior guarded by LiveWidgetSlidingWindow.test.ts):
- The
run_widgetsresult is a seed, not the state. Its payload must carrygeneratedAt— the server clock at query time (ISO-8601). SeeLiveWidgetSeedPayloadinwidgets/live/liveWidgetTypes.ts. - Seeds must be idempotent. Manual tile refresh and dashboard auto-refresh re-run
run_widgetsand re-seed; the platform does not skip live tiles (a re-seed heals stream gaps from dropped connections or hidden tabs). Merge seeds so a re-run never double counts — see the sliding-window semantics below. - No
dateRangeorfilterTestAccountsconfig. Live tiles show a fixed real-time window (dateRange contradicts it), and the livestream can't apply test-account filters, so seed and stream would disagree. The header's date range hides automatically for live types (catalog resolution defaultsshowDateRangeto false whenlive).
Backend conventions
The seed query is ordinary product code — a query_fn in products/dashboards/backend/widgets/<type>.py delegating to the product's query module (the WA seeds will live in a dedicated module such as products/web_analytics/backend/hogql_queries/live_widget_seeds.py, named apart from the /web/live page's own client-side seed queries).
Conventions:
- Return
generatedAt(datetime.now(UTC).isoformat()at query time) in every payload. - Accept and ignore
include_total_count— it's part of the genericquery_fncalling convention. - Keep the window length a constant in product code, mirrored by a FE constant (e.g. a 30-minute window on both sides), and cap payload size — the seed rides the batched
run_widgetsresponse.
Frontend toolkit — products/dashboards/frontend/widgets/live/
Compose these:
| Module | What it does |
|---|---|
liveWidgetTypes.ts — isLiveDashboardWidgetType(), LiveWidgetSeedPayload |
FE read of WidgetSpec.is_live from the generated manifest, plus the base seed-payload interface (generatedAt) — extend it in your result types |
LiveWidgetSlidingWindow |
Minute-bucketed window: overall count + named breakdown domains, each fed by an extractor (event) => string | null (null = skip). Encodes the seed-merge correctness rules — see below |
useLiveWidgetSeed(payload, seed) |
The one prop→action React bridge: seeds your logic from the tile's result prop (pass null while the payload isn't ready) |
components.tsx — LiveWidgetEmptyState |
"No data in the window yet" body with optional CTA |
components.tsx — LiveWidgetIndicator |
The pulsing "Live" header marker (platform-rendered — you don't wire this) |
Seed-merge semantics (do not "simplify" these): the SSE stream reads Kafka (fresh) while seeds read ClickHouse (can lag ingestion). LiveWidgetSlidingWindow therefore merges seeds via per-bucket max (never replace — an empty lagging re-seed must not wipe stream-accumulated counts) and drops streamed events at or before the domain's seed generatedAt (strict >), so a re-seed never double counts. widgets/live/LiveWidgetSlidingWindow.test.ts guards these.
One connection per dashboard: make the product's live logic unkeyed and share it across the family's tiles — kea ref-counting keeps one connection or poller no matter how many live tiles are placed, and tears it down when the last unmounts. Reset state in afterMount so data can't leak across dashboards.
Transports: no transport helper ships with the toolkit. The contract is transport-agnostic: feed the window from a polling helper with an onEvents/onMinuteTick shape, or re-run the seed query on an interval.
Recipe: shipping a new live widget family
On top of the normal new-type checklist:
- Spec:
is_live=True,creation_flag="<your-rollout-flag>", nodateRange/filterTestAccountson the config model (enforced at spec construction). - Seed query in your product's backend returning
generatedAt; thinquery_fnwrapper inwidgets/<type>.py. - Catalog entry as normal —
showDateRangehides automatically for live types. To keep the picker card hidden pre-release, land the FE catalog entry with the release;creation_flagis the backend gate either way (availability-and-gating.md). - One unkeyed shared logic on
LiveWidgetSlidingWindow(or your own windowing if minute buckets don't fit — keep the idempotent-seed rule). - Components:
useLiveWidgetSeed(payload, seedAction), render from selectors,LiveWidgetEmptyStatewhen the window is empty. hogli build:widget-types(regenerates the manifest the FE catalog readslivefrom), then the normal verify suite.
Web analytics live widgets (products/dashboards/frontend/widgets/web_analytics/) are the first consumer to follow this recipe end to end.