Actually Tracking

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. Actually Tracking 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.

Route the script and its events through a subdomain of your site, such as a.yoursite.com, without running any proxy code. You add one DNS record; we handle the routing and the security certificate.

  1. Open Project settings → Tracking and enter the subdomain under Custom tracking domain.

  2. Add the DNS record it shows, where your domain's DNS is managed:

    TypeNameTarget
    CNAMEaproxy.actuallytracking.com

    On Cloudflare, set the record to DNS only (grey cloud). Some providers want the full name, a.yoursite.com, instead of a.

  3. Wait for the status to turn Active. It is checked when you add the domain, every ten minutes after that, and whenever you press Check again. The certificate is issued automatically within a minute of the DNS record appearing.

  4. Load the script from your subdomain and send events to it:

<script
  src="https://a.yoursite.com/at1.js"
  data-client-id="YOUR_CLIENT_ID"
  data-api-url="https://a.yoursite.com"
  defer
  async
></script>

Once a domain is active, the install snippets in Project settings → Tracking use it automatically, for the script tag and for every SDK's apiUrl.

Keep data-api-url (or apiUrl) as the full https:// address of your subdomain. Session replay loads from the same subdomain, and your project's allowed domains stay the same: they are the sites the script runs on, not the tracking subdomain.

If your site sets a Content Security Policy, allow your subdomain in script-src and connect-src.

A project can have up to five custom domains, for example one per site or environment. To stop using one, switch your script back to https://actuallytracking.com/op1.js, remove the domain in settings, then delete the DNS record.

Run your own proxy

If your app already forwards requests through its own server, you can proxy the script and events yourself instead.

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 Actually Tracking.

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

import { Hono } from 'hono'

const app = new Hono()

// 1. Proxy the script file
app.get('/op1.js', async (c) => {
  const scriptUrl = 'https://actuallytracking.com/op1.js'
  try {
    const res = await fetch(scriptUrl)
    const text = await res.text()
    
    c.header('Content-Type', 'text/javascript')
    // Optional caching for 24 hours
    c.header('Cache-Control', 'public, max-age=86400, stale-while-revalidate=86400')
    return c.body(text)
  } catch (e) {
     return c.json({ error: 'Failed to fetch script' }, 500)
  }
})

// 2. Proxy the track event
app.post('/track', async (c) => {
  const body = await c.req.json()
  
  // Forward the client's IP address (be sure to pick correct IP based on your infra)
  const ip = c.req.header('cf-connecting-ip') ?? 
             c.req.header('x-forwarded-for')?.split(',')[0]

  const headers = new Headers()
  headers.set('Content-Type', 'application/json')
  headers.set('Origin', c.req.header('origin') ?? '')
  headers.set('User-Agent', c.req.header('user-agent') ?? '')
  headers.set('actuallytracking-client-id', c.req.header('actuallytracking-client-id') ?? '')
  
  if (ip) {
    headers.set('actuallytracking-client-ip', ip)
  }

  try {
    const res = await fetch('https://api.actuallytracking.com/track', {
      method: 'POST',
      headers,
      body: JSON.stringify(body),
    })
    return c.json(await res.text(), res.status)
  } catch (e) {
    return c.json(e, 500)
  }
})

export default app

This script sets up two endpoints:

  1. GET /op1.js: Fetches the Actually Tracking script and serves it from your domain.
  2. POST /track: Receives events from the frontend, adds necessary headers (User-Agent, Origin, Content-Type, actuallytracking-client-id, actuallytracking-client-ip), and forwards them to Actually Tracking's API.

Frontend Configuration

Once your proxy is running, you need to configure the Actually Tracking script on your frontend to use your proxy endpoints instead of the default ones.

<script>
  window.op=window.op||function(){var n=[];return new Proxy(function(){arguments.length&&n.push([].slice.call(arguments))},{get:function(t,r){return"q"===r?n:function(){n.push([r].concat([].slice.call(arguments)))}} ,has:function(t,r){return"q"===r}}) }();
  window.op('init', {
    apiUrl: 'https://api.domain.com'
    clientId: 'YOUR_CLIENT_ID',
    trackScreenViews: true,
    trackOutgoingLinks: true,
    trackAttributes: true,
  });
</script>
<script src="https://api.domain.com/op1.js" defer async></script>

By doing this, all requests are sent to your domain first, bypassing adblockers that look for third-party tracking domains.

On this page