Visitor Notifier
Operational sidecar for monitoring site visits through Cloudflare Pages/KV and a Windows tray notifier.
Overview
Section titled “Overview”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
Server Side
Section titled “Server Side”Visit Capture
Section titled “Visit Capture”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
- coarse browser, operating-system, and device classes
- referrer domain (never its path or query)
- daily rotating pseudonymous
visitorId
The live log never stores the plain IP address, city, complete user agent, or complete referrer URL. Query strings are
discarded, and dynamic credit-claim paths are reduced to their non-secret route. When
VISITOR_NOTIFY_SECRET is configured, the middleware derives visitorId with a secret-key HMAC over the UTC day and
the request IP. The identifier therefore supports grouping within one day but cannot link visits across days.
Entries expire after 180 days. The admin dashboard still filters visit2: metadata to the most recent hour for its
live request, daily-scoped visitor, country, and path summaries.
Visit Feed
Section titled “Visit Feed”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.
Windows Tray App
Section titled “Windows Tray App”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; daily-scoped
visitorIdvalues are the primary grouping key
Configuration
Section titled “Configuration”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
Limitations
Section titled “Limitations”- the tray app is Windows-only
- this workflow is operational tooling
- without
VISITOR_NOTIFY_SECRET,/api/visitsrejects requests
Related Features
Section titled “Related Features”- Hosted AI Setup
- Security