Cloudflare Worker
The edge worker is a reverse proxy in front of your origin: it assigns visitors, transforms the HTML stream, and beacons exposures — with zero changes to your application.
One command
npx shiftzero deployThe CLI scaffolds a worker wired to your dashboard, prompts for your publishable API key (stored as a Wrangler secret, never in a file), and deploys it to your Cloudflare account.
Manual setup
wrangler.jsonc
{
"name": "shiftzero-edge",
"main": "src/worker.ts",
"compatibility_date": "2024-12-30",
"vars": {
"DASHBOARD_URL": "https://your-dashboard.example.com",
"ORIGIN_URL": "https://origin.example.com",
"COLLECTOR_URL": "https://collector.example.com",
"CONFIG_TTL_MS": "30000"
},
// Same-account worker-to-worker calls must use a service binding:
"services": [{ "binding": "COLLECTOR", "service": "your-collector-worker" }]
}wrangler secret put SZ_API_KEY # publishable dashboard key (sz_live_…)
wrangler secret put SZ_COLLECTOR_KEY # collector write key
wrangler deployConfiguration
| Setting | Purpose |
|---|---|
DASHBOARD_URL | Control plane. The worker pulls running experiments, audiences and the holdout on a 30s TTL, serving the last-good config through any control-plane blip. |
ORIGIN_URL | Your real site. The worker proxies every request to it and transforms HTML responses. |
COLLECTOR_URL | Where exposure + patch-health beacons go (out-of-band, never blocking the response). |
COOKIE_DOMAIN | Optional. Set .example.com so identity persists across subdomains. |
SZ_API_KEY | Secret. Authenticates every control-plane pull. |
SZ_COLLECTOR_KEY | Secret. Write key stamped on every beacon so the collector only accepts authenticated events. |
Cloudflare blocks a Worker from fetching another Worker’s
workers.dev URL on the same account (error 1042) — and the failure is silent for fire-and-forget beacons. If your collector is a Worker on the same account, the services binding above is required, not optional.Other platforms
The same engine runs on any JS edge: createEdgeApp from @shiftzero/edge/app with bufferingResponseTransform works on Vercel Edge and Netlify Edge Functions — the dashboard’s Setup page shows a ready-to-paste snippet with your values filled in.