Architecture
MikroAnalytics follows the MikroSuite pattern: a small product surface, a plain Node runtime, a local database, and static assets built for production.
Runtime
Section titled “Runtime”- Server: Node.js HTTP server.
- Dashboard: Vanilla HTML, CSS, and TypeScript.
- Tracker: Tiny browser script served from
/m.js. - Configuration: MikroConf-backed
mikroanalytics.config.jsonfor runtime settings. - Runtime config: Public browser settings at
/config.json; secrets stay server-side. - Storage: SQLite through
node:sqlitefor sites and aggregates. - Auth: MikroAuth magic links with HttpOnly session cookies.
- Build: esbuild, Lightning CSS, and HTML minification.
Request Flow
Section titled “Request Flow”- The website loads
/m.jswith adata-siteattribute. - The tracker sends pageviews, navigation changes, and custom events to
/api/collect. - The server validates the site, origin host, privacy signals, event name, path, referrer, campaign values, and event properties.
- The database updates aggregate counters by site and date.
- The dashboard manages sites through
/api/sitesand reads reports through/api/report.
Data Model
Section titled “Data Model”MikroAnalytics stores independent aggregate tables:
daily_totals,page_counts,event_counts,referrer_counts,campaign_counts,browser_counts,os_counts,device_counts,country_counts,daily_uniques,sites,raw_eventsfor optional short-lived debugging.
This keeps reporting simple and avoids needing raw event history for normal operation.
Privacy Boundary
Section titled “Privacy Boundary”The sanitizer is the core privacy boundary. It strips query strings and fragments from paths, normalizes referrers according to policy, filters event properties, blocks common sensitive property keys, summarizes user agents into broad dimensions, and ignores requests with DNT or GPC signals.
Raw request metadata is used only while handling the request unless an explicit optional feature needs it, such as daily unique estimation.
Operational Boundary
Section titled “Operational Boundary”The browser collect endpoint is public by design, but it only accepts dashboard-managed site IDs and allowed hosts. Dashboard and reporting endpoints require a session cookie or bearer token.
Keep the SQLite database on persistent storage, back it up, and run cleanup on a schedule that matches your retention policy.
Why This Shape
Section titled “Why This Shape”MikroAnalytics chooses boring parts on purpose. The product should be easy to inspect, easy to self-host, and easy to remove. A team should be able to understand what data is collected without reverse-engineering a vendor pipeline.