GoodData
Proxy Guide

Proxying the Tracking Script

Adblockers often block tracking scripts that are loaded from third-party domains (like cdn.gooddata.com or your self-hosted analytics domain). To ensure maximum data accuracy and prevent the script from being blocked, you can proxy the Gooddata script through your own domain.

By proxying, the script appears as a first-party resource (e.g., <YOUR_PROJECT_ID>/js/script.js), bypassing standard adblocker rules while maintaining privacy compliance.

Proxying with Next.js

If you are using Next.js, you can use the rewrites feature in your next.config.js to seamlessly proxy the script and API endpoints.

// next.config.js
module.exports = {
  async rewrites() {
    return [
      {
        source: '/js/script.js',
        destination: 'https://gooddata-fyp.onrender.com/sdk/tracker.js',
      },
      {
        source: '/api/analytics/:path*',
        destination: 'https://gooddata-fyp.onrender.com/api/track/:path*',
      },
    ];
  },
}

Once configured, you simply update your tracking snippet to point to /js/script.js and set the data-project-id and data-api attributes:

<script defer src="/js/script.js" data-project-id="<YOUR_PROJECT_ID>" data-api="/api/analytics"></script>

Proxying with NGINX

If you are using NGINX, you can configure a reverse proxy block:

server {
    # ... your existing configuration

    location = /js/script.js {
        proxy_pass https://gooddata-fyp.onrender.com/sdk/tracker.js;
        proxy_set_header Host gooddata-fyp.onrender.com;
        proxy_ssl_server_name on;
    }

    location /api/analytics/ {
        proxy_pass https://gooddata-fyp.onrender.com/api/track/;
        proxy_set_header Host gooddata-fyp.onrender.com;
        proxy_ssl_server_name on;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}