Skip to main content
On Cloudflare, the proxy runs as a Worker or as a Pages Function. A Worker routed on your whole domain works in front of any origin. A Pages Function fits a site hosted on Cloudflare Pages. Read how the proxy works first if you have not set one up before. Replace YOUR_SITE_ID and YOUR_PROXY_PATH with your own values. Site settings › Installation shows both, with this code already filled in. Generate the site secret there too.

Cloudflare Worker

1

Install the package

2

Add the environment variables

In .dev.vars for a local run. For the deployed Worker, set the secret with wrangler secret put HIGHSEAT_SECRET and the path under vars in your Wrangler config.
.env
3

Add the Worker

Route the Worker on yoursite.com/*: fallback: fetch passes every other request on to your origin. A Worker that serves the site’s static assets has no origin: pass fallback: request => env.ASSETS.fetch(request), and leave not_found_handling out of your Wrangler config. With not_found_handling set, the assets answer every path that has no file, the proxy path included, so list the path in run_worker_first.
4

Load the tracker from the path

In the <head> of every page, in place of the tag that loads from Highseat.
Deploy, then check the proxy. The card in Installation settings turns green when an event arrives through it. The Worker sees every request on your domain. It answers the proxy path, and fallback: fetch passes every other request on to your origin unchanged.

Cloudflare Pages

1

Install the package

2

Add the environment variables

In the Pages project’s settings, as variables of the production environment. Encrypt the secret.
.env
3

Add the proxy function

Pages ignores functions/ when the build ships a _worker.js, as the Astro, SvelteKit and Remix adapters do: remove the adapter from a static site.
functions/[path].ts
4

Run the function on the path alone

In the folder your build copies to its output as is, such as public/. Every page stays a static asset.
public/_routes.json
5

Load the tracker from the path

In the <head> of every page, in place of the tag that loads from Highseat.
Deploy, then check the proxy. _routes.json runs the function on the proxy path alone, so every page stays a static asset. Without the file, the function runs on every path with one segment. Pages ignores functions/ when the build ships its own _worker.js, as the Astro, SvelteKit and Remix adapters do. The proxy path then answers with your site’s 404 page. Remove the adapter from a static site, or use the framework’s own endpoint, such as the Astro proxy.