Server side tracking [deprecated] edit

On this page you will find how to collect page views server side.

We recommend using page view events to collect page views server side.

When you send data from your server to Simple Analytics you need to provide a few fields:

Field Type Example Required Explanation
url string https://example.com/ yes The current URL of the page
ua string Mozilla/5.0 … sometimes We use this if there is no User Agent present in the headers
width number 1440 no The viewport width of the device (not possible via server)
unique boolean true no This tells us if this visit is unique. Don’t send this field if you don’t detect unique page views
timezone string Europe/Amsterdam no The time zone of the current user so we can detect the country
referrer string https://duckduckgo.com/ no The referrer of the current page (if any)
urlReferrer string blog no The value of ?ref=... in the URL (more info)

If we find a User Agent in the headers, we will use that.

Please strip all sensitive data from your URLs. We do this at our end as well, but it’s better to have this done on your server.

Our API is located at https://queue.simpleanalyticscdn.com/post.

The request should be a POST with JSON like this:

{
  "url": "https://example.com/",
  "ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:70.0) Gecko/20100101 Firefox/70.0",
  "width": 1440,
  "unique": true,
  "timezone": "Europe/Amsterdam"
}
Send request in Node.js
const https = require("https");

const data = JSON.stringify({
  url: "https://example.com/",
  ua: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:70.0) Gecko/20100101 Firefox/70.0",
  width: 1440,
  unique: true,
  timezone: "Europe/Amsterdam",
});

const options = {
  hostname: "queue.simpleanalyticscdn.com",
  path: "/post",
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Content-Length": data.length,
  },
};

const req = https
  .request(options, (res) => {
    let data = "";

    console.log("Status Code:", res.statusCode);

    res.on("data", (chunk) => {
      data += chunk;
    });

    res.on("end", () => {
      console.log("Body: ", JSON.parse(data));
    });
  })
  .on("error", (err) => {
    console.log("Error: ", err.message);
  });

req.write(data);
req.end();

The response for this request will look like this:

{
  "success": true,
  "duration_ms": 1,
  "message": "Thank you",
  "location": "Amsterdam, The Netherlands"
}

Let us know if we can help you with anything!