Set Up Agent Analytics
Overview
Half of your website's traffic probably comes from artificial agents, and they're becoming more intelligent every day. Track the activity of all known agents using the WordPress Plugin or API.
1. Create a New Project
Sign up and create a new project for your website if you haven't already.
- Navigate to the Projects page
- Click the New Project button
- Enter your website details
- Click Create
2. Copy Your Access Token
- Click on your project
- Click Settings
- Copy your access token
3. Start Sending Visit Events
There are 2 ways to send visit events from your website to your project.
Option 1: Using the WordPress Plugin
Use this method for WordPress websites. Adding the plugin is quick and easy.
- Log in to your website's WordPress dashboard
- Click Plugins in the sidebar
- Search for "Dark Visitors" or download the plugin directly
- Click Install Now
- Click Activate
- Click Dark Visitors in the sidebar
- Paste your access token
- Click Save Changes
Option 2: Using the API
Use this method for server-side rendered websites. Simply make a request to the Visits endpoint every time a page view request is made to your website.
The Request
Endpoint | |
---|---|
URL | https://api.darkvisitors.com/visits |
HTTP Method | POST |
Headers | |
Authorization |
A bearer token with your project's access token (e.g. Bearer 48d7dcbd-fc44-4b30-916b-2a5955c8ee42 ). |
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 |
Tips
- Add this call in middleware to cover all of your pages from one place.
- Don't wait for the API response (i.e. make it non-blocking) to avoid adding latency to your page response.
- Ensure that errors are handled in a way that does not make your page response fail too.
Example
This is an example for a javascript backend.
// For each page view, send a visit to Dark Visitors
fetch("https://api.darkvisitors.com/visits", {
method: "POST",
headers: {
"Authorization": "Bearer " + ACCESS_TOKEN,
"Content-Type": "application/json"
},
body: JSON.stringify({
request_path: request.path,
request_method: request.method,
request_headers: request.headers
})
})
... // Render and return the page's HTML response
4. Test Your Integration
- Navigate to the Projects page
- Click on your project
- Click Settings
- Click Visit With Dark Visitor
- Click realtime
If your website is correctly sending visit events to the project, you should see a new visit from the Dark Visitor agent in the project's realtime timeline.