WordPress
A must-use plugin reports crawler visits from inside WordPress. It is the quickest setup on self-hosted WordPress, with one important limit: it only sees requests that reach PHP.
Limited features: cache misses only
WordPress only runs PHP when a page is not served from a cache. Page-cache plugins (WP Rocket, W3 Total Cache, LiteSpeed), host caches, and CDNs answer most requests before WordPress runs, so those crawler visits are never reported. On a typical cached site that is 60–95% of hits. If your site is behind Cloudflare, use the Cloudflare Worker instead: it sees every request.Prerequisites#
- Self-hosted WordPress with file access (SFTP, SSH, or your host's file manager).
- PHP with the cURL extension (enabled on almost every host).
- Your site token and website id from Bot traffic → Agent Analytics Setup in the app. The snippet there already has both filled in; the examples on this page use
YOUR_SITE_TOKENandYOUR_WEBSITE_ID. See the HTTP API reference for the full payload.
Steps#
- 1
Create the plugin file
Inwp-content/, create a folder namedmu-pluginsif it does not exist, and a file inside it namedrankealo-bot-traffic.php. - 2
Paste the snippet
Paste the snippet from Agent Analytics Setup (or the one below with your values) and save. Must-use plugins load automatically; there is nothing to activate. - 3
Check it is loaded
In the WordPress admin, Plugins → Must-Use lists the file.
<?php
add_action('template_redirect', function () {
if (!in_array($_SERVER['REQUEST_METHOD'] ?? '', ['GET', 'HEAD'], true)) return;
$ua = $_SERVER['HTTP_USER_AGENT'] ?? '';
if (!preg_match('/bot|crawler|spider|chatgpt|gptbot|claude|perplexity|bing|google/i', $ua)) return;
$host = preg_replace('/:\d+$/', '', strtolower($_SERVER['HTTP_HOST'] ?? ''));
$path = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?: '/';
$payload = json_encode([
'websiteId' => 'YOUR_WEBSITE_ID',
'domain' => $host,
'href' => 'https://' . $host . $path,
'ai' => [
'userAgent' => $ua,
'ip' => $_SERVER['REMOTE_ADDR'] ?? null,
'statusCode' => http_response_code(),
'source' => 'server_middleware',
],
]);
$ch = curl_init('https://app.rankealo.ai/api/ai-visibility/crawler-hits/ingest');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'Authorization: Bearer YOUR_SITE_TOKEN'],
CURLOPT_POSTFIELDS => $payload,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT_MS => 800,
]);
curl_exec($ch);
curl_close($ch);
});
What is sent#
- URLHost and path. The query string is never sent.
- User agentUsed to identify the crawler.
- IPREMOTE_ADDR; hashed on arrival, never stored raw.
- Status codeThe response code WordPress is about to send.
Limitations#
- Cache hits are invisible (see above).
- The report is a blocking cURL call with an 800 ms timeout, and it only runs for crawler requests. Human visitors are never slowed down.
- Behind a reverse proxy,
REMOTE_ADDRmay be the proxy's IP rather than the crawler's. - WordPress.com sites cannot add mu-plugins. Use the Cloudflare Worker if the domain is on Cloudflare.
Confirm data is flowing#
- 1In Rankealo, open Bot traffic → Agent Analytics Setup.
- 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#
Check now says No data received+
The plugin does not appear under Must-Use+
Hits are skipped+
Still stuck? Contact support
