Rankealo

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 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. 1

    Create the plugin file

    In wp-content/, create a folder named mu-plugins if it does not exist, and a file inside it named rankealo-bot-traffic.php.
  2. 2

    Paste the snippet

    Paste the snippet below and save. Must-use plugins load automatically; there is nothing to activate. The code contains no keys: it reads them from wp-config.php.
  3. 3

    Add your values to wp-config.php

    Above the line /* That's all, stop editing! */, add define('RANKEALO_BOT_TOKEN', '…'); and the same for RANKEALO_INGEST_URL, with the values from Agent Analytics Setup. Server environment variables with the same names work too.
  4. 4

    Check it is loaded

    In the WordPress admin, Plugins → Must-Use lists the file.
php
<?php
/**
 * Rankealo bot traffic. Add to wp-config.php (above "That's all, stop editing!"):
 *   define('RANKEALO_BOT_TOKEN', '...');
 *   define('RANKEALO_INGEST_URL', '...');
 * or set them as server environment variables. Missing values = tracking is off.
 */
add_action('template_redirect', function () {
  $env = function ($name) {
    return defined($name) ? (string) constant($name) : (string) getenv($name);
  };
  $token = $env('RANKEALO_BOT_TOKEN');
  $ingest_url = $env('RANKEALO_INGEST_URL');
  if ($token === '' || $ingest_url === '') return;
  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([
    'domain' => $host,
    'href' => 'https://' . $host . $path,
    'ai' => [
      'userAgent' => $ua,
      'ip' => $_SERVER['REMOTE_ADDR'] ?? null,
      'statusCode' => http_response_code(),
      'source' => 'server_middleware',
    ],
  ]);
  $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 => $payload,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT_MS => 800,
  ]);
  curl_exec($ch);
  curl_close($ch);
});

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: wp-config.php: add define('RANKEALO_BOT_TOKEN', '…'); (and RANKEALO_INGEST_URL) above "That's all, stop editing!", or set them as server environment variables.

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.

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_ADDR may 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#

  1. 1
    In Rankealo, open Traffic → Agent Analytics.
  2. 2
    Press Check now in step 3. Once a crawler has visited, it shows Receiving data with the time of the last hit.
  3. 3
    Open 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+
Crawler requests are probably served from cache. Test with curl -A "GPTBot/1.2" on a URL with a cache-busting path, or exclude crawler user agents from your page cache.
The plugin does not appear under Must-Use+
The file must be directly in wp-content/mu-plugins/ (not in a subfolder) and start with <?php.
Hits are skipped+
The host WordPress sees must match the website you set up in Rankealo. Staging domains are ignored on purpose.

Still stuck? Contact support

Reading is step one. Measuring your AI visibility is step two.

Rankealo tracks how often your brand is mentioned and cited across the major AI engines, then helps you publish the pages that close the gaps.