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

Reference

Configuration

This page covers every option for runlight() and routes(), including stores and sites.

ts

import { runlight } from "@runlight/sdk";

export const rl = runlight({ store, site, /* ...options */ });
export const routes = rl.routes({ /* ...route options */ });

This page uses the TypeScript library’s names. Every other language takes the same options, spelled the way that language spells names, as its page shows, from PHP to Rust.

Stores

Runlight keeps everything in a handful of tables prefixed rl_, created on first use and upgraded in place.

Every store takes a prefix option to use in place of rl_, such as wp_rl_, so two apps sharing one database each keep their own tables. The prefix can be up to 32 letters, digits, and underscores, and it cannot start with a digit. A store’s tables() lists its tables by name, which helps an app that removes Runlight.

SQLite

ts

import { sqlite } from "@runlight/sdk/sqlite";

sqlite({ path: "./data/runlight.db" });

SQLite needs better-sqlite3 and suits a single server, where the file can live beside your app’s own database. On a serverless host with no lasting disk, use Postgres.

A file Runlight makes is readable and writable by its owner and group only (0660), so a scheduled job running as another user of the same group can still use it.

Postgres

ts

import { postgres } from "@runlight/sdk/postgres";

postgres({ url: process.env.DATABASE_URL });

Postgres needs pg. Pass url, or pass pool to share a pool your app already has (Runlight never ends a pool it did not make). A pool needs at least 2 connections.

When Runlight makes the pool, max sets the number of connections and defaults to 10. A request waits at most 10 seconds for a free connection (a tracker hit tries twice more before it is let go), and statementTimeout stops any one query after that many milliseconds, 120000 by default (0 turns it off).

If several processes start at once, the tables are still created only once. A process waits at most 30 seconds for another process that is creating or upgrading the tables, after which a request answers 503 with the code tables_busy, and a tracker hit waits at most 10 seconds and is then dropped.

MySQL and MariaDB

ts

import { mysql } from "@runlight/sdk/mysql";

mysql({ url: process.env.DATABASE_URL });

This store needs mysql2 and works with MySQL 8.0.20 or later and MariaDB 11.4 or later. Pass a mysql:// or mariadb:// URL as url, or pass pool to share a pool from mysql2/promise your app already has (Runlight never ends a pool it did not make). A pool needs at least 2 connections.

When Runlight makes the pool, max sets the number of connections and defaults to 10. A request waits at most 10 seconds for a free connection (a tracker hit tries twice more before it is let go), and statementTimeout stops any one query after that many milliseconds, 120000 by default (0 turns it off). On MySQL that limit covers reads, and on MariaDB it covers every statement.

If several processes start at once, the tables are still created only once. A process waits at most 30 seconds for another process that is creating or upgrading the tables, after which a request answers 503 with the code tables_busy, and a tracker hit waits at most 10 seconds and is then dropped.

The tables use utf8mb4 with the utf8mb4_0900_bin collation. Text is compared and sorted by code point, with case and trailing spaces kept, so every report reads the same as it would on SQLite or Postgres.

libSQL and Turso

ts

import { libsql } from "@runlight/sdk/libsql";
import { createClient } from "@libsql/client"; // or "@libsql/client/web" on the edge

libsql({ client: createClient({ url: process.env.TURSO_URL, authToken: process.env.TURSO_TOKEN }) });

This store needs @libsql/client. Turso over HTTP works anywhere fetch does, including Vercel Edge and Deno Deploy, and a file: URL points to a local SQLite file.

Cloudflare D1

ts

import { d1 } from "@runlight/sdk/d1";

d1({ database: env.DB });

Pass the D1 binding from your Worker’s environment. D1 has no interactive transactions, and a Worker may send it only so many queries a request, so an import sends a step’s writes in batches, each one all or nothing. A link whose history fits one batch is written whole or not at all, and running the import again skips the links already written. A link with more than about 18,000 clicks recorded one by one, or an Umami day of more than about 18,000 events, needs the Workers Paid plan.

Bun

ts

import { bunSqlite } from "@runlight/sdk/bun";

bunSqlite({ path: "./data/runlight.db" });

This store uses Bun’s built-in SQLite, for apps on Bun, where better-sqlite3 does not load.

