Operational sidecar for monitoring site visits through Cloudflare Pages/KV and a Windows tray notifier.
This is an ops/support toolchain around masterselects.com.
The system has two halves:
- Cloudflare Pages middleware records visit events into KV
- a Windows tray app polls
/api/visitsand shows local notifications for new visitors
functions/_middleware.ts records eligible page visits in the background and writes new entries under the visit2: KV prefix. It tracks only successful HTML GET responses outside /api/ and skips bot-like user agents.
Unknown HTML paths return a real 404 at the Pages edge instead of loading and tracking the editor SPA fallback. Known entry paths and real static assets continue normally.
Stored metadata can include:
- timestamp
- path
- country / city
- user agent
- referer
- derived
visitorId
Entries expire after one hour. The admin dashboard also reads visit2: metadata for last-hour request, unique-visitor, country, and path summaries.
GET /api/visits returns recent visits from KV.
Requirements:
VISITOR_NOTIFY_SECRETmust be configured- callers pass the secret as a query parameter or
x-visitor-secretheader - optional
sinceandlimitparameters filter the response
The route merges both visit2: and legacy visit: keys, sorts newest-first, and returns a compact { count, visits } JSON payload. limit defaults to 50 and is constrained to 1–200.
The tray client lives in tools/visitor-tray/.
Main files:
VisitorTray.ps1start.cmdstart.vbsstart-debug.cmdInstall-Startup.ps1Install-DesktopShortcut.ps1
Behavior:
- polls
/api/visits - can play an alert sound
- shows a custom, clickable toast notification when
ENABLE_BALLOONis enabled - opens the visited site/path from the toast when
OPEN_SITE_ON_BALLOON_CLICKis enabled - provides a grouped, scrollable live log from the tray icon; stable
visitorIdvalues are the primary grouping key
The tray app reads configuration from:
- repo
.dev.vars - repo
.dev.vars.local tools/visitor-tray/.env.local- process environment variables
Important values:
VISITOR_NOTIFY_SECRETSITE_URL- optional
POLL_INTERVAL_MS,MAX_VISITS_PER_POLL, andALERT_SECONDS - optional
ENABLE_SOUND,ENABLE_BALLOON, andOPEN_SITE_ON_BALLOON_CLICK - optional
HISTORY_LIMIT - optional
ALERT_SOUND_PATH
- the tray app is Windows-only
- this workflow is operational tooling
- without
VISITOR_NOTIFY_SECRET,/api/visitsrejects requests