Skip to content

About

Festival Visitor Tracker.

Resources

Stars

0 stars

Watchers

2 watching

Forks

Repository files navigation

Visit Tracker

Bun workspaces:

  • packages/db: D1 schema (drizzle) and SQL migrations, shared by worker and view
  • worker: Cloudflare Worker that records clicks on the festival website
  • view: SvelteKit dashboard on Cloudflare Pages

Install dependencies at the repository root:

bun install

Database

Edit packages/db/src/schema.ts, then generate a migration:

bun db:generate

Apply migrations (from worker/):

cd worker
bun db:migrate:local   # local D1 for development
bun db:migrate:remote  # production D1

View

deploy:

cd view; bun run deploy

Worker

Besides recording clicks, a cron trigger (every 10 minutes) imports Cloudflare Analytics into D1 (traffic_pageviews from Web Analytics, traffic_requests from HTTP requests). Progress is kept per source in ingest_state; see worker/src/ingest/.

The import needs an API token with the "Account Analytics Read" permission (without it the cron only logs and skips). For wrangler dev, copy worker/.dev.vars.example to worker/.dev.vars.

First deploy (from worker/):

bun db:migrate:remote                          # 1. create the tables
bunx wrangler secret put CF_ANALYTICS_TOKEN    # 2. set the token
bun run deploy                                 # 3. deploy (the cron imports the last hour)
CF_ANALYTICS_TOKEN=... bun backfill --from 2026-11-01 --to 2026-11-21 --remote --apply  # 4. older data

bun backfill queries the API in 6-hour chunks (data older than ~30 days is unavailable) and writes a SQL file; without --apply it only prints the wrangler d1 execute command. Use --source pageviews|requests to limit it and --local to target the local D1. It replaces the rows of the requested range and never touches ingest_state, so it is safe to run while the cron is active.

Subsequent deploys:

cd worker; bun run deploy

About

Festival Visitor Tracker.

Resources

Stars

0 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages