Antlytics logoAntlytics
← Blog
5

First-Party Analytics Proxy: Why and How to Set It Up

Ad blockers hide your analytics. A first-party proxy routes data through your domain so you see all visitors.

First-Party Analytics Proxy: Why and How to Set It Up

Ad blockers can block analytics requests to known third-party domains. A first-party proxy routes analytics through your own domain so the requests are indistinguishable from your own API traffic. Here is why it matters and how to set it up.

What a first-party proxy does

When you install a tracking script, your visitors' browsers send pageview data to an analytics server — in Antlytics's case, to https://www.antlytics.com/api/ingest/pageview.

Ad blockers maintain blocklists of known analytics domains. When a browser extension recognises www.antlytics.com as an analytics endpoint, it blocks the request. The pageview is not recorded.

A first-party proxy intercepts that request before it leaves your domain:

  1. Your analytics script sends the request to your own domain (for example, https://yoursite.com/api/antlytics/pageview).
  2. A route handler on your server receives the request.
  3. The route handler forwards it to the Antlytics ingest endpoint.

The browser sees only a request to your own domain. Ad blockers cannot block it.

Why ad blockers block analytics

Ad blockers work by matching network requests against blocklists. These lists contain domains and URL patterns associated with tracking scripts. Analytics hostnames — including Antlytics's — appear on some blocklists.

The mechanism is blunt: if the domain matches, the request is blocked, regardless of whether the tool uses cookies or personal data. A privacy-first, cookieless analytics tool can still be blocked by an ad blocker simply because it is a known analytics domain.

The first-party proxy sidesteps this by making all requests appear to come from your own domain.

How the proxy works

Visitor's browser
       │
       │ POST /api/antlytics/pageview
       ▼
Your domain (yoursite.com)
       │
       │ Forward to upstream
       ▼
Antlytics ingest (www.antlytics.com)

The proxy is a thin route handler. It receives the request, validates it (CORS headers), and forwards it to the upstream Antlytics endpoint. No data is stored on your server — it is a pass-through.

Setting it up in Next.js

The @antlytics/analytics package includes the proxy handler. Creating the route is one line:

// app/api/antlytics/pageview/route.ts
export { GET, OPTIONS, POST } from "@antlytics/analytics/proxy"

Then configure the SDK to use your domain as the apiHost:

// app/layout.tsx
import { Analytics } from "@antlytics/analytics/next"

export default function RootLayout({ children }) {
  return (
    <html>
      <body>
        {children}
        <Analytics
          trackingId="your-tracking-id-uuid"
          apiHost="https://your-domain.com"
        />
      </body>
    </html>
  )
}

When apiHost is set to your domain, the SDK sends pageview requests to /api/antlytics/pageview on your domain rather than directly to Antlytics. The route handler forwards them upstream.

Setting it up in other frameworks

For frameworks without a built-in route handler, you need a server-side endpoint that proxies the request.

Generic approach (any Node.js server):

// Your express/Fastify/Hono route handler
async function analyticsProxy(req, res) {
  const upstream = 'https://www.antlytics.com/api/ingest/pageview'
  const response = await fetch(upstream, {
    method: req.method,
    headers: { 'Content-Type': 'application/json' },
    body: req.method !== 'GET' ? JSON.stringify(req.body) : undefined,
  })
  res.status(response.status).send(await response.text())
}

Then update your tracking script to point u to your proxy endpoint URL.

For detailed documentation, see the first-party proxy docs.

Verifying it works

  1. Deploy the proxy route handler to your site.
  2. Open your site in a browser with an ad-blocker extension enabled.
  3. Open the browser network tab.
  4. Look for a POST request to /api/antlytics/pageview on your own domain.
  5. Confirm the request succeeds (status 200 or 204).
  6. Check your Antlytics dashboard — the visit should appear in real time.

If you previously saw gaps in your analytics during development (when you test with extensions), the proxy should close that gap.

Performance impact

The first-party proxy adds one network hop: your server forwards the request to Antlytics rather than the visitor's browser sending it directly. This does not affect page load time because the analytics request fires after the page loads (strategy="afterInteractive").

The only performance consideration is your server's latency to Antlytics's ingest endpoint, which is minimal.

FAQ

Do I need the proxy? Not required. Start without it. Add it if you notice a meaningful gap between expected visitor counts and recorded data, which may indicate ad-blocker interference.

Does the proxy store any data on my server? No. The route handler is a pass-through. No analytics data is stored on your server.

Will this affect my Vercel/hosting costs? A pageview proxy request is a tiny JSON payload. The cost is negligible on any serverless platform.

Does the proxy work with Edge Runtime? Use the default Node.js runtime for the proxy route. Do not add export const runtime = "edge".

What if I'm not using Next.js? Any server-side language or framework can implement the proxy pattern. The core is: receive the pageview JSON, forward to https://www.antlytics.com/api/ingest/pageview.

Is the proxy required for GDPR compliance? No. Antlytics is cookieless regardless of whether you use the proxy. The proxy is about data completeness, not compliance.


Related: Next.js analytics setup guide · Troubleshooting · First-party proxy docs