@ossy/analytics
v3.21.0
Published
Analytics module — Host visitor traffic for registered domains
Downloads
1,818
Readme
@ossy/analytics
Host-traffic analytics. See SPEC.md.
Platform-wide (ops) insights belong in a back-office Mongo dashboard — ADR 0014.
Pages
| Page | Path | Audience |
|------|------|----------|
| analytics/home | /analytics · /analys | Signed-in + entitled → traffic for a registered Host. No domain → empty state. Otherwise the public sales page (no stats loads). |
Workspace member/resource counts are not this package — they belong on workspace settings.
Actions
| Action | Access | Notes |
|--------|--------|-------|
| @ossy/analytics/actions/create-page-view | public | Ingest. Server resolves Host (hostname / Origin) with @ossy/domains/actions/find-by-domain (content.domain). www is a different host. Unknown Host → 200 no-op (recorded: false). Connection ip is stamped on the eventstore row (ADR 0016). |
| @ossy/analytics/actions/get-page-view-stats | workspace | Stats for a Host this workspace registered (host required). The Host is confirmed with ListResources on /@ossy/domains/. Window is whole UTC days of resource created. Traffic from per-day PageViewStatsProjection snapshots; byCountry from the location projection. |
| @ossy/analytics/actions/get-workspace-kpis | workspace | Member + resource counts — UI on /settings; not shown on /analytics. |
Locations (#769)
Event (source of truth): after Host allowlist, the page-view eventstore row carries the trusted connection IP (ip, ADR 0016). Client body ip / countryCode and viewer geo headers are ignored. Unknown Hosts never write an event.
Read models:
PageViewStatsProjection(@ossy/analytics/data/page-view-stats) — one snapshot per Host per UTC day (workspaceId:host:YYYY-MM-DD). Stores that day's view count, the set ofvisitorIds, and up to 2000 path counts (#960). A range unions those id sets, so a returning visitor counts once.PageViewLocationProjection(@ossy/analytics/data/page-view-location) — same per-day scope (workspaceId:host:YYYY-MM-DD). Mapsevent.ip→ ISOcountryCodevia MaxMind GeoLite2-Country (GEOLITE2_COUNTRY_MMDB) and stores{ views, visitors }per country for that day (#966). A range unions those ids. Rebuilding with a new.mmdbrefreshes historical countries while events keep raw IPs.
Day keys use envelope created as a UTC date. from / to include those whole days.
Database on containers (#804): @ossy/platform startServer downloads GeoLite2-Country at boot when MAXMIND_LICENSE_KEY is set (same path on ossy.se, plexus-sanitas, and any future website image). ECS sets GEOLITE2_COUNTRY_MMDB=/tmp/GeoLite2-Country.mmdb. Do not commit .mmdb files. Locally: export the key (and optionally the path) before npx platform start. Startup rebuild (AggregateRebuild.BuildAndSaveAll) then fills historical byCountry. This product includes GeoLite2 data created by MaxMind, available from https://www.maxmind.com
UI: location tiles show unique visitors per country — never show IP. Host-scoped (pick a domain on /analytics).
Preview
Enable Analytics, register a domain on the workspace, then open /analytics and select that Host.
