Usage
What people do in a program: which screens they open, which actions and
calls they use, what fails, who comes back, and measures of the program's
own (track); and the web's own numbers a site's owner looks for in Google
Analytics or Plausible: visitors, visits, pageviews and bounces, where visits
came from, the country, the browser and device, goals, who is here now and
how fast each page loaded. Kept in the program's own database and shown on
its own admin page. Optional, off unless said, nothing leaves the back end,
and by default no IP address is kept and no lasting id is stored in the
browser (what is collected). Every event kept one by one and asked
of later (funnels, retention, paths, people, flags, experiments, ClickHouse) is
analytics.md. Back to the map.
app "Shop" usage=onuse "pkg:usage/usage.mote"// Who may read usage: this program's answer.fn usageMay(): bool let me = auth.me()? return me?.email == "owner@shop.example"// What counts as a visit reaching what it is for (optional).fn usageGoals(): string[] = ["checkout", "/thanks"]action checkout track("checkout", {plan: cart.plan, total: cart.total})route "/admin/usage" UsagePanel UsageChart event="checkout" by="plan" last="30 days"# mote.toml, beside the entry[packages]usage = "../mote/extensions/usage"That is all of it. With those lines the admin page shows visitors, visits,
pageviews, pages a visit, the bounce rate and the time in front against the
span before; the pages with their entrances and exits, the sources and
campaigns, the countries, the devices and browsers, the goals, who is here
now and how fast each route loaded; then people active today, this week and
this month, the screens, actions and calls most used with how often each
fails and how long it takes, what track was told, and who came back week
by week.
Mental model#
There are two parts, and only the first is in Mote itself.
- The seam (the compiler and the runtime). The runtime already sees a
screen shown, an action run, a call answered, a sign-in, a job's run. With
usage=onit gathers them, with whattrack(…)says, and hands them to the program's own code:server on usage(batch)+ a block, every five seconds. It keeps nothing itself. - The extension (
extensions/usage, ordinary Mote in a package). It has theserver on usageblock, the models the events are kept in, the questions asked of them asserver fns, and the panel's components. It is not in the compiler: a program takes it withuse, and can read it, change it, or write its own.
Without both usage=on and a server on usage block nothing is gathered
and nothing of this is built: the page and the back end are byte for byte
what they are without it, and a track(…) line compiles to nothing.
Turning it on#
What is gathered#
What is collected#
What is never gathered#
Cookies and consent#
The web's numbers#
Where visits come from#
Where people are#
Browsers and devices#
Bots#
Speed#
Now#
The open line#
Autocapture#
Goals#
track#
app "Shop" usage=onshape Cart plan: string total: numberstate cart: Cart = {plan: "pro", total: 40}state seen = 0server fn pay(plan: string, total: number): number // On the back end too: as whoever made the call. if total > 1000 track("large order", {plan}) return total// A consumer of one's own: every batch, counted. (The extension is one of these.)model Tally name: string key count: int = 0server on usage(batch) for e in batch let name = `${e.kind} ${e.name}` let row = Tally.get(name)? if row == none Tally.add({name, count: 1})? else Tally.set(name, {count: row.count + 1})?server fn tallied(): number return Tally.count({})?action checkout pay(cart.plan, cart.total)? track("checkout", {plan: cart.plan, total: cart.total, gift: false}) seen = tallied()?button "Check out" press=checkouttext `${seen}`The panel#
Who may read it#
The questions#
A visitor who signs in#
Several apps, one panel#
What is kept, and for how long#
The seam#
app "Shop" usage=on geo=city paths=full vitals=all// A consumer of one's own: screens by where, campaign and address, as each page's browser said them.model Seen key: string key count: int = 0fn where(c: UsageClient): string = c.city ?? c.country ?? (c.zone == "" ? "(unknown)" : c.zone)server on usage(batch) for e in batch let c = e.client if c == none || e.kind != "screen" continue let campaign = e.utm?.campaign ?? "(none)" Seen.put({key: `${where(c)} ${campaign} ${e.path ?? e.name}`, count: 1}, {count: inc(1)})?route "/" text "Home"route "/job/:id" text `Job ${id}`What it costs#
docs/usage.md