Server events
Go
Send server-side conversions from Go (net/http) — forwarded from the request, credited to the real visitor.
Fire a server-side conversion from a Go net/http handler, crediting the real visitor:
package handlersimport ( "bytes" "encoding/json" "net" "net/http" "strings")func clientIP(r *http.Request) string { if xff := r.Header.Get("X-Forwarded-For"); xff != "" { return strings.TrimSpace(strings.Split(xff, ",")[0]) } host, _, err := net.SplitHostPort(r.RemoteAddr) if err != nil { return r.RemoteAddr } return host}func TrackSuccess(w http.ResponseWriter, r *http.Request) { payload, _ := json.Marshal(map[string]string{ "event_name": "success", "name": "signup", "page_path": r.URL.Path, "ip": clientIP(r), "user_agent": r.Header.Get("User-Agent"), }) req, _ := http.NewRequest(http.MethodPost, "https://datalook.app/event", bytes.NewReader(payload)) req.Header.Set("Authorization", "Bearer YOUR_API_KEY") req.Header.Set("Content-Type", "application/json") if resp, err := http.DefaultClient.Do(req); err == nil { resp.Body.Close() } w.WriteHeader(http.StatusOK)}Note
r.RemoteAddr is host:port, so split off the port with net.SplitHostPort; only the first X-Forwarded-For entry is the real 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.