Server events
Next.js
Send server-side conversions from a Next.js Server Action — forwarded from the request, credited to the real visitor.
Record a server-side conversion from a Next.js 16 Server Action:
'use server'import { headers } from 'next/headers'export async function recordConversion() { // headers() is async in Next 16 — await it. const h = await headers() // First X-Forwarded-For entry is the real browser visitor. const ip = (h.get('x-forwarded-for') ?? '').split(',')[0].trim() // Server Actions have no request path; derive it from the originating page. const referer = h.get('referer') const page_path = referer ? new URL(referer).pathname : '/' 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, ip, user_agent: h.get('user-agent') ?? '' }) })}Note
A Server Action runs as its own POST, so there is no request path to read — take the originating page from the referer header, and forward the visitor's X-Forwarded-For and User-Agent so the conversion is credited to the real browser visitor.
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.