Backend Integration16. Jan, 2021
This guide assumes you have already added a domain to your dashboard. If that’s not the case, read the website integration article.
Add Pirsch to Your Backend
The backend integration is the recommended way to integrate Pirsch into your website, as it cannot be blocked by the browser. Instead of relying on a script, you will make an API request to monitor traffic.
Create a Client
To get started, you first need to create a client ID and secret.
- open the dashboard and navigate to the Settings page for your website
- under the Client section, click Add Client
- enter a description and click Save
- this will open a new dialog showing a client ID and secret. Copy and store them in a secure place
The example below shows how you can make the API requests required to get an access token and send a page hit. This is sufficient for most websites. For full reference, please visit the API documentation.
First, you need to gain an access token used to authenticate other requests. You need to do this before you make the first page hit request and everytime you receive a HTTP status code 401 (unauthorized) to refresh the access token.
This will return an access token like this.
To monitor traffic, make sure you send a request to Pirsch everytime someone visits a page. How you do this depends on the programming language and framework you’re using. Here is what a request could look like.
As you can see, you need to send the visitors IP, full URL, User-Agent header, and a few more headers. While only the IP, URL, and User-Agent are required, we recommend to send as much of these fields as possible, as they will improve the quality of the analytics data. Don’t worry, we don’t store personal information like the IP address. To learn more, please read the details on privacy.