For WordPress, setting up server analytics is the same process as setting up client analytics. If you already did that, you can move to the next step.
The Node.js package and full docs are available on NPM.
Install the Package
Download and include the package using the command line.
npm install @darkvisitors/sdk
Copy Your Access Token
- Navigate to the Projects page
- Select your project
- Click Settings
- Copy your access token
Initialize the Client
Create a new instance of DarkVisitors
with your access token.
import { DarkVisitors } from "@darkvisitors/sdk"
const darkVisitors = new DarkVisitors("your-access-token")
Start Tracking Visits
In your endpoints, simply call trackVisit
for each incoming pageview request. If the visit was from an artificial agent, it will show up in agent analytics.
darkVisitors.trackVisit(request)
If you can, do this in middleware to track all requests from a single place. You can see an example on the NPM page.
Make an HTTP request the REST API from any codebase or programming language.
Copy Your Access Token
- Navigate to the Projects page
- Select your project
- Click Settings
- Copy your access token
Start Tracking Visits
In your endpoints, call the API with detail about each incoming pageview request to your website. If the visit was from an artificial agent, it will show up in agent analytics.
URL |
URL |
https://api.darkvisitors.com/visits |
HTTP Method |
POST |
Headers |
Authorization |
A bearer token with your project's access token (e.g. Bearer 48d7-fc44-4b30-916b-2a59 ). |
Content-Type |
This needs to be set to application/json |
Body |
request_path |
The URL path of your visitor's request |
request_method |
The HTTP method of your visitor's request (e.g. GET , POST , etc.) |
request_headers |
The HTTP headers of your visitor's request, as a key-value object. Be sure to strip out anything sensitive. |
Example
curl -X POST https://api.darkvisitors.com/visits \
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"request_path": "'"${request.path}"'",
"request_method": "'"${request.method}"'",
"request_headers": "'"${request.headers}"'"
}'
Tips
- Call this call in middleware to track all requests from a single place.
- Make this call non-blocking to avoid adding latency to your page response.
- Handle errors in a way that doesn't make your page response fail too.
The Shopify integration is in the works. If you want early access, please contact us.
The Python package is in the works. If you want early access, please contact us. Feel free to use the REST API in the meantime.
The PHP package is in the works. If you want early access, please contact us. Feel free to use the REST API in the meantime.