Proxy with NextJS

You can use NextJS to route all tracking traffic though your own (or Vercel) server and domain. This will help prevent AdBlockers from blocking analytics.

Step 1: Add rewrites

Add the following rewrites to the next.config.js

module.exports = {
    async rewrites() {
        return [
            // First one is only necessary if using Script Tag
            { 
                source: "/toolbird.js", 
                destination: "https://api.toolbird.io/js/script.js"
            },
            {
                source: "/toolbird/event",
                destination: "https://api.toolbird.io/v1/event"
            },
            {
                source: "/toolbird/identify",
                destination: "https://api.toolbird.io/v1/identify"
            }
        ]
    }
}

Step 2 - Script Tag

You will need to add `data-host` to the script tag like so:

<script 
    src="/toolbird.js" 
    data-domain="yourdomain.com"
    data-host="/toolbird"
></script>

This will rewrite all requests to the `/toolbird.js` endpoint to the script endpoint on the Toolbird Server.

Step 2 - JavaScript Package

When using the Javascript Package you will need to add another option to the initalising function.

toolbird.init({
    domain: "yourdomain.com",
    host: "/toolbird"
})

Last updated