Getting started Doc #7 Reviewed Nov 7, 2026

Serve from your own site

Proxy the tracker through a path on your own site, so the browser only talks to your domain

Instead of a custom domain, you can serve the tracker from a path on your own site, for example https://yourstore.com/_a/s.js. Your server forwards those requests to Anacoic, so the browser only ever talks to your site. It takes a few lines of server config.

How it works

  1. The page loads /_a/s.js from your site. The tracker sends events to /_a/e, next to where it was loaded from.
  2. Your server forwards both paths to https://edge.anacoic.com/s.js and https://edge.anacoic.com/e, with the visitor’s request as it came: method, query string, body and headers such as Content-Type, User-Agent, Origin and Sec-GPC.
  3. It removes the Cookie header (the gateway doesn’t need your site’s cookies) and adds three headers:
HeaderValue
X-Anacoic-Proxy-SecretThis gateway’s proxy secret
X-Anacoic-Client-IPThe visitor’s IP address, as your platform reports it
X-Anacoic-HostYour site’s host name
  1. It passes the gateway’s reply back unchanged, including any Set-Cookie header.

Why the secret

Every request through your proxy reaches the gateway from your server’s IP address. Ad platforms need the visitor’s address to match events, and the gateway’s per-IP rate limit needs it too. Anyone can send an IP header, so the gateway only believes X-Anacoic-Client-IP and X-Anacoic-Host when the request also carries the gateway’s proxy secret. A request with a wrong secret is refused with 401. Without any secret, the forwarded headers are ignored and every visitor looks like your server.

Find the secret in the gateway under Diagnostics → Security controls → Proxy secret. Only organization owners and admins see it. Put it in your server’s settings or environment variables, never in a page or a snippet. If it leaks, replace it there: the old one stops working at once.

Step 1: add the proxy

Pick the setup that matches where your site runs. Each one forwards only /_a/s.js and /_a/e.

Next.js

Add middleware.ts to the project root (on Next.js 16 the file is proxy.ts and the function is proxy). A rewrite in next.config can’t add the secret header, so this uses middleware. Set ANACOIC_PROXY_SECRET in your environment variables.

import { NextResponse, type NextRequest } from 'next/server';

const EDGE = 'https://edge.anacoic.com';
const PREFIX = '/_a';
const PATHS = new Set(['/s.js', '/e']);

export async function middleware(request: NextRequest) {
  const path = request.nextUrl.pathname.slice(PREFIX.length);
  if (!PATHS.has(path)) return new NextResponse(null, { status: 404 });

  const headers = new Headers(request.headers);
  headers.delete('cookie');
  headers.delete('host');
  headers.delete('accept-encoding');
  headers.set('X-Anacoic-Proxy-Secret', process.env.ANACOIC_PROXY_SECRET ?? '');
  headers.set('X-Anacoic-Host', request.nextUrl.hostname);
  // Vercel sets x-real-ip to the visitor's address; elsewhere use the header your load balancer sets
  const ip = request.headers.get('x-real-ip');
  if (ip) headers.set('X-Anacoic-Client-IP', ip);

  const upstream = await fetch(EDGE + path + request.nextUrl.search, {
    method: request.method,
    headers,
    body: request.method === 'POST' ? await request.arrayBuffer() : undefined,
    redirect: 'manual',
  });
  return new NextResponse(upstream.body, { status: upstream.status, headers: upstream.headers });
}

export const config = { matcher: '/_a/:path*' };

Cloudflare Worker

