Analytics: how long people play, and where they stop
local s = analytics.session() -- the session under way, or the last one
print(s.context, s.seconds) -- "editor", 92.4
for _, visit in s.scenes do
print(visit.scene, visit.seconds)
end
print(s.ended and s.ended.by, s.exit and s.exit.scene) -- "edit", "bridge"
analytics.sessions() lists every session of the world the engine holds,
oldest first: this run's, and on an engine bound to a world the ones the
device kept from earlier runs. A session another run left open reads open
until 90 seconds after its record was last written down (another engine on
the device may still be playing it), and lost from then on. /zero/runtime/analytics/session,
/zero/runtime/analytics/sessions and /zero/runtime/analytics/status serve
the same documents to a tool or an agent that reads files.
What a session holds
| Field | What it says |
|---|---|
context | player (a runtime boot), editor (a play in the editor), agent (a play an agent entered, or a sub-client's) |
seconds, startedAt | how long it ran, and when it began (Unix ms) |
ended.by | edit (left play), quit, background, swap (the world unloaded), restart, or lost: the engine ended without closing it, and the next run of the world on the device closed it |
scenes | each scene it went through: scene, at (the second it entered), seconds (how long it stayed) |
transitions | how many times it moved to another scene |
milestones | firstInput: the second a person first pressed, clicked or touched anything; playable: the second the world was first playable |
frames | one summary per minute of play: frames, meanMs, p50Ms, p95Ms, worstMs, hitches (frames of 50 ms or more), longHitches (100 ms or more); the minute under way is partial |
loads | each scene load and how many milliseconds it took |
errors | script errors, watchdog halts (halt) and failed module loads (load), counted by the asset that raised them |
exit | where an ended session stopped: scene, cell (the viewport camera's 4-metre cell), inputAgeSeconds (seconds since the last input), lastEvent (the last name analytics.count filed) |
scene, cell, inputAgeSeconds, lastEvent | the same four, now, for a session still open |
cost | the recorder's own time on the engine thread per frame |
A session with exit.inputAgeSeconds far above a few seconds ended with
nobody pressing anything: the person had stopped playing before the session
ended. A session that ended lost ended badly (a crash, a closed tab, the
system ending the app).
Reading a playtest
Play the world (enter play, drive it, leave play), then read the session:
local s = analytics.session()
assert(s.ended.by == "edit")
local last = s.scenes[#s.scenes]
print(`stopped in {s.exit.scene} after {s.seconds}s, {last.seconds}s in that scene`)
for _, e in s.errors do
print(`{e.asset} raised {e.count} {e.class} error(s)`)
end
Across sessions, analytics.sessions() answers how long people play and where
they stop:
local stops = {}
for _, s in analytics.sessions() do
if s.exit then
stops[s.exit.scene or "?"] = (stops[s.exit.scene or "?"] or 0) + 1
end
end
Filing a world's own measurements
Three calls file anything else into the open session, kept apart for each set of dimensions:
analytics.count("door.opened", 1, { door = "north" }) -- a count
analytics.sample("lap.seconds", 31.5) -- a distribution: count, sum, min, max, mean
analytics.spatial("deaths", body.transform.position) -- a heat layer of 4-metre cells
A name is a slug: lowercase letters, digits, _, - and ., at most 48
bytes. Dimensions are up to 4 slug keys, each holding a slug, a number or a
boolean. Anything else (a name a player typed, a sentence) is filed under
other, stated once in the log, and the call answers false. With no session
open the calls answer nil and record nothing.
Where the records are kept
On the device only: an engine bound to a world keeps its sessions (up to 32 per
world) in the engine's data directory on a desktop or Android, and in the
browser's IndexedDB on the web. An --offline engine keeps them for its own
run. /zero/runtime/analytics/status names where.