How to Route Mixpanel Through a First-Party Proxy

By default, the Mixpanel JavaScript SDK loads from cdn.mxpnl.com and sends data to api.mixpanel.com. Many ad blockers and privacy extensions block requests to known analytics domains, so a share of events never arrives. Routing Mixpanel traffic through a subdomain you own, such as track.yoursite.com, makes requests first-party and much less likely to be blocked.

This guide covers the three ways to do it: Mixpanel’s managed First-Party Domains, a self-hosted proxy (nginx, Docker or cloud functions), and framework rewrites such as Next.js. It also covers configuration for every SDK and how to verify the setup.

A note on scope: a proxy reduces blocking, but it doesn’t change consent requirements. If a user hasn’t consented to analytics, you still shouldn’t track them.

Choosing an approach

Mixpanel First-Party DomainsSelf-hosted proxyFramework rewrite (e.g. Next.js)
Infrastructure to runNoneYour server or containerYour web app
TLS certificateManaged by MixpanelYou manageYour app’s existing certificate
PlanEnterprise onlyAny planAny plan
Serves the SDK library itselfNoYesYes, if configured
Best forEnterprise teams wanting zero maintenanceFull control, any planApps already on Next.js or similar

If you already run server-side GTM, sending Mixpanel events through it is another first-party option.

Option 1: Mixpanel First-Party Domains (Enterprise)

Mixpanel’s First-Party Domains feature hosts the endpoint and certificate for you. According to Mixpanel’s docs, it needs an Enterprise plan, an Organization Owner or Admin role, DNS access and a subdomain (not the root domain). Organizations can create up to three.

Step 1: Add the domain

In Organization Settings → First-Party Domains, enter your subdomain (for example track.yourcompany.com) and choose the region that matches your projects’ data residency: US, EU or India. Use a separate domain per region.

Step 2: Create two CNAME records

RecordPoints to
Your tracking subdomainapi-proxy.mixpanel.com (US), api-proxy-eu.mixpanel.com (EU) or api-proxy-in.mixpanel.com (India)
_acme-challenge record shown in the UIThe unique target Mixpanel provides

Two rules from Mixpanel’s docs:

  • Keep the _acme-challenge record permanently, or certificate renewal fails.
  • If your DNS is behind a proxying CDN such as Cloudflare, set the tracking record to DNS only (grey cloud).

Step 3: Wait for Active

The domain moves through Pending DNS validation → Issuing certificate → Active. Don’t send production traffic before it’s Active; requests fail until the certificate exists.

Step 4: Point your SDKs at the domain

Only the host changes; your token and secrets stay the same. See the SDK table below.

What it supports

Mixpanel lists supported paths including event and profile ingestion (/track, /engage, /groups), /import, Session Replay (/record), feature flags (/flags) and settings. It doesn’t serve the SDK library or other CDN assets, so don’t point the JavaScript SDK’s library path at it. The Session Replay recorder module also still loads from Mixpanel’s CDN. If you need those assets on your own domain too, use a self-hosted proxy.

Deleting a first-party domain starts a 5-day grace period during which it keeps working and can be restored.

Option 2: Self-hosted proxy

Mixpanel publishes an example nginx configuration in its tracking-proxy GitHub repository. It forwards API requests to Mixpanel and can also serve the JavaScript library.

Step 1: Deploy the proxy

You can:

  • Copy the nginx location blocks from Mixpanel’s repo into an existing nginx server.
  • Build the repo’s Docker image and run it on a container platform (Cloud Run, ECS, Fly.io, Kubernetes).
  • Use a community fork with one-click deploy options.

Key points in the configuration:

  • Upstream host: api.mixpanel.com for US projects; change it to api-eu.mixpanel.com (or the India host) for other data residency. This is the most common mistake.
  • Library path: a location such as /lib.min.js that serves Mixpanel’s JavaScript library from the CDN.
  • Client IP forwarding: pass the visitor’s real IP via X-Forwarded-For / X-Real-IP, otherwise every user is geolocated to your proxy server’s location.

Step 2: Put it on your subdomain

Point a DNS record such as track.yoursite.com at the proxy and set up HTTPS (for example with your load balancer, Cloudflare in proxied mode, or Let’s Encrypt).

Step 3: Test the proxy directly

Open https://track.yoursite.com/ in a browser. The response should match what https://api.mixpanel.com/ returns. You can also validate nginx syntax with nginx -t. Community repositories include load-testing scripts if you expect high traffic.

Step 4: Point the JavaScript SDK at the proxy

If you use the HTML snippet, define the custom library URL before the snippet so the library itself loads from your domain:

<script>
  const MIXPANEL_CUSTOM_LIB_URL = 'https://track.yoursite.com/lib.min.js';
</script>
<!-- Mixpanel snippet here -->
<script>
  mixpanel.init('YOUR_PROJECT_TOKEN', {
    api_host: 'https://track.yoursite.com'
  });
</script>

If you install via npm, the library is bundled with your app, so you only need api_host.

Option 3: Next.js rewrites

If your app runs on Next.js, you can proxy through the app itself with rewrites, so requests go to a path on your own domain:

// next.config.js
module.exports = {
  async rewrites() {
    return [
      { source: '/mp/lib.min.js', destination: 'https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js' },
      { source: '/mp/:path*', destination: 'https://api-js.mixpanel.com/:path*' }
    ];
  }
};
mixpanel.init(process.env.NEXT_PUBLIC_MIXPANEL_TOKEN, {
  api_host: '/mp'
});

Use a path dedicated to Mixpanel that isn’t used anywhere else in your app. For EU or India projects, use the matching regional API host as the destination. Check how your hosting platform forwards the visitor’s IP; if it doesn’t, geolocation may reflect the server’s region.

SDK configuration reference

Mixpanel’s docs list the option to change on each SDK:

SDKOption
JavaScriptapi_host
Node.jshost
Pythonapi_host on the Consumer
Swift / iOSserverURL
AndroidsetServerURL()
React NativeserverURL
FluttersetServerURL()
PHPhost
UnityAPI Host Address in project settings

For the GTM template, add api_host in the init tag’s custom initialization options (post 22).

Verify the setup

  1. Open your site with developer tools and filter the network tab for your tracking subdomain. Requests should return 200.
  2. Confirm there are no remaining requests to api-js.mixpanel.com or cdn.mxpnl.com (unless intended, such as the replay recorder).
  3. In Mixpanel’s Events view, confirm events arrive in the right project.
  4. Check the city and country on new events. If everything shows one location, the real client IP isn’t being forwarded.
  5. Compare daily event volume before and after. Many teams see an increase once blocked requests start arriving.

Common issues

ProblemCause
Events rejected or missingProxy points to the US host for an EU or India project
All users in one cityClient IP not forwarded
404 on /lib.min.jsLibrary path not configured, or using First-Party Domains (which doesn’t serve the library)
TLS errorsCertificate not issued yet, or Cloudflare proxying the first-party domain record
Some requests still blockedSubdomain name contains words blocklists target, such as “mixpanel” or “analytics”

A neutral subdomain name (for example t., data. or e.) is less likely to appear in blocklists.

Summary

Use Mixpanel First-Party Domains if you’re on Enterprise and want no infrastructure. Use a self-hosted nginx proxy if you need control or aren’t on Enterprise. Use framework rewrites if your app already handles it. In every case, match the regional host, forward the client IP, set api_host on every SDK, and verify in the network tab and Events view.

Sources