Create a Worker on your site’s zone with the route yourstore.com/_a/*, and add ANACOIC_PROXY_SECRET as a secret on the Worker.

const EDGE = 'https://edge.anacoic.com';
const PREFIX = '/_a';
const PATHS = new Set(['/s.js', '/e']);

export default {
  async fetch(request, env) {
    const url = new URL(request.url);
    const path = url.pathname.slice(PREFIX.length);
    if (!PATHS.has(path)) return new Response('Not found', { status: 404 });

    const headers = new Headers(request.headers);
    headers.delete('Cookie');
    headers.set('X-Anacoic-Proxy-Secret', env.ANACOIC_PROXY_SECRET);
    headers.set('X-Anacoic-Client-IP', request.headers.get('CF-Connecting-IP') ?? '');
    headers.set('X-Anacoic-Host', url.hostname);

    return fetch(EDGE + path + url.search, {
      method: request.method,
      headers,
      body: request.method === 'POST' ? request.body : undefined,
      redirect: 'manual',
    });
  },
};

nginx

Add this inside the server block for your site and replace YOUR_PROXY_SECRET. Keep the file out of version control. nginx passes Set-Cookie back by default.

location ~ ^/_a/(s\.js|e)$ {
    rewrite ^/_a(/.*)$ $1 break;
    proxy_pass https://edge.anacoic.com;
    proxy_ssl_server_name on;
    proxy_set_header Host edge.anacoic.com;
    proxy_set_header Cookie "";
    proxy_set_header X-Anacoic-Proxy-Secret "YOUR_PROXY_SECRET";
    proxy_set_header X-Anacoic-Client-IP $remote_addr;
    proxy_set_header X-Anacoic-Host $host;
}

If nginx sits behind a load balancer or CDN, $remote_addr is that machine’s address. Use the visitor address it passes on instead (for example with nginx’s real_ip module).

Netlify

Save this as netlify/edge-functions/anacoic.ts and set ANACOIC_PROXY_SECRET in the site’s environment variables.

import type { Config, Context } from '@netlify/edge-functions';

const EDGE = 'https://edge.anacoic.com';
const PREFIX = '/_a';
const PATHS = new Set(['/s.js', '/e']);

export default async (request: Request, context: Context) => {
  const url = new URL(request.url);
  const path = url.pathname.slice(PREFIX.length);
  if (!PATHS.has(path)) return new Response('Not found', { status: 404 });

  const headers = new Headers(request.headers);
  headers.delete('cookie');
  headers.delete('host');
  headers.delete('accept-encoding');
  headers.set('X-Anacoic-Proxy-Secret', Netlify.env.get('ANACOIC_PROXY_SECRET') ?? '');
  headers.set('X-Anacoic-Client-IP', context.ip);
  headers.set('X-Anacoic-Host', url.hostname);

  return fetch(EDGE + path + url.search, {
    method: request.method,
    headers,
    body: request.method === 'POST' ? request.body : undefined,
    redirect: 'manual',
  });
};

export const config: Config = { path: '/_a/*' };

Step 2: load the tracker from your site

Replace the snippet on your pages with this one, using your gateway ID:

<script src="/_a/s.js" data-gateway="YOUR_GATEWAY_ID"></script>

The Setup tab in the dashboard has the same setups and the tag with your gateway ID filled in, under Your own site.

Step 3: check it

  1. Open a page of your site with your browser’s developer tools on the Network tab.
  2. You should see /_a/s.js load and a request to /_a/e answered with 200.
  3. In Anacoic, the event shows in the gateway’s live stream. Its receipt in the Delivery log lists the IP address among the identifiers sent.

A 401 from /_a/e means the secret in your proxy doesn’t match the gateway’s. A 429 for most visitors usually means the proxy isn’t sending the secret, so every visitor counts as your server’s IP address.

Cookies on your domain

When the visitor has allowed ad storage, the gateway’s reply can set Meta’s _fbp and _fbc cookies on your domain, for up to 90 days. A cookie set by your server this way lasts longer in Safari than one set by a script. This needs the consent signal from your consent banner:

anacoic.consent({ ad_storage: 'granted' });

Without it, no cookie is set. The gateway only renews values the tracker already sent and never sets cookies on edge.anacoic.com. Your proxy must pass Set-Cookie back to the browser, as all the setups above do.

Global Privacy Control

Browsers such as Brave can send Sec-GPC: 1, a signal that the visitor opts out of having their data sold or shared. By default the gateway then sends the event only to your own webhooks, not to ad platforms, and sets no marketing cookies. The delivery log shows these events as “Visitor opted out (Global Privacy Control)”. The setting is under Diagnostics → Security controls. Proxies pass the header on unchanged.