You can use Netlify redirects to proxy all analytics traffic through your own domain. This will reduce DNS lookups, as well as prevent Adblockers from blocking requests.
_redirects
fileAdd following rewrite rules into the file:
/bee.js https://cdn.splitbee.io/sb.js 200/_hive/* https://hive.splitbee.io/:splat 200
Find the Netlify rewrites documentation here
You will need to adapt the script tag to reflect the changes and use your own proxy.
<script async data-api="/_hive" src="/bee.js"></script>
data-api
sets the endpoint for all tracking requests. We are using /_hive
in this example.
src
needs to point to the Splitbee JS file that is proxied through your servers. We are using /bee.js
in this example. Feel free to adapt those paths & filenames.
When using the @splitbee/web library, you need to tell it where to load Splitbee from as well as where it should send all events. To do this, enter your custom endpoint and the URL to the proxied script in the init
function.
splitbee.init({scriptUrl: "/bee.js",apiUrl: "/_hive",})
All set. You can open up the network tab inside the DevTools to verify that all traffic is indeed routed through your domain.