Server events
Astro
Send server-side conversions from an Astro API route — forwarded from the request, credited to the real visitor.
Send a server-side conversion from an Astro API route:
import type { APIContext } from 'astro';export async function POST({ request, clientAddress }: APIContext) { const path = new URL(request.url).pathname; const ip = request.headers.get('x-forwarded-for')?.split(',')[0].trim() || clientAddress; const userAgent = request.headers.get('user-agent') ?? ''; await fetch('https://datalook.app/event', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json', }, body: JSON.stringify({ event_name: 'success', name: 'signup', page_path: path, ip: ip, user_agent: userAgent, }), }); return new Response(null, { status: 204 });}Note
Astro passes the IP via clientAddress on the APIContext, but only when the adapter is in SSR (server/hybrid) mode — it is undefined in static output.
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.