Platforms
Craft CMS
See who visits your Craft CMS site, where they come from, and when AI agents read it.
The Runlight plugin runs Runlight inside a Craft 5.3 or later 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 the Craft Plugin Store.
What it does
- It adds Runlight’s script to every front-end page. On a page Craft 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 Control Panel users’ own visits unless you turn that off. The pages they see without the script are never cached, so everyone else still gets it.
- It reports AI agents such as ChatGPT and Claude when they fetch your pages, after the connection has closed, so the agent never waits on the report. Runlight checks the agent’s IP address against its published list and then drops it.
- It adds a Runlight item to the Control Panel that shows this site’s dashboard there, in the language the person reads the Control Panel in.
Set it up
Install the plugin by running composer require runlight/craft and then php craft plugin/install runlight, or install it from the Plugin Store in the Control Panel. The plugin’s settings open on a setup screen, and nothing is counted until you choose where Runlight runs. Press Run Runlight in this Craft site and it starts counting the site.
The Runlight item in the Control Panel 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.
Admins, and people with the Manage Runlight permission, are owners of this Runlight. People with the See Runlight’s numbers permission see the same dashboard without changing anything. Both are under Users, Permissions, Runlight, and everyone else is asked to sign in to Craft.
Changes are taken only from your site’s own pages, so another site cannot make them with an owner’s session.
Running Runlight inside Craft 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 Craft’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 and every server of a site sees the same ones. Its tables are named after Craft’s table prefix, such as craft_rl_events, and Runlight marks them as this install’s.
If tables with those names are already there and are not this install’s own Runlight tables, such as a standalone Runlight’s in the same database, it leaves them alone and uses a SQLite file. With any other database, the numbers go in a SQLite file in storage/runlight, which the web never serves, and which needs PHP’s pdo_sqlite. A SQLite file belongs to one server, so on several servers, or a host that replaces storage on each deploy, use a database Runlight can keep its numbers in.
Nothing records the choice beside the numbers. Runlight’s tables in Craft’s database mean Craft’s database, and a SQLite file means SQLite, so the choice holds on every server and through every deploy.
The secret Runlight signs sessions with, and seals the keys you save in its dashboard with, comes from Craft’s securityKey, so it is the same everywhere too. Changing securityKey signs everyone out of Runlight, and keys saved in its dashboard, such as a mail service’s, have to be entered again.
Uninstalling the plugin removes Runlight’s tables, each by name and only this install’s, even when storage/runlight is gone, and its folder.
Locations and upkeep
Visitors’ countries come from Cloudflare’s header when the request verifiably came through Cloudflare’s own addresses. Otherwise, turn on Locations in the plugin’s settings, and the upkeep downloads DB-IP’s free country database once a month into storage/runlight on each server. 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 Craft’s log has a warning that says why.
The upkeep also runs Runlight’s scheduled check, which makes each day’s salt, sends email reports, and deletes visits past the retention you set. A visit to the site queues it at most once an hour, and only while no earlier one is waiting.
Craft’s queue only runs while someone uses the Control Panel unless a queue runner is set up, so add php craft runlight/check to your server’s cron, hourly. When the upkeep 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 Craft works out for each request, which follows Craft’s trustedHosts and ipHeaders settings.
Craft trusts proxy headers from any host until you name the ones in front of your site, so set trustedHosts in config/general.php, or CRAFT_TRUSTED_HOSTS, to your load balancer’s or CDN’s addresses, and no visitor can choose an address with a header.
The counts per address, and the daily key they are hashed with, go in Craft’s cache, in two entries that are replaced every minute and every day.
Counting
In the plugin’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
- Install the plugin as above.
- On the setup screen, under Connect to a Runlight you run elsewhere, enter the address your Runlight answers at, such as
https://stats.example.comfor the standalone server orhttps://example.com/runlightfor an app with Runlight mounted. Runlight shows it under Settings, Install, as Runlight address. - Press Connect. Your Runlight asks you to sign in if you have not, and then asks you to allow the connection for this domain’s site. If Runlight has no site for it yet, it offers to add one.
- Press Allow. Runlight sends you back to Craft with every setting filled in, and the Runlight item in the Control Panel shows this site’s numbers.
Connecting gives the plugin 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 Control Panel, 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 Craft.
You can also revoke this site’s dashboard keys in Settings, Install, under Dashboard key.
Connect needs the Control Panel 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.
Connecting writes the keys into Craft’s .env file, as RUNLIGHT_AGENTS_KEY and RUNLIGHT_DASHBOARD_KEY, and saves the settings as $RUNLIGHT_AGENTS_KEY and $RUNLIGHT_DASHBOARD_KEY, so project config names the variables and holds no key. Each environment then sets its own.
When .env cannot be written, Connect saves the keys in the settings themselves and says how to move them.
Enter the settings by hand
Each setting in the plugin 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, or into .env as above. 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. Once the page has loaded, the plugin checks that the address answers.
Every setting may name an environment variable, such as $RUNLIGHT_URL.
If you change the address, the keys you saved for the old one are cleared, so a key is never sent to a different Runlight. Enter them again for the new address, or press Connect. As with any Craft plugin, every setting can also come from config/runlight.php, and values there override the Control Panel.
php
<?php
return [
'address' => 'https://stats.example.com',
'observeKey' => '$RUNLIGHT_AGENTS_KEY',
'dashboardKey' => '$RUNLIGHT_DASHBOARD_KEY',
];Email reports
With Runlight running inside Craft, its email reports and test emails go through Craft’s own mailer when Settings, Email uses a transport other than Sendmail, such as SMTP or a mail service’s plugin. They come from Craft’s system email address and sender name, and Settings, Email service in the dashboard says which transport sends them.
With Sendmail, the dashboard asks you to set up a mail service there instead. You can also choose another service while Craft’s mailer is set up, and go back to Craft’s mailer later from the same place.
The dashboard in the Control Panel
With Runlight inside Craft, the Runlight item shows the whole dashboard in the Control Panel, 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, so when the Control Panel is served from a different address, set with baseCpUrl, the item opens the dashboard in a new tab instead.
With a Runlight elsewhere and a dashboard key, the Runlight item shows this site’s dashboard in the Control Panel, 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 Control Panel 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. Once saved, a key typed in literally shows as an empty field in the settings form, and leaving the field empty keeps it. An environment variable is still better, since it keeps the key out of project config.
Each time an admin opens the page, the plugin’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 can access the Runlight plugin, admins included, see the page. Your Runlight must be served over HTTPS when the Control Panel is, or the browser refuses the frame.
Static caching
Static caches such as Blitz serve pages without running Craft, or stop Craft before the page is sent. Those pages still include the script, so visits are counted.
A page a Control Panel user sees without the script is never cached: the plugin tells Blitz not to cache it and sends headers that keep other caches from storing it. AI agent fetches of the cached pages are not reported, because the plugin never gets the chance to see them.