Web analytics

Serve the tracker from your own domain

Ad blockers often block analytics served from another domain. Two routes on your own domain forward the tracker and its events to Logdash.

Ad blockers often block analytics served from another domain. Serve the script and the events from your own domain instead, with two routes that forward to Logdash. The tracker works the same either way.

Prefer not to write the routes yourself? The AI prompt tab of the setup in Logdash gives your coding agent a prompt that adds both routes and the script tag to your codebase, and checks them end to end.

Add two routes

RouteForwards toNotes
GET /_ld/script.jshttps://logdash.io/sdk/web.jsServe it as application/javascript and cache successful responses.
POST /_ld/eventshttps://api.logdash.io/web_eventsPass the status code back. Accept JSON bodies of up to 32 KB, and do not cache the responses.

Forward the right headers

On the events route, forward the browser's Origin and User-Agent headers, and set x-logdash-client-ip to the visitor's IP address.

  • Without an Origin the API answers 403.
  • Without the IP address every visitor shares your server's address, so visitors are undercounted. If that server runs in a datacenter or cloud, every event is dropped.

Never forward cookies, authorization headers or ingest keys on either route, and keep the target URLs fixed so the routes cannot become an open proxy.

Point the script tag at your routes

index.html
<script
  defer
  src="/_ld/script.js"
  data-site="your-site-id"
  data-endpoint="/_ld/events"
></script>

Load a page and open your browser's network panel: the script comes from /_ld/script.js and events go to /_ld/events with status 202.