Developer Documentation

Tracking, Caps & Identity

Integrating with an AI coding agent?
Point Claude Code, Cursor, or Codex at https://adsrouter.ai/llms-full.txt — it contains every endpoint, auth header, JSON schema, Koah bridge snippet, and beacon rule in one self-contained file.

Cloaked First-Party Beacons & Clicks

For every S2S ad (direct, network, house, gravity, thrad, velocity), AdsRouter wraps tracking URLs on https://api.adsrouter.ai:

  • impression_beacon_url (GET /v1/imp/:id): Fire once when the ad is genuinely viewable (at least 50% visible in the viewport). AdsRouter stamps viewed_at, increments ar_stats_daily.impressions, and returns 204 No Content for own ads or 302 Found to the upstream network's impression pixel for mediated ads.
  • render_beacon_url (GET /v1/render/:id): Returned when an upstream network (such as Thrad) uses two-stage billing. Fire immediately when the ad mounts in the DOM.
  • click_url (GET /v1/click/:id): Always use ad.click_url as the link href (never bypass it). AdsRouter stamps clicked_at, increments ar_stats_daily.clicks, and 302-redirects to the destination or upstream click URL.

Viewability Beacon Snippet (Custom Renderers)

function trackAdViewability(cardEl, ad) {
  if (ad.render_beacon_url) {
    new Image().src = ad.render_beacon_url;
  }

  let fired = false;
  const fireImpression = () => {
    if (fired || !ad.impression_beacon_url) return;
    fired = true;
    if (navigator.sendBeacon) {
      navigator.sendBeacon(ad.impression_beacon_url);
    } else {
      fetch(ad.impression_beacon_url, { mode: 'no-cors', keepalive: true });
    }
  };

  if ('IntersectionObserver' in window) {
    const io = new IntersectionObserver((entries) => {
      if (entries.some((e) => e.isIntersecting && e.intersectionRatio >= 0.5)) {
        fireImpression();
        io.disconnect();
      }
    }, { threshold: 0.5 });
    io.observe(cardEl);
  } else {
    fireImpression();
  }
}

Tiered Identity Resolution

Frequency caps need a stable per-user key without forcing cookies or PII. AdsRouter resolves identity_key in strict priority order:

Tieridentity_kindSource FieldNotes
1 (Best)maiduser.maidApple IDFA or Google GAID (only when end user consented).
2pub_user_iduser.pub_user_idOpaque publisher-scoped user ID from your app's auth system.
3 (Fallback)ip_ua_hashdevice.ip + device.ua + accept_languageOne-way sha256(ip|ua|accept_lang). No raw IP stored in the identity key.

Frequency Caps & In-Flight Reservations

You can set frequency caps at both the property level (default_freq_cap_hourly, default_freq_cap_daily) and the campaign level (freq_cap_hourly, freq_cap_daily, freq_cap_window_sec).

To prevent rapid concurrent chat turns from blowing past a cap before the browser fires the viewability beacon, AdsRouter counts viewed impressions (viewed_at IS NOT NULL) plus any in-flight reservations (reservation_expires_at > now(), default 10 minutes). If an ad is served but never viewed, its reservation expires automatically after 10 minutes and frees the cap slot.