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

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

Step 3: Test Your Integration

If your website is correctly connected, you should see visits from the Dark Visitor agent in the realtime timeline within a few seconds.