Docs
Advanced
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 https://statsy.com/api/beep.

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
Content-Typeapplication/jsonYes

HTTP Body

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

ParameterValueRequired
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 https://statsy.com/api/beep \
  -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: 127.0.0.1' \
  -H 'Content-Type: application/json' \
  --data '{"name":"pageview","url":"http://dummy.site","domain":"dummy.site","screen_width":1666}'

Response

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