Counter Town

A lightweight, real-time web analytics tracker built on Val Town. Monitor traffic across multiple sites from a single dashboard—no external dependencies, no monthly bills.

Features

  • Real-time tracking – See pageviews, referrers, and top pages as they happen
  • Multi-site dashboard – Track multiple websites from one place
  • Zero infrastructure – Fully hosted on Val Town with persistent SQLite storage
  • Easy setup – Add a single script tag and you're done

Inspired by Stats and GoatCounter.

Quick Start

1. Fork the val

Click the fork button to create your own copy.

2. Initialize the database

The tables initialize automatically on first run. If you need to manually set them up, call initAnalytics() from backend/database/migrations.ts.

3. Configure your sites

Edit the counterTownConfig object in backend/lib/CounterTown.ts with your site information and add your site URLs to allowedOrigins.

4. Add the tracking script

Place this snippet just before the closing </body> tag on each site you want to track:

<script> (function() { var script = document.createElement('script'); script.async = true; script.src = 'https://<your-username>-<project-name>.val.run/trackingScript'; var firstScript = document.getElementsByTagName('script')[0]; firstScript.parentNode.insertBefore(script, firstScript); })(); </script>

Replace <your-username> and <project-name> with your Val Town username and project name (e.g., https://nbbaier-countertown.val.run/trackingScript).

5. View your dashboard

Navigate to your val's HTTP endpoint to see live analytics.