
Public
Likevaltown_project_analytics
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Public Val Town analytics service:
Live service:
valtown_project_analytics is a reusable analytics service for lightweight event tracking across multiple Val Town projects.
It provides:
- a browser client script you can drop into any Val Town app
- an ingest endpoint for event writes
- simple JSON reporting endpoints for summaries and recent events
- shared storage using Val Town global SQLite
This is intentionally small and pragmatic. It is meant for meaningful product events, not full session replay or enterprise analytics workflows.
GET /Human-readable landing page with usage notesGET /client.jsReusable browser clientPOST /trackEvent ingest endpointGET /summary?project=<name>Per-project summary with unique sessions, totals, and recent eventsGET /events?project=<name>&limit=25Recent per-project event streamOPTIONS *CORS preflight handling
Events are stored in a shared SQLite table named events.
Columns:
idprojecteventsession_idpage_pathpage_urlreferrersourceuser_agenttsreceived_atprops_json
Indexes:
idx_events_project_tsidx_events_project_event_ts
<script src="https://pchinjr--2dfdceb4239511f1baa142dde27851f2.web.val.run/client.js" defer></script> <script defer> window.addEventListener("DOMContentLoaded", function () { const analytics = window.ValTownAnalytics.init({ project: "my-project", globalProps: { app: "my-project", }, }); analytics.track("page_viewed", { screen: "landing" }); }); </script>
window.ValTownAnalytics.init(config) accepts:
projectendpointoptional overrideglobalPropsoptional object merged into every eventdebugoptional boolean
It returns:
track(event, props)sessionId()
Behavior:
- generates and persists a browser session id in
localStorage - uses
navigator.sendBeaconwhen available - falls back to
fetchwithkeepalive
{ "project": "guess-that-hype", "event": "quiz_started", "sessionId": "vt-...", "pagePath": "/", "pageUrl": "https://example.web.val.run/", "referrer": "https://example.com/", "source": "browser", "ts": "2026-03-19T13:00:00.000Z", "props": { "runId": "...", "questionsPerRun": 8 } }
page_viewedquiz_startedquestion_answeredquiz_completedshare_clickedshare_copiedcta_clicked
Good fit for:
- custom event analytics across several Val Town projects
- product funnels and lightweight reporting
- simple owner-controlled instrumentation
Not designed for:
- session replay
- identity stitching across devices
- advanced cohort analysis
- enterprise-scale analytics workloads
main.tsFull analytics service implementationREADME.mdProject documentation