IP Check API
File: app/api/analytics/ip-check/route.ts
GET /api/analytics/ip-check
Detects whether the current request comes from an internal/admin IP address.
Response
{
"internal": true
}or
{
"internal": false
}How it works
- Reads the client IP from
x-forwarded-forheader (standard for Vercel/proxied deployments) - Checks against a hardcoded IP allowlist
- Returns
{ internal: true }if the IP matches
Client usage
Called on page load from instrumentation-client.ts:
fetch("/api/analytics/ip-check")
.then(r => r.json())
.then(data => {
if (data.internal) {
posthog.register({ is_internal: true });
}
});This tags all subsequent PostHog events with is_internal: true, allowing the analytics dashboard to filter out internal traffic.
Caching
Cache-Control: max-age=3600 (1 hour).