Server-side Tracking

Server-side Tracking

The easiest way to get started with Statsy is to use our client-side tracking script. But in some cases you might want to track your users server-side. It's not complicated but requires a bit more dev work and access to the server.

Instead of making the tracking request from the client, you'll make it from the server. This means you'll need to pass the user's IP, User-Agent and the event name to the server. The server will then make the tracking request to Statsy.

When to use server tracking?

  • You want to track users that don't have JavaScript enabled
  • You want to bypass ad-blockers
  • You already use Edge or Server Side Rendering and want to send less JavaScript to your users
  • You want to have more control over the tracking process, for example by blocking certain IP addresses or user agents

Making the request

The API endpoint for all events is

HTTP Headers

Make a POST request to this endpoint with the following headers:

HTTP HeaderValueRequired
X-Forwarded-ForOriginal IP of the user's requestYes
User-AgentUser-Agent of the user's requestYes


The body of the request should be a JSON object with the following properties:

eventNameThe name of the event. By default it's pageview. Other event names will be considered a custom event (goal).No (default to pageview)
domainThe ID of your Site. You can find it in the site settings.Yes
urlFull URL of the user's request, including query params like utmsNo
labelUser-Agent of the user's requestNo

Example request

curl -i -X POST \
  -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36 OPR/71.0.3770.284' \
  -H 'X-Forwarded-For:' \
  -H 'Content-Type: application/json' \
  --data '{"name":"pageview","url":"","domain":"","screen_width":1666}'


  "status": "ok",
  "message": "Beeped!"