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 Header | Value | Required |
---|---|---|
X-Forwarded-For | Original IP of the user's request | Yes |
User-Agent | User-Agent of the user's request | Yes |
Content-Type | application/json | Yes |
HTTP Body
The body of the request should be a JSON object with the following properties:
Parameter | Value | Required |
---|---|---|
eventName | The name of the event. By default it's pageview . Other event names will be considered a custom event (goal). | No (default to pageview ) |
domain | The ID of your Site. You can find it in the site settings. | Yes |
url | Full URL of the user's request, including query params like utms | No |
label | User-Agent of the user's request | No |
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!"
}