Server events
FastAPI
Send server-side conversions from FastAPI — forwarded from the request, credited to the real visitor.
Fire a server-side conversion from a FastAPI route handler:
import httpxfrom fastapi import APIRouter, Requestrouter = APIRouter()@router.post("/checkout/success")async def checkout_success(request: Request): # Prefer the first X-Forwarded-For entry (the real visitor), else the client host. forwarded = request.headers.get("x-forwarded-for") visitor_ip = forwarded.split(",")[0].strip() if forwarded else request.client.host async with httpx.AsyncClient() as client: await client.post( "https://datalook.app/event", headers={"Authorization": "Bearer YOUR_API_KEY"}, json={ "event_name": "success", "name": "signup", "page_path": request.url.path, "ip": visitor_ip, "user_agent": request.headers.get("user-agent", ""), }, ) return {"ok": True}Note
In Starlette/FastAPI the path is request.url.path (not request.path), and request.client.host can be None behind a proxy, so rely on X-Forwarded-For when running behind one.
How it’s credited
This reads the visitor’s IP and User-Agent from the request and forwards them, so the conversion lands on the real visitor — device, country, and source included. No
identify(), no ids, no cookie. Get an API key in the dashboard under Track it from your server; see the overview for the concepts and the webhook path.