runlight() options

Option Default What it does
store (required) Where the numbers live, one of sqlite, postgres, mysql, libsql, d1, or bunSqlite.
site {} The site this install tracks.
sites Several sites in one install, each with its hostnames, used in place of site.
geo Your own location lookup, for hosts that send no location headers.
trustProxy unset Read the visitor’s address and the host’s location headers (Cloudflare, Netlify, Vercel) from the request. Unset, they count only on a connection from this computer or a private network, where proxies and load balancers connect from. When the mount passes no connection address, as a Next.js route handler, Hono, or Bun does, they count on a hosting platform Runlight knows and wherever NODE_ENV is not production, so behind your own proxy in production, set it as Behind a proxy describes. true believes them from anywhere, for a CDN that connects from public addresses, and false never does. Set "x-forwarded-for", "x-real-ip", or "cf-connecting-ip" to read the address from only that header.
linkPath "/go" Where short links on your app’s own domain live.
rateLimit 120 Tracker requests allowed from one address each minute, or false or 0 for no limit.
mail The mail service for email reports, set in code, or your app’s own mailer, which a service saved in the dashboard can replace.
mailServices every service The mail services Settings offers, by id, such as every one but smtp. Saving another is refused with the code mail_service, and a service saved earlier that is not listed is treated as no service, so the app’s own mailer sends.
managedSites false Keep sites in the database and manage them from the dashboard, as the standalone server does, in place of site and sites.
updateAgentRanges false Downloads the address lists AI companies publish, once a day during the scheduled check, to check AI agent fetches. Without it, the copy that came with the release is used.
localInstalls false Lets an install at http://localhost or http://127.0.0.1 be connected, for trying a hub and an app on one machine. Without it, connecting an install on a local address is refused with the code connect_url.
secret RUNLIGHT_SECRET, then RUNLIGHT_TOKEN Encrypts the keys stored in the database, for the mail service, the AI Assistant, and connected installs.

Sites

Field Default What it does
id "default" for the first site Stable id stored with every row, made of letters, digits, dots, dashes, and underscores.
name the first hostname, or "My site" when there is none Shown on the dashboard and editable in Settings.
hostnames [] (any) Which hostnames count toward this site, ignoring www.. With several sites, each site needs at least one.
timezone "UTC" IANA timezone for days, weeks, and the hours on the dashboard, such as "America/Toronto", and editable in Settings.

A visit from a hostname no site claims is ignored, so a staging copy of your site does not count unless you add its hostname.

Rate limit

Each process counts tracker requests per visitor address over one minute and drops the rest quietly, so a script cannot flood a site with made-up visits. A real visitor sends a few requests a minute, far below the default of 120.

The count lives in memory under a hashed address and is cleared every minute, so no address is ever kept. On hosts that run many short-lived copies of your app, such as Cloudflare Workers, each copy counts on its own, so the limit there is looser.

Location

Country, region, and city come from your host’s headers on Vercel, Cloudflare, and Netlify, with no setup, whenever Runlight believes the request’s forwarding headers: by default on a platform’s functions or behind a proxy on a private network, and with trustProxy set to true or a header’s name behind a CDN that connects from public addresses. Otherwise a visitor could write those headers, so Runlight ignores them and geo answers instead. Elsewhere, pass geo, a function that turns an IP address into a location. This example backs it with an MMDB file.

ts

runlight({
  store,
  geo: async (ip) => {
    const found = reader.get(ip); // your MMDB reader
    return found ? { country: found.country?.iso_code, city: found.city?.names?.en } : null;
  },
});

The address is dropped after the lookup, so only the place is kept.

routes() options

