Setup Serverside API

This page revovles around how to use HTTP REST API requests in order to track page views and events. You might wanna check first if we have a library for the backend language that you are using like C# or Node.js. You can look at the following link to find out which languages we currently are offering libraries for.

Serverside Libraries

Read more

Regardless of which endpoint you are trying to use in the REST API, you will always have to include the API Key in the Authorization Header. Here is an example how this could look like:

Authorization header
Authorization: SjqsDDmC4USJCnRHpSmOggMgprJ15g7UG5KPScfgpAqA

To find the API Key for your website, you have to navigate Websites > Edit website > Left side. On right side of the API Key, you can click to copy the API Key, including the header name. There is also the functionality to regenerate your API key.

Never expose your API Key to any of your clientside code or untrusted backends. It is like a password, and you should regenerate the key if the key got publicly exposed.

The most common approach for using the Backend API is with the following flow:

 

  • Custom JS Snippet sending specific information to your backend Endpoint.
  • Process the request adding more information 
  • Sending the information to sitesights.io via the Backend API on your backend

 

This js object shows you what information you need from your frontend before sending it to your backend endpoint:

This approach makes it impossible to be blocked by any standard analytics blocker
Needed information and how to get it
const getPayload = () => {
    return {
        "ScreenWidth": window.screen.width,
        "ScreenHeight": window.screen.height,
        "Language": window.navigator.language,
        "Referrer": document.referrer,
        "Absolute": document.location.href,
    };
}

Depending on whether you just want to send a page view or event you also have to include the event name and parameters in the above data.

 

After you received the data from the frontend you have to fill in the rest of needed data on your backend, look up the corresponding endpoint to see more details:

Serverside Page View

Read more

Serverside Event

Read more

Here is an example of how to call our API from your Backend after you received the payload from your Frontend as seen above.

 

 

POST
https://app.sitesights.io/api/page-view 

 

Headers:

Authorization: Sqjr2..(Your API Key as seen above)

Body (JSON string):

Example Body
{
  "Metrics": {
    "Browser": {
      "IP": "91.48.119.123 (From your server framework)",
      "UserAgent": "Mozilla/5.0... (From your server framework / headers)"
    },
    "Identify": {
      "ClientId": null
    },
    "Language": {
      "Code": "en (From your frontend window.navigator.language)"
    },
    "Location": {
      "CountryCode": "AF (This entire section requires you to have a geolocation service to fetch for the IP, or if you are using a reverse proxy service like Cloudflare, you can enable special headers providing you with these information on the fly.",
      "ContinentCode": "AF",
      "City": "test",
      "Region": null,
      "RegionCode": null,
      "PostalCode": "33100",
      "Timezone": null
    },
    "Page": {
      "Absolute": "https://app.sitesights.io/analytics (From your frontend document.location.href)"
    },
    "Referrer": {
      "Absolute": "(From your frontend document.referrer)"
    },
    "Screen (From your frontend window.screen.width & window.screen.height)": {
      "Width": 200,
      "Height": 200
    }
  }
}

Currently there are these features to the Serverside API:

 

  • Send page views
  • Send events

 

You can see details about all REST API Endpoints here:

Serverside Endpoints

Read more