All docsSearch docs

Start

  1. 01Getting started
  2. 02Install
  3. 03Tracking

Features

  1. 04The dashboard
  2. 05Goals
  3. 06Short links
  4. 07AI sources and agents
  5. 08Email reports
  6. 09Scheduled check
  7. 10Ask your AI

Reference

  1. 11Performance
  2. 12Configuration
  3. 13HTTP API

Platforms

  1. 14Standalone server
  2. 15ClickHouse
  3. 16PHP
  4. 17WordPress
  5. 18Drupal
  6. 19Craft CMS
  7. 20Webflow
  8. 21Python
  9. 22Rails
  10. 23Ruby
  11. 24Go
  12. 25Java
  13. 26.NET
  14. 27Elixir
  15. 28Rust

Trust

  1. 29Privacy

Platforms

Drupal

See who visits your Drupal site, where they come from, and when AI agents read it.

The Runlight module runs Runlight inside a Drupal 10.3, 11, or 12 site, with the dashboard at /runlight on the site and the numbers in its own database. It can also send to a Runlight you run elsewhere, either the standalone server or an app with Runlight mounted, so one dashboard covers many sites. It’s on drupal.org.

What it does

  • It adds Runlight’s script to every page outside the admin theme. On a page Drupal answers with a 404, the script also records an event named 404 with the missing page’s path, so the properties of 404 in the Events box list the broken addresses people reached and how often.
  • It leaves out the visits of people who can administer Runlight unless you turn that off.
  • It reports AI agents such as ChatGPT and Claude when they fetch your pages, including pages that Drupal’s page cache answers. The report goes out after the response has been sent, so the page is never slowed down. Runlight checks the agent’s IP address against its published list and then drops it.
  • It adds a Runlight item under Reports that shows this site’s dashboard in the admin. The dashboard starts in Drupal’s language, the one the Reports page is in or the one in its address, so /fr/runlight/ opens in French, until someone picks another in the dashboard.
  • It works with the Redirect module’s Enforce clean and canonical URLs option, so you can keep that on, and on sites with a language in the path. After updating the module, run drush updb or drush cr so Drupal picks up its new service.

Set it up

Install the module with composer require drupal/runlight and enable it with drush pm:install runlight, or under Extend. Its settings, under Configuration, System, Runlight, open on a setup screen, and nothing is counted until you choose where Runlight runs. Press Run Runlight in this Drupal site and it starts counting the site.

Reports, Runlight shows the numbers, and its Open in Runlight button opens the full dashboard at /runlight on your site. There you can add goals, funnels, short links, and email reports.

Anyone with the Administer Runlight permission is an owner of this Runlight. Anyone with the View Runlight permission sees the same dashboard without changing anything, and everyone else is asked to sign in to Drupal.

Changes are taken only from your site’s own pages, so another site cannot make them with an owner’s session.

Running Runlight inside Drupal needs PHP 8.2 or later with the pdo, mbstring, and openssl extensions. The setup screen says when something is missing.

Where the numbers are kept

When Drupal’s database is Postgres, MySQL 8.0.20 or later, or MariaDB 11.4 or later, Runlight keeps its numbers there, so your database backups include them. Its tables are named after Drupal’s table prefix, such as rl_events, or d_rl_events with a prefix of d_, and Runlight marks them as this site’s.

If tables with those names are already there and are not this site’s own Runlight tables, such as a standalone Runlight’s in the same database, it leaves them alone and uses a SQLite file. It connects with its own connection, opened by Drupal’s database driver from the same settings as Drupal’s, so TLS options under pdo and any init_commands apply to it too.

With any other database, the numbers go in a SQLite file in a runlight folder under Drupal’s private files, which needs PHP’s pdo_sqlite and a private files folder, set with $settings['file_private_path'] in settings.php. Runlight never keeps anything under public files.

The choice is made the first time Runlight runs and never changes, so the numbers never split across two places.

Uninstalling the module removes Runlight’s tables, each by name and only this site’s, or its folder, along with what it kept in state and in Drupal’s cache.

Locations and upkeep

Runlight uses Cloudflare’s location header when the request came through Cloudflare’s own addresses or a reverse proxy Drupal trusts. Otherwise, visitors’ countries come from a database: turn on Show which countries visitors come from in the module’s settings, and Drupal’s cron downloads DB-IP’s free country database once a month into Runlight’s folder in private files, or else into Drupal’s temporary folder. Each download is checked against the SHA-1 checksum DB-IP publishes on db-ip.com, and is used only when it is a DB-IP country database no older than the one in use. Otherwise the one in use stays, and Drupal’s log has a warning that says why.

Drupal’s cron also runs Runlight’s scheduled check, which makes each day’s salt, sends email reports, and deletes visits past the retention you set, so keep cron running, as most Drupal sites already do. When the check has not run for over a day, the settings page says so.

Visitors’ addresses

Runlight counts visitors with a daily hash of their address, and limits how often one address can send. It takes the address Drupal works out for each request, which is the connection’s own address unless settings.php names the proxies in front of the site, so no visitor can choose one with a header. When that address is one of Cloudflare’s, it takes the visitor’s address from Cloudflare’s CF-Connecting-IP header, so a site behind Cloudflare needs nothing set.