Option Default What it does
basePath "/runlight" Where the routes are mounted, with the script at {basePath}/s.js.
token RUNLIGHT_TOKEN Protects the dashboard and API. Send it as Authorization: Bearer <token>, or open the dashboard once with ?token= to get a cookie. null leaves everything open, for example behind your own auth.
accounts false Sign-in accounts for the dashboard, with invites by role. See Accounts below.
authorize Your own check, used in place of a token. Return true for full access, "member" for someone who can change everything apart from the mail service, the assistant’s settings, and deleting a site, "read" for someone who may only read, or false, from a function or a promise.
cronSecret CRON_SECRET A second secret the scheduled check accepts besides the token.
origin Your app’s public address, such as https://example.com. A link domain can never be this host, and links in email reports point to it, whatever Host header a request names. Without it, the request’s own host stands in, and a connected hub cannot add link domains or email reports.
ownHosts A function that returns more names your app answers on, such as ["app.example.com"], which can never become link domains either.
signIn Your own sign-in page. An app connecting over OAuth sends a signed-out owner there with ?next=, and the dashboard links to it when a session ends.
signOut A link to sign out, shown in the dashboard’s footer.
geoCredit false Credits DB-IP in the dashboard’s footer, as its free location data asks.
csrf A function that returns a token the dashboard sends back with every change, in an x-runlight-csrf header, and the OAuth consent form in a csrf field, for an authorize that checks where a change comes from, as a CMS checks its own forms. It is asked for each time the dashboard or the form is shown. The WordPress plugin gives a nonce.
cms The CMS that adds the script to every page, such as "WordPress", when Runlight runs inside one. The dashboard then opens on its numbers even before the first visit, Settings, Install says the CMS adds the script, and pages on the same origin, such as the CMS’s admin, may show the dashboard in a frame. The WordPress, Drupal, and Craft plugins set it.
observeKey RUNLIGHT_OBSERVE_KEY An install-wide key a WordPress, Drupal, or Craft site can use to report AI agent fetches to POST /api/observe for any site. Each site also has its own agents key, shown under Settings, Install, which reports only for that site and is the better choice.

The options accountOf, tokenMade, and tokensOf connect the routes to the standalone server’s own accounts and are internal to it.

With no token, the dashboard and API answer 503 until you set one, unless NODE_ENV is development. Collecting visits, the script, short links, share links, and unsubscribe links never need the token.

Accounts

Turn on accounts to let several people sign in to the dashboard, each with their own email, password, and role, the same way the standalone server does.

ts

export const { GET, POST, PUT, PATCH, DELETE } = rl.routes({ accounts: true });

The dashboard then asks everyone to sign in at /runlight/login. To create the first account, open /runlight/setup and enter your RUNLIGHT_TOKEN along with your email and password, so only whoever runs the app can. That account is the owner. The sign-in, setup, two-factor, reset, and invitation pages show in the browser’s language when the dashboard has it (English, French, Spanish, German, and Portuguese), and in English otherwise.

In development with no token, or with token: null, which leaves everything open, the first account needs no token, so make it before anyone else can reach the page.

The owner and admins invite people in Settings, Team Members. Invitations default to a member or viewer of the selected site. Invite to all sites is unchecked by default; check it for access to every site or an admin invitation. The invite goes out by email when a mail service is set up. Existing accounts keep their access. A site-only account cannot create API tokens, authorize OAuth apps, import data, or use installation-wide controls.

Everyone can turn on two-factor sign-in under Account. The token still works as a bearer token for scripts.

Sessions are signed with RUNLIGHT_SECRET, or the token when that is not set, so keep it the same across restarts and deploys. Passwords are hashed with scrypt where the runtime has it, as Node, Bun, and Deno do, and with PBKDF2 on edge runtimes such as Cloudflare Workers. New scrypt hashes use N=32768, r=8, and p=3, recorded in the hash, and a password stored at a lower cost is hashed again the next time it signs in.

If someone forgets their password, the owner or an admin can remove them and invite them again. If the owner forgets theirs, set a new password from a script that uses your Runlight instance.

ts

import { Accounts } from "@runlight/sdk";
import { rl } from "./lib/runlight";

const accounts = new Accounts(rl.store, process.env.RUNLIGHT_SECRET ?? process.env.RUNLIGHT_TOKEN!);
const user = await accounts.setPassword("you@example.com", "a new long password", Date.now());
await accounts.disableTwoFactor(user.id);

Environment variables

Variable Used for
RUNLIGHT_TOKEN The dashboard and API token.
RUNLIGHT_SECRET Encrypting stored keys for mail, the AI Assistant, and connected installs (falls back to the token).
CRON_SECRET Calling the scheduled check.
RUNLIGHT_OBSERVE_KEY CMS plugins reporting AI agent fetches.