BI events
Retired by PostHog (#971 and #977, merged 2026-10-15)
The Pipelines → R2 Iceberg pipeline and R2 SQL described below were removed in #971. The event catalog still applies and rows go to PostHog; POST /api/bi and its rules were removed in #977. Current repo doc: docs/product-events.md. See Product events move to PostHog.
#977 (step 5, merged 2026-10-15) went further: it removed POST /api/bi, and browser events now go straight to PostHog with posthog-js. See PostHog — Step 5 (#977, merged) and Browser events direct to PostHog.
Behavioural analytics for Brilliant: studio and workers emit named events into an Iceberg table (Cloudflare Pipelines → R2), queried with R2 SQL. Same shape as monday’s BigBrain (event name, kind, placement, tenant/user/app ids, a data JSON blob) so queries transfer.
Canonical repo doc: docs/bi.md. Catalog of record is code, not this page.
Pipeline (sketch)
studio / site ──POST /api/bi──▶ control-plane ──env.BI.send()──▶ stream → pipeline → R2 Iceberg
conductor / dispatch ──/ingest/*──▶ control-plane ──┘| Piece | Role |
|---|---|
| Emit (workers) | track(env, ctx, source, evt) from @brilliant/capabilities |
| Emit (browser) | track(event, props) from packages/composer (studio + site); no-op when localStorage["brilliant.bi.off"]="1" |
| Ingest | Control-plane POST /api/bi (session + visitor no-session branch, #364 merged) and internal /ingest/* paths |
| Off switch | Remove the pipelines block in apps/control-plane/wrangler.jsonc |
| Schema of record | infra/bi/stream-schema.json — a row that does not match is accepted by the stream and dropped by the pipeline with no error on our side |
One stream for every env; env is staging or the side-env name. Filter on it. Provisioning details stay in the repo doc / docs/prod-prep.md (account and stream IDs are not copied here).
Catalog
packages/capabilities/src/bi-events.ts owns every event name that may land in the event column. Add the entry there first; do not re-list the full catalogue on this page. grep BI_EVENTS.<name> finds emitters.
Never put prompt text or user content in data. Lengths, counts, ids, model names, and outcomes only. The LangSmith trace has the text.
source is brilliant-app for everything today (server and browser both pass through the control plane). Keep the column for a second producer later.
Emitter classes (#363 + #364, merged)
Security contracts from merged #363 (closes #309) and merged #364 (closes #321).
The session on POST /api/bi pins tenant and user. It does not pin session_id or data. If the browser could post platform lifecycle rows (signed_up, app_created, …), a signed-in user could inflate funnels or forge campaign attribution (utm_campaign on signed_up).
| Class | Who emits | How |
|---|---|---|
| visitor | Landing / marketing before sign-in | POST /api/bi without a session |
| browser | Studio / site client after sign-in (MCP tools may also emit shared funnel events) | POST /api/bi with a session |
| platform | Control plane / workers only | Server track / ingest paths — never the browser |
Classification lives next to the catalog as BI_EVENT_POSTED_BY in bi-events.ts. It satisfies Record<BiEventName, "visitor" | "browser" | "platform">, so a new event does not compile until it is classified.
Contract bi-browser-events-only (#363, on main): with a session, /api/bi accepts BROWSER_BI_EVENTS (visitor ∪ browser). A batch that names a platform event is rejected with 400 and emits nothing. Studio/site track() is typed to that set. placement must not be MCP_PLACEMENT ("mcp", any case / surrounding space) — that tag marks the platform's MCP funnel rows.
Platform-only names (pinned by test)
signed_up, app_created, turn_settled, app_deployed, app_access_changed, app_published, mcp_connected, mcp_revoked, mcp_tool_called.
Visitor names
page_viewed, prompt_submitted, suggestion_clicked, model_changed — classified visitor in BI_EVENT_POSTED_BY. With a session they are still accepted (they are in BROWSER_BI_EVENTS); without a session they are the only allowed names.
Attribution note
signed_up is emitted server-side once when /auth/callback creates the user, carrying first-touch attribution from the marketing hand-off. See Marketing site — Attribution. That path must stay platform-only.
Visitor ingest (#364, merged)
Landed in #364 (merged 2026-10-03, yoni-monday). Closes #321. Contract bi-visitor-ingest-bounded.
Before this, /api/bi sat behind session middleware, so signed-out landing batches (page_viewed, prompt_submitted, …) got a 401 the client swallowed. The campaign funnel had signups and nothing before them.
| Piece | Behaviour |
|---|---|
| No-session branch | Only VISITOR_BI_EVENTS; at most 20 events per batch |
| Identity | Rows carry no tenant_id, user_id, app_id, or turn_id (zod drops them whatever the body says) |
| Rate limit | BI_VISITOR_RATELIMIT — 30 batches / minute per IP (ns 4606); runs before the body is read. Missing, failing, or exhausted → 429, nothing emitted |
| Session present | Valid or not (cookie or Bearer) → session middleware; invalid cookie stays 401, never quietly anonymous |
| Funnel join | BI session_id via /start → signed_up |
Trade-off: a shared office NAT with many visitors can lose some landing rows at 30/min/IP.
Related
Replaced by PostHog (#948, #971 merged)
The PostHog PR stack replaces this BI pipeline with PostHog and removes the admin's BI page. Step 1, #948, merged 2026-10-15 and only adds the studio client and identity. Step 2, #953 (merged), replaced Sentry with PostHog error tracking and did not touch this pipeline. Step 4, #971, is the BI step and merged 2026-10-15 16:41 IDT: product events now go to PostHog. Step 5, #977, merged 2026-10-15 21:25 IDT: it removed POST /api/bi, and browser events go straight to PostHog. See PostHog.
Product events move to PostHog (#971, merged)
#971 (merged 2026-10-15 16:41 IDT by yoni-monday, merge cb7500e1) keeps the event catalog and the ingest rules on this page but sends every row to PostHog instead of the Pipelines stream into R2 Iceberg. The pipeline and R2 SQL parts above are now history; the Cloudflare resources are destroyed on the next infra run per stack.
- Unchanged: the 25-event catalog and names in
bi-events.ts,BI_EVENTS, theBiEventrow type,BI_EVENT_POSTED_BYclassification, the browser client (batching, session id,brilliant.bi.offkill switch), andPOST /api/biwith its visitor branch, batch limits,BI_VISITOR_RATELIMITand thedatasize cap.- #977 (merged 2026-10-15 21:25 IDT) removed
POST /api/bi, the visitor class,session_idand thebrilliant.bi.offswitch, so this bullet is now history.
- #977 (merged 2026-10-15 21:25 IDT) removed
- New transport: worker
track()and/api/bisend rows to PostHog's/batch/endpoint in one request (staging project666164, prod664776).distinct_idis the user, elsesid:<session_id>, elsetenant:/app:/anonymous. Browserdatacan no longer set$keys,token,api_key,distinct_idor any column name such astenant_id(only$current_urlis kept, cut to origin and path). - Impersonated browser batches are accepted but not forwarded. Server-side events under an act session still carry the customer's
user_id. signed_upalso sends$identifywith$anon_distinct_id=sid:<sid>, so the landing funnel merges into the new user in PostHog (it replaces thesession_idjoin through/start).- #977 (merged) replaced this server-side merge with a browser
identify(user.id)after sign-in.
- #977 (merged) replaced this server-side merge with a browser
page_viewedis removed. The studio uses posthog-js$pageview; the marketing contact page sendsBI_EVENTS.pageview($pageview).- Removed: the Pipelines stream, sink, pipeline and catalog (the Iceberg history goes with them),
infra/bi/**includingstream-schema.json, theBIbinding, the admin BI, dashboards, SQL console and dashboard-chat pages, andpackages/dashboards. R2 SQL queries stop working. Thebrilliant-bibucket is retained for now and is emptied and deleted by hand. - Repo doc:
docs/bi.mdis nowdocs/product-events.md.
Full design notes and rollout: PostHog — Step 4 (#971, merged).
Browser events direct to PostHog (#977, merged)
#977 (merged 2026-10-15 21:25 IDT by yoni-monday, merge 13576e01; branch posthog-5-browser-events) is step 5 of the PostHog stack. Most of the ingest rules recovered on this page are now history too. The HTML body above stays as historical context.
POST /api/biis removed, with its per-IP rate limit (BI_VISITOR_RATELIMIT) and the site worker's proxy for it. The studio and the marketing site send browser events straight to PostHog with posthog-js. Server-emitted events are unchanged.- The visitor class is gone. Without
/api/bi,visitorandbrowserno longer differ, soBI_EVENT_POSTED_BYisbrowser|platformandVISITOR_BI_EVENTSis removed. - The
session_idcolumn is gone. The site hands its PostHog id to the studio asdid(replacingsid) in the/startfragment; the studio accepts only a UUIDv7 and only while the visitor is anonymous. A browseridentify(user.id)after sign-in merges the landing events into the user, instead of the server-side$identify. The site keeps the id in the tab'ssessionStorage, with no cookie or localStorage entry. - The
brilliant.bi.offkill switch is gone. PostHog's own opt-out replaces it. - Browser events are forgeable. The PostHog project token is public, so never build anything that trusts a browser event. The server's
source: "brilliant-app"is forgeable too.
Full design notes and tradeoffs: PostHog — Step 5 (#977, merged).
Semantic lint events added (#1008, merged)
#1008 (merged 2026-10-17 14:28 IDT) adds semantic_lint_run and semantic_lint_finding to BI_EVENTS, both classified platform in BI_EVENT_POSTED_BY. The conductor sends them after a passing typecheck when the tenant's semantic_lint flag is on. Properties: Semantic lint, Analytics in PostHog.