• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
pchinjr

pchinjr

valtown_project_analytics

Reusable analytics for Val Town apps.
Public
Like
valtown_project_analytics
Home
Code
2
README.md
H
main.ts
Environment variables
Branches
1
Pull requests
Remixes
History
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.
Sign up now
Code
/
README.md
Code
/
README.md
Search
3/19/2026
README.md

ValTown Project Analytics

Public Val Town analytics service:

  • https://www.val.town/x/pchinjr/valtown_project_analytics

Live service:

  • https://pchinjr--2dfdceb4239511f1baa142dde27851f2.web.val.run

Overview

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.

Routes

  • GET / Human-readable landing page with usage notes
  • GET /client.js Reusable browser client
  • POST /track Event ingest endpoint
  • GET /summary?project=<name> Per-project summary with unique sessions, totals, and recent events
  • GET /events?project=<name>&limit=25 Recent per-project event stream
  • OPTIONS * CORS preflight handling

Data Model

Events are stored in a shared SQLite table named events.

Columns:

  • id
  • project
  • event
  • session_id
  • page_path
  • page_url
  • referrer
  • source
  • user_agent
  • ts
  • received_at
  • props_json

Indexes:

  • idx_events_project_ts
  • idx_events_project_event_ts

Browser Integration

<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>

Client API

window.ValTownAnalytics.init(config) accepts:

  • project
  • endpoint optional override
  • globalProps optional object merged into every event
  • debug optional boolean

It returns:

  • track(event, props)
  • sessionId()

Behavior:

  • generates and persists a browser session id in localStorage
  • uses navigator.sendBeacon when available
  • falls back to fetch with keepalive

Event Shape

{ "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 } }

Recommended Metrics

  • page_viewed
  • quiz_started
  • question_answered
  • quiz_completed
  • share_clicked
  • share_copied
  • cta_clicked

Tradeoffs

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

Files

  • main.ts Full analytics service implementation
  • README.md Project documentation
FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
AboutAlternativesPricingBlogNewsletterCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
© 2026 Val Town, Inc.