Analytics collector and dashboard for frontend events.
This app stores analytics events in Postgres and provides:
- an ingestion endpoint (
POST /api/events) - a dashboard with latest events and aggregates (
/)
- React Router (SSR)
- React + TypeScript
- PostgreSQL (
pg) - NAV design system (
@navikt/ds-react) - Recharts
npm installUsing Docker Compose:
docker compose up -d dbThe default local database credentials are:
- database:
analytics - user:
analytics - password:
analytics - host:
localhost - port:
5432
Create .env in the project root:
DATABASE_URL=postgres://analytics:analytics@localhost:5432/analytics
# Optional: require this token on POST /api/events
ANALYTICS_TOKEN=change-menpm run devApp is available at http://localhost:5173.
GET /- analytics dashboard (latest events + totals per app and tenant)GET /views- page views report with range selector and chartPOST /api/events- ingest one event or batchOPTIONS /api/events- CORS preflight
POST /api/events accepts either:
- a single event object, or
{ "events": [ ... ] }
{
"ts": "2026-02-27T10:15:00.000Z",
"app": "fint-min-app",
"type": "page_view",
"path": "/home",
"element": "search-button",
"tenant": "my-tenant",
"meta": {
"query": "search-params"
}
}Notes:
appandtypeare requiredtypesupportspage_view,button_click,search- max 10 events per request
- if
ANALYTICS_TOKENis set, send it asx-analytics-token
Single event:
curl -X POST "http://localhost:5173/api/events" \
-H "Content-Type: application/json" \
-H "x-analytics-token: change-me" \
-d '{
"app": "fint-min-app",
"type": "page_view",
"path": "/"
}'Batch:
curl -X POST "http://localhost:5173/api/events" \
-H "Content-Type: application/json" \
-H "x-analytics-token: change-me" \
-d '{
"events": [
{ "app": "fint-min-app", "type": "page_view", "path": "/" },
{ "app": "fint-min-app", "type": "button_click", "element": "save" }
]
}'npm run dev- start dev servernpm run build- production buildnpm run start- run built servernpm run typecheck- React Router typegen + TypeScript check
To run both services:
docker compose up --buildThis starts:
dbon5432appon3000
When using Compose app service, DATABASE_URL points to the db service internally.