Extensions
Usage
Extensions
usage.md

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.

mote
app "Shop" usage=on
use "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"
toml
# 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=on it gathers them, with what track(…) 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 the server on usage block, the models the events are kept in, the questions asked of them as server fns, and the panel's components. It is not in the compiler: a program takes it with use, 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#

The web's numbers#

Where visits come from#

Where people are#

Browsers and devices#

Bots#

Speed#

Now#

The open line#

Autocapture#

Goals#

track#

Examplea whole program
app "Shop" usage=on
shape Cart
plan: string
total: number
state cart: Cart = {plan: "pro", total: 40}
state seen = 0
server 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 = 0
server 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=checkout
text `${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#

Examplea whole program
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 = 0
fn 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#

esc
1072 sections of 111 pages, ranked as you type.A heading's words count for more than what stands under it.
↑↓move
↵open
ranked by BM25, in the page