Extensions
Analytics
Every event a program sees, kept one by one and asked of later: how many and by what, who came back, how far people got through a funnel, what they did next, who is new and who has gone quiet. Two declarations do it, each written like a model, and the usage extension builds a product analytics tool on them (PostHog's ground: people, funnels, retention, flags, experiments, dashboards). Back to the map; usage.md is what the runtime gathers.
log Events: an append-only, ordered, durable log on the back end, the program's own Kafka. Rows go in by the thousand, each gets an offset (0, 1, 2 … with no gaps), and consumers (server on Events(batch)) each read it in order from their own place, at least once. A door (capture) takes events from other sites and programs, PostHog's shape included.fact Event: an analytics table, wide and append-mostly, asked by time and grouped. SQLite by default, in a file of its own; Postgres where the program's models are (MOTE_SQL=postgres://…), the log with it; ClickHouse whereMOTE_ANALYTICSnames one. The same questions (trends, uniques, percentiles, breakdowns, funnels, retention, paths, stickiness, lifecycle, frequency) are written for either.use "pkg:usage/analytics.mote": the two of them already declared, fed byusage=onand the door, with people, cohorts, feature flags, experiments, saved insights, dashboards, export, webhooks and a panel (below).
Examplea whole program
app "Shop"// Everything that happened, as it came, for a week. `capture`: POST /capture takes it from outside.log Events plan: string = "" keep 7 days capture// The same events, for 400 days, asked by time; and a count of each name each day, kept as they come.fact Event plan: string = "" total: number = 0 rollup daily by name, day count, uniq(who)// The consumer that moves the log into the store, in batches.server on Events(batch) as store Event.addAll(batch)?server fn bought(plan: string, total: number) requires signedIn let me = auth.me()? Events.append({name: "checkout", who: me?.id ?? "", plan, props: {total}})?server fn report(): json requires signedIn let daily = Event.trend({last: "30 days", every: "day", by: "plan"})? let funnel = Event.funnel({steps: ["/", "/cart", "checkout"], within: 24})? let back = Event.retention({every: "week", periods: 8})? return {daily, funnel, back}text "A shop"Mental model#
log#
Consumers#
How it is kept#
In Postgres#
The capture door#
fact#
SQLite, unless said#
Postgres, where the models are#
ClickHouse, where said#
Questions#
Product analytics#
The panel#
Left out on purpose#
What it costs#
Refused#
Edit this page:
docs/analytics.md