Cloudflare Worker
If the site is proxied by Cloudflare (orange cloud), a Worker on the site's route sees every request, whatever hosts the origin. The Worker forwards one line per request in the background, using waitUntil, so it never delays the response.
When to choose it
- Your app is on Lovable, Bolt, v0, Replit or any host that doesn't give you its logs, and it has its own domain.
- The domain's DNS is on Cloudflare with the proxy on. Cloudflare's free plan is enough.
Because the Worker sits in front of your site, it counts every request, including bots and AI crawlers that never run JavaScript, and requests your host answers from its cache.
Code
Works for any site behind Cloudflare (Pages, Workers or a proxied origin). Add a Worker on the route example.com/*:
// Growbeat — forwards one log line per request, never blocks the response.
const ENDPOINT = "https://getgrowbeat.com/api/v1/ingest";
const TOKEN = "tl_in_YOUR_TOKEN"; // write-only: it can't read anything
export default {
async fetch(request, env, ctx) {
const t0 = Date.now();
const response = await fetch(request);
const url = new URL(request.url);
ctx.waitUntil(fetch(ENDPOINT, {
method: "POST",
headers: { "Authorization": `Bearer ${TOKEN}`, "Content-Type": "application/x-ndjson" },
body: JSON.stringify({
ts: new Date().toISOString(),
ip: request.headers.get("cf-connecting-ip") || "",
method: request.method, path: url.pathname + url.search, status: response.status,
ua: request.headers.get("user-agent") || "", ref: request.headers.get("referer") || "",
host: url.host, rt: (Date.now() - t0) / 1000, src: "cloudflare",
}) + "\n",
}).catch(() => {}));
return response;
},
};
Deploy it with wrangler deploy and add a route example.com/*. On the Workers Free plan the limit is 100k requests/day. Above that, use the agent at the origin.
Check it works
Open any page of your site. Within a minute the install screen in Growbeat switches to «receiving». If not, check the route covers your domain (both example.com/* and www.example.com/* if you use both) and that the token is set.