Any backend (HTTP API)
If your server can make an HTTP request, it can report crawler visits. POST one JSON event per crawler request, or batch up to 500, to the ingest endpoint.
Prerequisites#
- A server or edge function that sees each incoming request (URL, user agent, IP).
- Your site key and ingest URL from Rankealo → Traffic → Agent Analytics in the app (the key identifies your site, and you can regenerate it there). You set them as environment variables on your host (see Environment variables); the code only reads them, so it never contains a key. See the HTTP API reference for the full payload.
Steps#
- 1
Detect crawler requests
Check the user agent with a broad pattern like the ones below. You do not need an exact list: Rankealo classifies the user agent again and drops anything that is not a known crawler. - 2
Send the event without blocking
POST the event after the response is sent, or in the background. Never make the crawler wait for Rankealo. - 3
Keep the values in environment variables
Read the key and ingest URL fromRANKEALO_BOT_TOKENandRANKEALO_INGEST_URL. Never hard-code them or put them in browser code.
Environment variables#
The code reads two environment variables. If any is missing it does nothing, so your site keeps working while you set them up.
RANKEALO_BOT_TOKEN: Per-site ingest key for this website. Keep it secret.RANKEALO_INGEST_URL: The Rankealo ingest endpoint the code posts crawler hits to.
Where to set them: Your server's environment: host env settings, Docker / systemd environment, or a .env file your app loads.
The values are in Rankealo → Traffic → Agent Analytics, each with a copy button. Paste them into your host's settings yourself; never commit them to your repository.
curl#
Try the endpoint by hand: export the two variables in your shell, then run the command. A 200 with ingested: 1 means the key works.
# Reads RANKEALO_BOT_TOKEN and RANKEALO_INGEST_URL from your shell environment.
curl -X POST "$RANKEALO_INGEST_URL" \
-H "Authorization: Bearer $RANKEALO_BOT_TOKEN" \
-H "Content-Type: application/json" \
--data-binary @- <<EOF
{
"domain": "www.your-site.com",
"href": "https://www.your-site.com/pricing",
"ai": {
"userAgent": "Mozilla/5.0 (compatible; GPTBot/1.2; +https://openai.com/gptbot)",
"ip": "203.0.113.8",
"statusCode": 200
}
}
EOF
Node / Express#
// Express middleware: register before your routes.
// Reads RANKEALO_BOT_TOKEN and RANKEALO_INGEST_URL from the environment.
const CRAWLER_UA = /bot|crawler|spider|chatgpt|gptbot|claude|perplexity|bing|google|applebot|bytespider|ccbot/i;
app.use((req, res, next) => {
const token = process.env.RANKEALO_BOT_TOKEN;
const ingestUrl = process.env.RANKEALO_INGEST_URL;
const ua = req.get("user-agent") || "";
if (token && ingestUrl && (req.method === "GET" || req.method === "HEAD") && CRAWLER_UA.test(ua)) {
res.on("finish", () => {
// Fire and forget: never await this in the request path.
fetch(ingestUrl, {
method: "POST",
headers: {
"content-type": "application/json",
authorization: "Bearer " + token,
},
body: JSON.stringify({
domain: req.hostname,
href: req.protocol + "://" + req.get("host") + req.path,
ai: { userAgent: ua, ip: req.ip, statusCode: res.statusCode },
}),
}).catch(() => {});
});
}
next();
});
PHP#
<?php
// Call at the end of your front controller, after the response is sent.
// Reads RANKEALO_BOT_TOKEN and RANKEALO_INGEST_URL from the environment.
function rankealo_report_crawler(): void {
$token = (string) getenv('RANKEALO_BOT_TOKEN');
$ingest_url = (string) getenv('RANKEALO_INGEST_URL');
if ($token === '' || $ingest_url === '') return;
$ua = $_SERVER['HTTP_USER_AGENT'] ?? '';
if (!preg_match('/bot|crawler|spider|chatgpt|gptbot|claude|perplexity|bing|google/i', $ua)) return;
if (!in_array($_SERVER['REQUEST_METHOD'] ?? '', ['GET', 'HEAD'], true)) return;
if (function_exists('fastcgi_finish_request')) fastcgi_finish_request(); // respond first
$host = strtolower($_SERVER['HTTP_HOST'] ?? '');
$path = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?: '/';
$ch = curl_init($ingest_url);
if (!$ch) return;
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'Authorization: Bearer ' . $token],
CURLOPT_POSTFIELDS => json_encode([
'domain' => $host,
'href' => 'https://' . $host . $path,
'ai' => [
'userAgent' => $ua,
'ip' => $_SERVER['REMOTE_ADDR'] ?? null,
'statusCode' => http_response_code(),
],
]),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT_MS => 1500,
]);
curl_exec($ch);
curl_close($ch);
}
Batching
On busy sites, queue events and send them in batches of up to 500 with ahits array. The format is in the HTTP API reference.Limitations#
- Requests served by a cache or CDN in front of your server never reach your code, so they are not reported.
- Hits are marked as claimed identities unless you pass
ai.verifiedBot: truefrom a source you trust, such as your CDN's bot verification. - Up to 500 hits per request; larger batches are rejected with a 400.
Confirm data is flowing#
- 1In Rankealo, open Traffic → Agent Analytics.
- 2Press Check now in step 3. Once a crawler has visited, it shows Receiving data with the time of the last hit.
- 3Open the Bot traffic tab to see hits by crawler and by page.
The first hit depends on when a crawler next visits, which can take up to 24 hours. To test right away, request a page with a crawler user agent, for example curl -A "GPTBot/1.2" https://www.your-site.com/, then press Check now. A test like this is recorded as a claimed identity, like any hit without CDN verification.
Troubleshooting#
401 Unauthorized+
200 but ingested is 0 and skipped is 1+
503+
Still stuck? Contact support
