Skip to content

Serve the tracker from your own domain

Proxy the tracker, events and session replay through your site's domain with nginx, Caddy, a Cloudflare Worker or Next.js and Remix.

Serve Supermetry from a path on your own site, for example https://supermetry.com/sm/. Requests stay first-party, so content blockers and strict browser rules leave them alone.

Pick a prefix (here /sm/) and forward these paths to Supermetry (https://app.supermetry.com on Supermetry Cloud, or your own instance):

Your path Supermetry path Used for
/sm/js/ /js/ the tracker script
/sm/api/public/ /api/public/ events
/sm/replay.js /replay.js session replay recorder
/sm/api/replay/ /api/replay/ session replay uploads
/sm/px/ /px/ tracking pixels (optional)

Forward only these paths, not the whole app, and drop cookies: tracking needs none.

Then load your site’s script through the prefix:

<script defer src="https://supermetry.com/sm/js/YOUR_SITE_ID.js"></script>

The script sends events and replay data under the same prefix (/sm/api/public/v1/events, /sm/replay.js). Trackers from before this change need data-api="/sm/api/public/v1/events" on the script tag, and send session replay to /replay.js and /api/replay/ at the site’s root; forward those two root paths too if you use replay with an older tracker.

Your proxy now talks to Supermetry for every visitor. Without more information Supermetry sees your server’s address for everyone: wrong locations, unique visitors merged together and one shared rate limit.

  • Supermetry Cloud: create a proxy key for the site: open the site, then Settings → Installation → First-party proxy. Your proxy sends it with the visitor’s address on every request:

    Header Value
    X-Supermetry-Proxy-Key your key (smpk_…)
    X-Supermetry-Client-IP the visitor’s IP address

    The key works only for that site. It is a server-side secret: keep it in your proxy’s configuration or secret store, never in HTML, JavaScript or a public repository. Always set X-Supermetry-Client-IP in the proxy, so a browser can’t send its own.

  • Self-hosted: add your proxy’s address to SUPERMETRY_TRUSTED_PROXIES and send the visitor’s address in X-Forwarded-For. No key is needed.

# Supermetry Cloud key; keep it in a file only nginx can read, for example
# /etc/nginx/secrets/supermetry-key.conf containing: set $sm_key "smpk_…";
include /etc/nginx/secrets/supermetry-key.conf;
location ~ ^/sm/(js/|api/public/|replay\.js$|api/replay/|px/) {
rewrite ^/sm/(.*)$ /$1 break;
proxy_pass https://app.supermetry.com;
proxy_ssl_server_name on;
proxy_set_header Host app.supermetry.com;
proxy_set_header X-Supermetry-Proxy-Key $sm_key; # Cloud only
proxy_set_header X-Supermetry-Client-IP $remote_addr; # overwrites any browser value
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Cookie "";
client_max_body_size 2m; # replay uploads
}

Behind a CDN such as Cloudflare, $remote_addr is the CDN’s address. Configure nginx’s real IP module so it becomes the visitor’s: set_real_ip_from the CDN’s address ranges, plus real_ip_header CF-Connecting-IP (or the CDN’s equivalent).

supermetry.com {
@supermetry path /sm/js/* /sm/api/public/* /sm/replay.js /sm/api/replay/* /sm/px/*
handle @supermetry {
uri strip_prefix /sm
reverse_proxy https://app.supermetry.com {
header_up Host app.supermetry.com
header_up X-Supermetry-Proxy-Key {env.SUPERMETRY_PROXY_KEY}
header_up X-Supermetry-Client-IP {client_ip}
header_up -Cookie
}
}
}

Set SUPERMETRY_PROXY_KEY in Caddy’s environment, readable only by Caddy. Behind a CDN, configure Caddy’s trusted_proxies so {client_ip} is the visitor’s address.

// Route: supermetry.com/sm/* Secret: wrangler secret put SUPERMETRY_PROXY_KEY
const allowed = /^\/(js\/|api\/public\/|replay\.js$|api\/replay\/|px\/)/
export default {
async fetch(request, env) {
const url = new URL(request.url)
const path = url.pathname.slice('/sm'.length)
if (!allowed.test(path)) return new Response('Not found', { status: 404 })
const headers = new Headers(request.headers)
headers.delete('Cookie')
headers.delete('X-Supermetry-Client-IP')
const visitor = request.headers.get('CF-Connecting-IP')
if (visitor) {
headers.set('X-Supermetry-Proxy-Key', env.SUPERMETRY_PROXY_KEY)
headers.set('X-Supermetry-Client-IP', visitor)
}
return fetch(new URL(path + url.search, 'https://app.supermetry.com'), {
method: request.method, headers, body: request.body, redirect: 'manual',
})
},
}

The framework packages include a proxy. On Supermetry Cloud, pass the key from a server-side environment variable:

import { createSupermetryProxy } from "@supermetry/nextjs/proxy";
export const proxy = createSupermetryProxy({
proxyKey: process.env.SUPERMETRY_PROXY_KEY,
// Required with proxyKey: the visitor address from a header your platform sets
// and browsers cannot (x-real-ip on Vercel; adjust for your host).
getClientIp: (request) => request.headers.get("x-real-ip"),
});

Never read the visitor address from a header a browser can send, such as the first X-Forwarded-For value: with the key, Supermetry trusts it.

The route files for scripts, events and session replay are in the Next.js and Remix package READMEs.

  1. Open your site with the browser’s network panel: the script, events (/sm/api/public/v1/events, status 202) and, with replay on, /sm/replay.js load from your domain.
  2. Visit from your phone on mobile data. Realtime should show your phone’s real location, not your server’s.
  3. On Supermetry Cloud, Settings → Installation → First-party proxy shows when the key was last used.