Proxy Datasense with Next.js
Serve the Datasense script from your own domain with Next.js, so ad blockers don't block it.
Add this to next.config.ts. Replace /_ds with a path of your own.
next.config.ts
// next.config.ts
import type { NextConfig } from "next"
const nextConfig: NextConfig = {
async rewrites() {
return [
{ source: "/_ds/js/script.cookies.js", destination: "https://usedatasense.com/js/script.cookies.js" },
{ source: "/_ds/api/e", destination: "https://usedatasense.com/api/e" },
{ source: "/_ds/api/p", destination: "https://usedatasense.com/api/p" },
// Session replay, if you turn it on
{ source: "/_ds/js/recorder.js", destination: "https://usedatasense.com/js/recorder.js" },
{ source: "/_ds/api/replay", destination: "https://usedatasense.com/api/replay" },
]
},
}
export default nextConfigThen 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.