← Back

Next.js Proxy

If you are using Next.js (version 9.5+), you can bypass ad-blockers by using the rewrite functionality!

Add rewrites to next.config.js

Add following rewrite rules into the file:

async rewrites() {
  return [
    {
      source: "/bee.js",
      destination: "https://cdn.splitbee.io/sb.js",
    },
    {
      source: "/_hive/:slug",
      destination: "https://hive.splitbee.io/:slug",
    },
  ];
},
View Full config file example

Find the documentation here: https://nextjs.org/docs/api-reference/next.config.js/rewrites

module.exports = {
  async rewrites() {
    return [
	    {
	      source: "/bee.js",
	      destination: "https://cdn.splitbee.io/sb.js",
	    },
	    {
	      source: "/_hive/:slug",
	      destination: "https://hive.splitbee.io/:slug",
	    },
	  ];
  },
}

Adapt the Splitbee script tag

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 calls. 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.