Proxy Datasense with Cloudflare
Serve the Datasense script from your own domain with Cloudflare, so ad blockers don't block it.
Add this to worker.js. Replace /_ds with a path of your own.
worker.js
// Cloudflare Worker — route: example.com/_ds/*
const UPSTREAM = "https://usedatasense.com"
export default {
async fetch(request) {
const url = new URL(request.url)
const upstreamPath = url.pathname.replace(/^\/_ds/, "")
const headers = new Headers(request.headers)
headers.set("x-datasense-ip", request.headers.get("cf-connecting-ip") ?? "")
headers.set("x-datasense-country", request.cf?.country ?? "")
headers.set("x-datasense-region", encodeURIComponent(request.cf?.region ?? ""))
headers.set("x-datasense-city", encodeURIComponent(request.cf?.city ?? ""))
headers.delete("cookie")
return fetch(UPSTREAM + upstreamPath + url.search, {
method: request.method,
headers,
// Bytes, not text: session replay chunks are gzipped.
body: request.method === "POST" ? await request.arrayBuffer() : undefined,
})
},
}Then load the script from your own domain:
html
<script
defer
data-website-id="YOUR_SITE_ID"
src="/_ds/js/script.cookies.js"
></script>Verify
Open your site with an ad blocker on. In the browser's network tab, /_ds/js/script.cookies.js and /_ds/api/e load from your own domain, and the visit shows up on the Realtime page.