Avoid adblockers with proxy
Learn why adblockers block analytics and how to avoid it by proxying events.
In this article we need to talk about adblockers, why they exist, how they work, and how to avoid them.
Adblockers' main purpose was initially to block ads, but they have since started to block tracking scripts as well. This is primarily for privacy reasons, and while we respect that, there are legitimate use cases for understanding your visitors. OpenPanel is designed to be a privacy-friendly, cookieless analytics tool that doesn't track users across sites, but generic blocklists often catch all analytics tools indiscriminately.
The best way to avoid adblockers is to proxy events via your own domain name. Adblockers generally cannot block requests to your own domain (first-party requests) without breaking the functionality of the site itself.
Built-in Support
Today, our Next.js SDK and WordPress plugin have built-in support for proxying:
- WordPress: Does it automatically.
- Next.js: Easy to setup with a route handler.
Implementing Proxying for Any Framework
If you are not using Next.js or WordPress, you can implement proxying in any backend framework. The key is to set up an API endpoint on your domain (e.g., api.domain.com or domain.com/api) that forwards requests to OpenPanel.
Below is an example of how to set up a proxy using a Hono server. This implementation mimics the logic used in our Next.js SDK.
You can always see how our Next.js implementation looks like in our repository.
Hono Example
This script sets up two endpoints:
GET /op1.js: Fetches the OpenPanel script and serves it from your domain.POST /track: Receives events from the frontend, adds necessary headers (User-Agent, Origin, Content-Type, openpanel-client-id, openpanel-client-ip), and forwards them to OpenPanel's API.
Frontend Configuration
Once your proxy is running, you need to configure the OpenPanel script on your frontend to use your proxy endpoints instead of the default ones.
By doing this, all requests are sent to your domain first, bypassing adblockers that look for third-party tracking domains.