Connect your website to AI Traffic
Public guide: add your domain in SpyderBot, copy your tracking key, then install the snippet that matches your stack. No account is required to read this page - sign in only when you are ready to add a site in the app.
Before you install
Get a tracking key from the product (AI Traffic is inside SpyderBot after sign-in).
- Create an account or sign in.
- Open AI Traffic and add your website (domain). SpyderBot issues a unique tracking key for that site.
- Replace
YOUR_TRACKING_KEYin the snippets below with your real key. - After traffic hits your site, SpyderBot receives events and marks the installation as active when data arrives.
API endpoint for server-side calls:
https://api.spyderbot.net/server-track (POST, JSON body, header
X-Tracking-Key).
Browser (recommended for visitors)
Paste in <head> or your SPA root layout so normal browsers load the tracker.
<link rel="preconnect" href="https://spyderbot.net" crossorigin>
<script async src="https://spyderbot.net/wfm.js?key=YOUR_TRACKING_KEY&v=1.1.3"></script>
More integration channels
Official packages: Cloudflare Worker is released on GitHub (v1.0.0). WordPress plugin v0.3.2 is available below when downloads are enabled.
Log import (Server / CDN)
Upload nginx, Apache, or Cloudflare Logpush access logs to measure AI crawler hits (GPTBot, ClaudeBot, and similar), status codes, and pages crawled — including historical crawls. Does not measure human AI referrals or chat-referred humans. Default overlap is historical-only to avoid double-counting with live Worker/script tracking.
In the product: open AI Traffic → your website → Setup → Log import to upload a file or copy the Cloudflare Logpush HTTP destination.
Read the Log import guide →Cloudflare Worker (zero-code at the edge)
Inject tracking on HTML responses and POST server-side signals for bots that skip JavaScript. Route *yourdomain.com/*.
- Deploy with the button (opens Cloudflare's official flow for the public Worker repo).
- When asked for a secret, paste your SpyderBot tracking key as
TRACKING_KEY. - Add a route that covers HTML pages (avoid pure static/CDN asset paths).
- If you use CSP, allow
script-srcandconnect-srcforhttps://spyderbot.net(and your tracking API origin).
Source: github.com/spyderbotlabs/spb-cloudflare-worker (v1.0.0).
Alternative: copy-paste snippet
// SpyderBot Cloudflare Worker — paste in Cloudflare Dashboard → Workers → Create
// Recommended routes (exclude static assets):
// *yourdomain.com/
// *yourdomain.com/*.html
// *yourdomain.com/blog/*
// Avoid: *yourdomain.com/cdn-cgi/* , *yourdomain.com/assets/* , *yourdomain.com/*.css|js|png|…
// CSP: allow script-src + connect-src for https://spyderbot.net and the tracking API origin used below.
// Session cookie: _spyd_sid (SameSite=Lax, 30-min rolling) — only after analytics Accept
// (or for bot UA server-track). Honours sb_cookie_consent.
const TRACKING_KEY = 'YOUR_TRACKING_KEY';
const SERVER_TRACK_URL = 'https://api.spyderbot.net/server-track';
const SPYDER_SCRIPT_URL = 'https://spyderbot.net/wfm.js?key=YOUR_TRACKING_KEY&v=1.1.3';
const SPYDER_SCRIPT_URL_ORIGIN = 'https://spyderbot.net';
const SESSION_COOKIE = '_spyd_sid';
const SESSION_TTL_SEC = 30 * 60;
const CONSENT_COOKIE = 'sb_cookie_consent';
const CONSENT_VERSION = 3;
const BOT_UA_RE = /gptbot|chatgpt|claudebot|anthropic|perplexity|google-extended|bingbot|googlebot|bytespider|petalbot|amazonbot|applebot|duckduckbot|yandexbot|baiduspider|semrushbot|ahrefsbot|facebookexternalhit|twitterbot|linkedinbot|slurp|ccbot|diffbot|ia_archiver|\bbot\b|crawler|spider|scraper/i;
function isBotUa(ua) {
return BOT_UA_RE.test(ua || '');
}
function parseCookies(header) {
const out = {};
(header || '').split(';').forEach((part) => {
const i = part.indexOf('=');
if (i === -1) return;
const k = part.slice(0, i).trim();
const v = part.slice(i + 1).trim();
if (k) out[k] = decodeURIComponent(v);
});
return out;
}
function consentChoice(cookies) {
const raw = cookies[CONSENT_COOKIE] || '';
const parts = String(raw).split('|');
if (Number(parts[1] || 0) !== CONSENT_VERSION) return null;
if (parts[0] === 'accepted' || parts[0] === 'rejected') return parts[0];
// Granular choice (v3+): custom|ver|ts|aXmXfX → analytics purpose decides.
if (parts[0] === 'custom') {
const m = /^a([01])m[01]f[01]$/.exec(parts[3] || '');
if (m) return m[1] === '1' ? 'accepted' : 'rejected';
}
return null;
}
function getOrCreateSessionId(request) {
const cookies = parseCookies(request.headers.get('Cookie'));
const existing = cookies[SESSION_COOKIE];
if (existing && /^[A-Za-z0-9_-]{8,128}$/.test(existing)) {
return existing;
}
return 'cf_' + crypto.randomUUID().replace(/-/g, '');
}
function sessionSetCookie(sid) {
return SESSION_COOKIE + '=' + encodeURIComponent(sid)
+ '; Path=/; Max-Age=' + SESSION_TTL_SEC
+ '; SameSite=Lax';
}
function sessionExpireCookie() {
return SESSION_COOKIE + '=; Path=/; Max-Age=0; SameSite=Lax';
}
function clientIp(request) {
return request.headers.get('cf-connecting-ip')
|| (request.headers.get('x-forwarded-for') || '').split(',')[0].trim()
|| '';
}
function clientCountry(request) {
const fromCf = (request.cf && request.cf.country) || request.headers.get('cf-ipcountry') || '';
return String(fromCf).toUpperCase();
}
function looksLikeAsset(url) {
try {
const path = new URL(url).pathname.toLowerCase();
return /\.(css|js|mjs|map|jpg|jpeg|gif|png|ico|svg|webp|avif|woff2?|ttf|eot|mp4|webm|mp3|pdf|zip|gz|xml|txt|json)$/.test(path);
} catch (_) {
return false;
}
}
async function postServerTrack(request, sid, status, method) {
const ua = request.headers.get('user-agent') || '';
const ip = clientIp(request);
const country = clientCountry(request);
await fetch(SERVER_TRACK_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Tracking-Key': TRACKING_KEY,
'User-Agent': ua,
},
body: JSON.stringify({
url: request.url,
referrer: request.headers.get('referer') || '',
session_id: sid,
client_ip: ip,
country: country,
status_code: status,
method: method,
source: 'cf_worker',
}),
});
}
function withSessionHeaders(response, sid, stripValidators, allowSession, expireSession) {
const headers = new Headers(response.headers);
if (expireSession) {
headers.append('Set-Cookie', sessionExpireCookie());
} else if (allowSession) {
headers.append('Set-Cookie', sessionSetCookie(sid));
}
if (stripValidators) {
headers.delete('content-length');
headers.delete('etag');
headers.delete('last-modified');
}
return new Response(response.body, {
status: response.status,
statusText: response.statusText,
headers,
});
}
export default {
async fetch(request, env, ctx) {
const method = (request.method || 'GET').toUpperCase();
const cookies = parseCookies(request.headers.get('Cookie'));
const choice = consentChoice(cookies);
const ua = request.headers.get('user-agent') || '';
const bot = isBotUa(ua);
// Humans: _spyd_sid + wfm.js only after Accept. Bots: sid for server-track only.
const allowSession = bot || choice === 'accepted';
const expireSession = !bot && choice === 'rejected';
const sid = allowSession ? getOrCreateSessionId(request) : '';
// Fast-path: skip non-HTML work for obvious static assets
if (looksLikeAsset(request.url) && method !== 'HEAD') {
const assetResp = await fetch(request);
return withSessionHeaders(assetResp, sid, false, allowSession, expireSession);
}
const response = await fetch(request);
const contentType = response.headers.get('content-type') || '';
const isHtml = contentType.includes('text/html');
const status = response.status;
// Server-track ONLY bots / AI agents (humans → wfm.js after consent).
if (bot && isHtml && (method === 'GET' || method === 'HEAD')) {
ctx.waitUntil(postServerTrack(request, sid, status, method).catch(() => {}));
}
// Inject wfm.js only on successful GET HTML when analytics consent is Accept.
if (!isHtml || method !== 'GET' || status < 200 || status >= 300 || choice !== 'accepted') {
return withSessionHeaders(response, sid, false, allowSession, expireSession);
}
let alreadyTagged = false;
const preconnectTag = '<link rel="preconnect" href="' + SPYDER_SCRIPT_URL_ORIGIN + '" crossorigin>';
const scriptTag = '<script async src="' + SPYDER_SCRIPT_URL + '"><\/script>';
const rewriter = new HTMLRewriter()
.on('script[src]', {
element(el) {
const src = (el.getAttribute('src') || '').toLowerCase();
if (
src.includes('wfm.js')
|| src.includes('tracking.js')
|| src.includes('spyder.min.js')
|| src.includes('@spyderbot/spyder')
) {
alreadyTagged = true;
}
},
})
.on('head', {
element(el) {
el.onEndTag((endTag) => {
if (!alreadyTagged) {
endTag.before(preconnectTag + scriptTag, { html: true });
}
});
},
});
const transformed = rewriter.transform(response);
return withSessionHeaders(transformed, sid, true, allowSession, expireSession);
},
};
Cloudflare Worker — v1.0.0 (GitHub)
Public Worker repo with Deploy to Cloudflare. Paste your SpyderBot key as the TRACKING_KEY secret when prompted.
GitHub →WordPress plugin
Download SpyderBot Tracking v0.3.2. Install: Plugins → Add New → Upload Plugin → choose the zip → Activate → Settings → SpyderBot Tracking → paste your Tracking key → Test connection.
- Plugins → Add New → Upload Plugin
- Choose the zip and Activate
- Settings → SpyderBot Tracking → paste key → Test connection
Edge middleware — Next / Vercel / Netlify (coming soon)
Bot-only server-track at the edge with a shared _spyd_sid session cookie. Not publicly released yet — use the Cloudflare Worker or server snippets for now.
Learn more →GEO CLI — @spyderbot/geo (coming soon)
Audit robots.txt, llms.txt, and schema.org from the terminal. Package not published on npm yet.
Learn more →Google Tag Manager (docs only)
Use GTM to load the SpyderBot browser script. Docs-only guidance — no separate GTM gallery template.
Learn more →Server-side (PHP, Node.js, Python)
Use these when you need to record SEO and LLM crawlers that do not execute JavaScript. Run the call on every HTML request path you care about.
For accurate LLM referral counts, each visitor needs a unique session_id (see snippets) or add the browser script above.
Ready to add your website?
Sign in and open AI Traffic to generate your real tracking key and verify the connection.