Skip to content

Serve the script from your own domain

Updated October 18, 2026

Some ad and tracking blockers block requests to analytics domains, including statsdot.com. If you serve the script and its requests from your own domain, those lists no longer match. This is optional: most sites do fine without it.

The idea: a path on your site, for example /sd/, forwards everything to https://statsdot.com/. The script then loads from https://example.com/sd/js/script.js and sends visits to https://example.com/sd/api/collect, which your server passes on.

Your snippet becomes:

<script defer data-domain="example.com" src="/sd/js/script.js"></script>

Keep data-domain as the site you added in Statsdot. Pick a neutral path name: /sd/, /s/ or any word that is not "analytics" or "stats".

The visitor's address

Statsdot needs the visitor's IP address (only in memory, never stored) to count unique visitors. Behind a proxy, Statsdot sees your server's address, so the proxy must forward the visitor's address in the X-Forwarded-For header. Without it, every visit counts as the same visitor.

Nginx

location /sd/ {
    proxy_pass https://statsdot.com/;
    proxy_set_header Host statsdot.com;
    proxy_ssl_server_name on;
    # Behind Cloudflare, use $http_cf_connecting_ip instead of $remote_addr.
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Cookie "";
}

The trailing slash in proxy_pass removes /sd from the path.

Cloudflare Workers

Create a Worker with a route example.com/sd/*:

export default {
  async fetch(request) {
    const url = new URL(request.url);
    const headers = new Headers(request.headers);
    headers.set('X-Forwarded-For', request.headers.get('CF-Connecting-IP') ?? '');
    headers.delete('Cookie');

    return fetch('https://statsdot.com' + url.pathname.replace(/^\/sd/, '') + url.search, {
      method: request.method,
      headers,
      body: request.method === 'POST' ? request.body : undefined,
    });
  },
};

Next.js and Vercel

In next.config.js:

module.exports = {
  async rewrites() {
    return [{ source: '/sd/:path*', destination: 'https://statsdot.com/:path*' }];
  },
};

Netlify

In _redirects:

/sd/*  https://statsdot.com/:splat  200

Check that it works

Open your site, then your dashboard: the visit appears within seconds. After a day with real traffic, check that visitors look plausible. If every visit is counted as one visitor, your host does not forward X-Forwarded-For: set it as in the Nginx or Worker examples. If your site sends a Content Security Policy, the script now comes from your own domain, so 'self' is enough.