Connect Your Python Backend to Agent & LLM Analytics
Overview
Use the REST API to connect your website from a Python backend. Please contact us if you need help.
Step 1: Copy Your Access Token
- Navigate to the Projects page
- Select your project
- Click Settings
- Copy your access token
Step 2: Start Tracking Visits
Paste in this function that makes an HTTP request to the REST API with detail about an incoming pageview request.
async def track_visit_in_dark_visitors(request):
try:
async with aiohttp.ClientSession() as session:
await session.post(
"https://api.darkvisitors.com/visits",
headers={
"Authorization": f"Bearer {YOUR_ACCESS_TOKEN}",
"Content-Type": "application/json",
},
json={
"request_path": request.url.path,
"request_method": request.method,
"request_headers": dict(request.headers),
}
)
except Exception:
pass
In the endpoints where you serve your pages, call the function for each incoming pageview request. If you can, add this in middleware to track incoming requests to all pages from a single place.
asyncio.create_task(track_visit_in_dark_visitors(request))
Tips
- 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 3: 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.