Getting started
Your own domain
Serve the tracker from your own domain through a Cloudflare Worker, Cloudflare Pages or nginx, so fewer visits are blocked.
Some browsers and extensions block requests to analytics domains. If you would rather load everything from your own site, put a small proxy on a path of your domain, for example /stats, that passes requests on to Quietlytics. Visitors then load the script and send events to your own domain, so there is nothing to match against a list of analytics domains. This is optional: the normal snippet keeps working. Do Not Track and Global Privacy Control are still honoured exactly as before.
The proxy does three jobs: it serves the script at /stats/s.js, it passes /stats/event and /stats/vitals on to Quietlytics, and it tells Quietlytics the visitor's address and country (otherwise every visitor would look like your proxy). Those details are used only to make the daily visitor code and the country, exactly as for a direct visit, and are never stored.
Step 1: make a proxy key
On your account page, find Serve the tracker from your own domain and press Make a key. Copy it straight away, because it is shown once. The key proves the requests come from your proxy and works only for websites on your account. Keep it private and never put it in a web page. If it leaks, make a new key and the old one stops working at once.
Step 2: set up the proxy
Pick the option that matches how your site is hosted. The Cloudflare options are the easiest, and your site's DNS must be on Cloudflare with the record for your site proxied (the orange cloud). Menu names change from time to time, so look for the closest match.
Option A: a Cloudflare Worker (any site on Cloudflare)
- In the Cloudflare dashboard open Workers & Pages, choose Create, then Create Worker. Name it, for example,
quietlytics-proxy, and press Deploy. - Press Edit code, replace everything with the code below, and press Deploy:
export default {
async fetch(req, env) {
const url = new URL(req.url)
const path = url.pathname.replace(/^\/stats/, '')
const target = path === '/s.js' ? '/tracker.js' : '/api' + path
const headers = new Headers(req.headers)
headers.delete('cookie')
headers.set('x-ql-key', env.QL_KEY)
headers.set('x-ql-ip', req.headers.get('cf-connecting-ip') || '')
headers.set('x-ql-country', req.headers.get('cf-ipcountry') || '')
return fetch('https://quietlytics.app' + target, {
method: req.method,
headers,
body: req.method === 'POST' ? req.body : undefined,
})
},
}- Open the Worker's Settings, then Variables and Secrets. Add a variable of type Secret named
QL_KEYand paste your key as the value. Deploy again if asked. - Still in Settings, open Domains & Routes and add a Route. Set the route to
yoursite.com/stats/*and choose your site's zone. If your site also answers onwww, addwww.yoursite.com/stats/*too. (Use a Worker route rather than a Workers custom domain, so the Worker sits in front of your existing site on only that path.) - Check it: open
https://yoursite.com/stats/s.jsin your browser. You should see the tracker's code.
Option B: Cloudflare Pages
If your site is hosted on Cloudflare Pages, a Pages Function does the same job without a separate Worker. Add this file to your project as functions/stats/[[path]].js:
export async function onRequest({ request, env }) {
const url = new URL(request.url)
const path = url.pathname.replace(/^\/stats/, '')
const target = path === '/s.js' ? '/tracker.js' : '/api' + path
const headers = new Headers(request.headers)
headers.delete('cookie')
headers.set('x-ql-key', env.QL_KEY)
headers.set('x-ql-ip', request.headers.get('cf-connecting-ip') || '')
headers.set('x-ql-country', request.headers.get('cf-ipcountry') || '')
return fetch('https://quietlytics.app' + target, {
method: request.method,
headers,
body: request.method === 'POST' ? request.body : undefined,
})
}Then, in your Pages project, open Settings, then Variables and Secrets (or Environment variables), add QL_KEY as a secret for the production environment, and deploy the project again. There is no route to set up: the file name is the route, and it covers everything under /stats/. If your site is a static build, make sure the functions folder sits at the root of the project, next to your build output folder, not inside it.
Option C: your own server (nginx)
Any server that can proxy a request and add headers will do. With nginx:
location = /stats/s.js {
proxy_pass https://quietlytics.app/tracker.js;
proxy_ssl_server_name on;
proxy_set_header Host quietlytics.app;
proxy_set_header Cookie "";
}
location /stats/ {
proxy_pass https://quietlytics.app/api/;
proxy_ssl_server_name on;
proxy_set_header Host quietlytics.app;
proxy_set_header Cookie "";
proxy_set_header x-ql-key "PASTE-YOUR-KEY";
proxy_set_header x-ql-ip $remote_addr;
}If a CDN sits in front of this server, $remote_addr is the CDN's address, not the visitor's. Pass on the visitor's address instead (for example from CF-Connecting-IP or X-Forwarded-For), and a country code in x-ql-country if your CDN provides one. Without a country, visits are counted but show no country. Keep this config file private, because it contains the key.
Step 3: change your snippet
Replace the usual snippet with one that loads from your own path and says where to send events:
<script defer src="/stats/s.js" data-api="/stats"></script>
Everything now goes to your own domain, so your Content Security Policy needs no extra entries beyond what already allows your own scripts and requests.
Check it works
- Open your site with the browser's network tab open.
s.jsshould load from your domain, and/stats/eventshould return202. - Open your dashboard. The visit should appear within seconds, with your country.
If something is off:
/stats/s.jsshows a 404 or your normal 404 page. The route or function isn't running. Check the route's spelling and zone, that the site's DNS record is proxied (orange cloud), and for Pages that the file is in the right place and you deployed after adding it./stats/eventreturns 202 but nothing appears. Events are dropped without saying why. Check that the key is the current one for the account that owns this website, that the website is verified, and that the secret is named exactlyQL_KEY.- Visits appear but all from one country, or fewer visitors than expected. The proxy isn't passing the visitor's address or country. In a Worker or Pages Function it comes from
cf-connecting-ipandcf-ipcountry, so the site must be proxied through Cloudflare. /stats/eventis missing. The snippet is missingdata-api="/stats", so the tracker is still sending to quietlytics.app.- You changed the path. If you use a path other than
/stats, change it in the snippet'sdata-api, in the route, and in the code (the/^\/stats/line).