Behind a load balancer, a CDN, or a host’s proxy, tell Drupal about them, as you would for any other module. The module’s settings page warns when a proxy on this machine or a private network passes requests on and settings.php does not name it.

php

$settings['reverse_proxy'] = TRUE;
$settings['reverse_proxy_addresses'] = ['10.0.0.2'];

The counts per address, and the daily key they are hashed with, go in Drupal’s cache, in two entries that are replaced every minute and every day.

Counting

In the module’s settings, Count clicks on links to other sites records each click on a link to another site as an event named Outbound link, and Count file downloads records each click on a link to a file, such as a PDF or a zip, as an event named File download. Both are on until you turn them off.

Connect to a Runlight you run elsewhere

  1. Install and enable the module as above.
  2. On the setup screen, under Connect to a Runlight you run elsewhere, enter the address your Runlight answers at, such as https://stats.example.com for the standalone server or https://example.com/runlight for an app with Runlight mounted. Runlight shows it under Settings, Install, as Runlight address.
  3. Press Connect. Your Runlight asks you to sign in if you have not, and then asks you to allow the connection for the site that counts this domain. If no site counts it yet, it offers to add one.
  4. Press Allow. Runlight sends you back to Drupal with every setting filled in, and Reports, Runlight shows this site’s numbers.

Connecting gives the module two keys. The agents key reports AI agents reading your pages, and it can only report fetches for this one site, so it cannot read your stats or write into another site. The dashboard key shows this site’s dashboard in the admin, read only, so treat it as you would a password.

The dashboard key appears in Runlight under Settings, MCP & API, where deleting it stops the dashboard in Drupal.

You can also revoke this site’s dashboard keys in Settings, Install, under Dashboard key.

Connect needs the admin on HTTPS, or on localhost while you try things out, since Runlight only sends people back to such addresses. In an app with Runlight mounted, the site has to be in hostnames already (see Configuration), because there the sites are set in code.

Enter the settings by hand

Each setting in the module has the same name in Runlight, under Settings, Install, in the WordPress, Drupal, and Craft section, with a button to copy it. Copy Runlight address, Agents key, and Dashboard key into the fields of the same names and save. Runlight shows the dashboard key only once, so make a new one if you lose it.

Site id is needed only when that Runlight cannot tell this site by its domain. When you save, the page checks that the address answers.

Keys and environments

Where Runlight runs, its address, the site id, and both keys belong to one environment, so the module keeps them in Drupal’s state, which drush config:export leaves out. They never reach your repository, and importing configuration never points one environment at another’s Runlight.

What it counts, such as outbound links and downloads, stays in configuration and is exported as usual. Values that an earlier version of the module saved in configuration are still used until you next save the settings, which moves them to state.

To set any of them in code, put them in settings.php, which wins over the settings page.

php

$config['runlight.settings']['address'] = 'https://stats.example.com';
$config['runlight.settings']['observe_key'] = getenv('RUNLIGHT_AGENTS_KEY');
$config['runlight.settings']['dashboard_key'] = getenv('RUNLIGHT_DASHBOARD_KEY');

Email reports

With Runlight running inside Drupal, its email reports and test emails go through Drupal’s own mailer when the site has one set up beyond PHP’s mail(), such as the SMTP module, Symfony Mailer, or core’s mailer with an SMTP address. They come from the site’s email address, in the site’s name, and Settings, Email service in the dashboard says which mailer sends them. Without one, the dashboard asks you to set up a mail service there instead.

You can also choose another service while Drupal’s mailer is set up, and go back to Drupal’s mailer later from the same place. After updating the module, rebuild Drupal’s caches (drush cr) so it finds the hook that builds these emails.

The dashboard in the admin

With Runlight inside Drupal, Reports, Runlight shows the whole dashboard, the same one as at /runlight, with its settings, goals, and short links. Only pages on your own site may show it in a frame.

With a Runlight elsewhere and a dashboard key, the Reports, Runlight page shows this site’s dashboard in the same read-only view a share link shows, with its reports and date ranges and none of Runlight’s settings, short links, people, or other sites. The Open in Runlight button opens the full dashboard in your own Runlight.

The address the admin is served from must be among the site’s domains in Runlight, since only an admin page on one of them may show the dashboard. Connecting takes care of that. A leading www. makes no difference.

The dashboard key never reaches the browser. Each time an admin opens the page, the module’s server sends the key and the admin’s origin to Runlight and gets back a ticket that opens the dashboard once, within five minutes.

The page loads the dashboard from your Runlight in a frame that only this admin may show. The frame keeps its session in the page for an hour, without cookies, so browsers that block cookies in frames still show it. Once the hour is up, the frame says so and reloads the page when asked.

Deleting the key in Runlight’s Settings, MCP & API stops it and every open session at once. Only people who have the Administer Runlight or View Runlight permission see the page. Your Runlight must be served over HTTPS when the admin is, or the browser refuses the frame.

When Gin is the admin theme, the frame follows its dark mode setting. With Claro it stays light.