Proxy setup
Serve the script and send events through your own domain with data-api-url. Netlify, Nginx and Cloudflare Worker examples, marked untested.
Untested: The examples below have not been tested by the TayStack team. Treat them as a starting point and verify them as described at the end of this page.
What a proxy changes
By default the script sends events to /api/events on the same origin the script was loaded from. If you serve the script from your own domain, events therefore go to your own domain too. To send them to a different path, set data-api-url: the script uses that URL as it is, and a path such as /stats/e is resolved against the page.
<script defer data-website-id="site_abcd1234efgh" data-domain="example.com" data-api-url="/stats/e" src="/stats/script.js"></script>data-domain still has to match the page's own domain. Your proxy needs to do two things:
- Forward
GET /js/script.jsto the TayStack script. - Forward
POST /api/eventswith the body unchanged and the browser'sUser-Agent. A request without a User-Agent is treated as a bot and not stored.
Visitor location: The server reads the address of the connection it receives. Behind a proxy that is the proxy's address, so country, region and city describe the proxy, and the per-address request limit is shared by all your visitors. There is no way to pass the visitor's address through today.
Netlify redirects
# _redirects (or the same rules in netlify.toml)
/stats/script.js https://www.taystack.com/js/script.js 200
/stats/e https://www.taystack.com/api/events 200Nginx
location = /stats/script.js {
proxy_pass https://www.taystack.com/js/script.js;
proxy_ssl_server_name on;
proxy_set_header Host www.taystack.com;
}
location = /stats/e {
proxy_pass https://www.taystack.com/api/events;
proxy_ssl_server_name on;
proxy_set_header Host www.taystack.com;
}Cloudflare Worker
export default {
async fetch(request) {
const url = new URL(request.url)
if (url.pathname === '/stats/script.js' && request.method === 'GET') {
return fetch('https://www.taystack.com/js/script.js')
}
if (url.pathname === '/stats/e' && request.method === 'POST') {
return fetch('https://www.taystack.com/api/events', {
method: 'POST',
headers: {
'content-type': request.headers.get('content-type') || 'text/plain',
'user-agent': request.headers.get('user-agent') || '',
},
body: request.body,
})
}
// Everything else goes to your site as usual.
return fetch(request)
},
}Verify your proxy
- Open
/stats/script.json your domain. You should see the script. - Load a page and look in the Network tab for a
POSTto/stats/eanswering202. - Check that the visit appears in the dashboard. A 202 alone does not prove it was stored.
A proxy under your own domain may be blocked less often by ad blockers. That is not guaranteed.