Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/samgutentag/sbburgerweek/llms.txt

Use this file to discover all available pages before exploring further.

The tracking system records per-restaurant engagement events — popup views, directions clicks, share button taps, and upvotes — and surfaces them on the /stats leaderboard dashboard. It uses a Cloudflare Worker that writes events to Analytics Engine. The free tier covers 100,000 writes per day with 90-day data retention, which is more than enough for a week-long food event.

How tracking works

track.js is a lightweight, self-contained script loaded on every page. On load it reads THEME.trackUrl from config.js. If the URL is set, it defines window.track(action, label) as a function that serialises the event as JSON and fires it to the Worker via navigator.sendBeacon. If trackUrl is null, the entire setup is skipped — window.track is never defined and all call sites in app.js are silent no-ops.
// track.js — simplified
window.track = function (action, label) {
  if (navigator.sendBeacon) {
    var blob = new Blob(
      [JSON.stringify({ action: action, label: label })],
      { type: "application/json" }
    );
    navigator.sendBeacon(url, blob);
  }
};
The Worker stores each event as a data point in a named Analytics Engine dataset. The /stats page and the snapshot workflow query the Worker’s GET endpoints to retrieve aggregated counts.

Setup

1

Install Wrangler and log in

npm install -g wrangler
wrangler login
wrangler login opens a browser window to authenticate with your Cloudflare account.
2

Create an Analytics Engine dataset

In the Cloudflare dashboard, go to Workers & PagesAnalytics EngineCreate a dataset. Name it something descriptive for your event (e.g. sbburritoweek). Note the dataset name — you’ll need it for wrangler.toml.
3

Get your Cloudflare Account ID

On the Cloudflare dashboard home page, your Account ID is displayed in the right sidebar. It’s also visible in the URL: dash.cloudflare.com/<ACCOUNT_ID>/.... Copy it.
4

Configure wrangler.toml

Edit workers/track/wrangler.toml with your account ID and dataset name:
name = "sbburritoweek-track"
main = "index.js"
compatibility_date = "2024-01-01"

[vars]
ACCOUNT_ID = "YOUR_CLOUDFLARE_ACCOUNT_ID"

[[analytics_engine_datasets]]
binding = "TRACKER"
dataset = "sbburritoweek"
Replace YOUR_CLOUDFLARE_ACCOUNT_ID with the ID you copied in the previous step, and update the dataset name to match what you created. You can remove the RUM_SITE_TAG var if you don’t plan to use Cloudflare RUM (Browser Insights).
5

Create an API Token

In the Cloudflare dashboard, go to My Profile (top-right avatar) → API TokensCreate Token. Select Custom token and grant these permissions:
  • AccountAnalytics EngineRead
  • AccountWorkers ScriptsEdit
Scope the token to your account only, then copy the generated token value.
6

Add Worker secrets

cd workers/track
wrangler secret put CF_API_TOKEN
# Paste your Cloudflare API token when prompted

wrangler secret put ADMIN_TOKEN
# Choose a strong password for the /admin search query viewer
Secrets are encrypted at rest by Cloudflare and are never visible in wrangler.toml or your repo.
7

Update the event start date

Open workers/track/index.js and find all SQL queries containing a line like:
WHERE timestamp >= toDateTime('2026-02-19 09:00:00')
Change the date to your event’s start date in UTC. If you’ve already set eventStartDate in config.js, running python3 apply-theme.py updates this automatically.
8

Enable event writes in index.js

In workers/track/index.js, locate the POST handler. If there is an early return statement near the top of the handler (added when winding down a previous event to disable writes), remove it and uncomment the writeDataPoint call below it so that incoming events are actually stored.
9

Deploy the Worker

cd workers/track
wrangler deploy
Wrangler prints the Worker URL on success:
https://sbburritoweek-track.YOUR_SUBDOMAIN.workers.dev
Copy this URL.
10

Set trackUrl in config.js

trackUrl: "https://sbburritoweek-track.YOUR_SUBDOMAIN.workers.dev",
11

Apply, commit, and push

python3 apply-theme.py
git add config.js index.html
git commit -m "Enable click tracking"
git push
12

Verify tracking is working

Open your live site and click on a restaurant popup. In a second terminal, run:
cd workers/track
wrangler tail
You should see POST requests logged in real time. Visit /stats on your site — the leaderboard should begin populating.

What gets tracked

Every meaningful interaction fires a window.track(action, label) call. Here’s the full event table:
ActionWhen firedLabel
viewRestaurant popup opened (map or sidebar click)Restaurant name
sidebar-viewSidebar item scrolled into viewRestaurant name
directions-appleApple Maps link clickedRestaurant name
directions-googleGoogle Maps link clickedRestaurant name
websiteWebsite link clickedRestaurant name
phonePhone link tappedRestaurant name
instagramInstagram link clickedRestaurant name
shareShare button clickedRestaurant name
upvote / un-upvoteLike button toggledRestaurant name
deeplinkArrived via URL hash (#slug)Restaurant name
filter-areaArea filter button clickedArea name
filter-tagDietary tag filter clickedTag name
filter-hoursHours filter clickedFilter type
tip-s / tip-m / tip-lTip jar tier clicked"tip-jar"
tip-shareTip jar share button clicked"tip-jar"
stats-viewStats page loaded"stats"

Enabling and disabling writes

The Worker’s POST handler has an intentional on/off mechanism: an early return statement that short-circuits writes. Use this pattern when winding down an event so the Worker stays deployed (to serve the stats page) but stops accepting new events. Before your event — remove the early return and ensure writeDataPoint is active. After your event — add back the early return and comment out writeDataPoint, then redeploy:
cd workers/track && wrangler deploy
See the Snapshots page for the full wind-down checklist, including capturing hourly data before disabling the Worker.
The ADMIN_TOKEN protects the /admin endpoint, which exposes the top search queries entered by visitors during the event. Choose a strong, unique password — this endpoint is unauthenticated except for the token check.

Build docs developers (and LLMs) love