PostHog Reverse Proxy with Next.js Rewrites
How to route PostHog analytics through your own domain to bypass ad blockers and improve data accuracy.
By Ege Uysal
Ad blockers kill analytics. If you're relying on client-side tracking, you're probably missing 30-40% of your events. The fix is simple: proxy PostHog through your own domain.
The Problem
Ad blockers maintain lists of known tracking domains. us.i.posthog.com is on every list. When a user has an ad blocker installed, all requests to PostHog are silently dropped.
The Solution
Next.js rewrites let you proxy requests at the edge. Add two rewrite rules in next.config.ts:
/ingest/static/*- PostHog static assets/ingest/*- PostHog ingest API
Then point your PostHog client at /ingest instead of the PostHog domain. Requests now go to your domain first, then get forwarded to PostHog. Ad blockers see your domain and let them through.
Don't Forget
Set skipTrailingSlashRedirect: true in your Next.js config. PostHog's API uses trailing slashes, and Next.js will redirect them away by default.
Also add /ingest and /ingest/* to your robots.txt disallow list so search engines don't try to crawl your proxy endpoints.