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.
1
Install the package
2
Add the environment variables
In .env. The file name carries the path, so the endpoint needs only the secret.
.env
3
Add the proxy endpoint
Needs a server adapter. A static site uses its host’s function instead, such as Cloudflare Pages. On the Cloudflare adapter, pass secret: locals.runtime.env.HIGHSEAT_SECRET. clientAddress is the address that connected, so behind a proxied Cloudflare record, use “cloudflare” instead.
src/pages/YOUR_PROXY_PATH.ts
4
Load the tracker from the path
In your layout’s
<head>, in place of the tag that loads from Highseat.src/layouts/Layout.astro
A server adapter is required
The endpoint setsprerender = false and answers on demand, so the site needs a server adapter, such as @astrojs/node or @astrojs/vercel. A fully static site has no server to run it on. Use your host’s functions instead, such as Cloudflare Pages.
Behind Cloudflare
clientAddress is the address that connected to your server. Behind a proxied Cloudflare record, that is a Cloudflare address, so pass clientIp: "cloudflare" instead.
On the Cloudflare adapter, the secret is not in process.env. Pass it from the runtime: secret: locals.runtime.env.HIGHSEAT_SECRET.
The path is a file name
The file name carries the path, so the endpoint needs noHIGHSEAT_PATH. When you rotate the path, rename the file and update the script tag.