← Back
Connect Your Backend to Agent & LLM Analytics
Overview
Use the REST API to connect your website with a backend written in any programming language. Please contact us if you need help.
Step 1: Start Tracking Visits
In the endpoints where you serve your pages, make an HTTP request to the REST API for each incoming pageview request.
URL | |
---|---|
URL | https://api.darkvisitors.com/visits |
HTTP Method | POST |
Headers | |
Authorization |
A bearer token with your project's access token (e.g. Bearer YOUR_ACCESS_TOKEN ). You can get your project's access token by navigating to the Projects page, opening your project, and opening its settings page. |
Content-Type |
This needs to be set to application/json |
Body | |
request_path |
The URL path of the incoming pageview request |
request_method |
The HTTP method of the incoming pageview request (e.g. GET ) |
request_headers |
The HTTP headers of the incoming pageview request, as a key-value object. |
Example
curl -X POST https://api.darkvisitors.com/visits \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"request_path": "${request.path}",
"request_method": "${request.method}",
"request_headers": "${request.headers}"
}'
Tips
- Add this in middleware to track incoming requests to all pages from a single place.
- If you change this code, keep it non-blocking to avoid adding latency to your page response.
- If you change this code, keep handling errors in a way that doesn't make your page response fail too.
- Strip out any sensitive HTTP headers you don't want to send.
Step 2: Test Your Integration
- Navigate to the Projects page
- Select your project
- Click Settings
- Click Send a Test Visit
- Click Realtime
If your website is correctly connected, you should see visits from the Dark Visitor agent in the realtime timeline within a few seconds.