A real-time web analytics tracker and dashboard hosted on Val Town.
┌─────────────────────────────────────────────────────────────────┐
│ Server Side │
├─────────────────────────────────────────────────────────────────┤
│ counterTown.tsx Main HTTP server/router + tracking │
│ counterTownDb.tsx SQLite database layer (sites, views) │
└─────────────────────────────────────────────────────────────────┘
↓ SSE stream
┌─────────────────────────────────────────────────────────────────┐
│ Client Side │
├─────────────────────────────────────────────────────────────────┤
│ counterTownClient.tsx React app entry point + routing │
│ AnalyticsContext.tsx State management via SSE connection │
│ Dashboard.tsx Main dashboard orchestrator │
└─────────────────────────────────────────────────────────────────┘
Main entry point that handles:
CounterTown class for tracking logic and origin validationSQLite database layer with three tables:
sites - Tracked sites with total view countspath_analytics - Per-path stats (views, referrers, browsers, OS, etc.)view_timestamps - Individual view timestamps for time-series dataExports: initAnalytics(), trackPageView(), getAnalytics(), cleanupOldData()
React application entry point:
/ and /:sitenameApp componentCentral state management:
/stream endpoint for real-time updatesuseAnalytics() hook for componentsMain dashboard orchestrator that composes all section components based on the current site selection.
| Component | Purpose |
|---|---|
OverallStatsSection.tsx | Total views, visitors, paths summary |
statCard.tsx | Reusable stat display card |
SitesSection.tsx | List of all tracked sites |
TopPathsSection.tsx | Most visited paths table |
TopReferrersSection.tsx | Top referrer sources |
VisitorOriginsSection.tsx | Country-based visitor breakdown |
visitorGlobe.tsx | Globe visualization for visitor origins |
ChartsSection.tsx | Browser/OS/device charts container |
chartCard.tsx | Reusable chart card component |
Navigation.tsx | Site navigation/breadcrumbs |
ConnectionStatus.tsx | SSE connection status indicator |
| File | Purpose |
|---|---|
formatSiteName.tsx | URL formatting (strips protocol, www) |
personalData.tsx | Personal configuration data |
valTownAnalytics.tsx | Val Town specific analytics helpers |
/trackingScript that sends page views to /trackPageViewcounterTownDb.tsx stores views in SQLite with JSON aggregations/stream SSE endpointAnalyticsContext processes data and components render via React