All docs

Start

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

Features

  1. 04The dashboard
  2. 05Campaigns
  3. 06Goals & Conversions
  4. 07Funnels
  5. 08Short links
  6. 09Custom domains
  7. 10Importing history
  8. 11AI sources and agents
  9. 12Email reports
  10. 13Scheduled check
  11. 14Ask your AI
  12. 15Runlight for Mac

Reference

  1. 16Performance
  2. 17Configuration
  3. 18HTTP API

Platforms

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

Trust

  1. 34Privacy

Start

Install

Mount Runlight in Next.js, Nuxt, SvelteKit, Astro, Remix, Express, NestJS, Fastify, Koa, Hono, Bun, Deno, or Cloudflare Workers, find the guide for your language, or install the WordPress, Drupal, or Craft CMS plugin.

Every install needs an instance (see Getting started), its routes mounted under /runlight, and the script tag on your pages. Only the routes change between frameworks.

rl.routes() returns a Fetch handler, handler(request), plus the same function under each method name, so any framework built on web Request and Response can use it directly. Change the path with rl.routes({ basePath: "/stats" }), and the script tag becomes /stats/s.js.

WordPress, Drupal, and Craft CMS

A site built on one of these needs no code at all. Install Runlight’s plugin, and it runs Runlight inside the site, with the dashboard at /runlight and the numbers in the site’s own database.

Platform Install Then
WordPress wp plugin install runlight --activate Press Run Runlight in this WordPress on its setup screen.
Drupal composer require drupal/runlight and drush pm:install runlight Press Run Runlight in this Drupal site under Configuration, System, Runlight.
Craft CMS composer require runlight/craft and php craft plugin/install runlight Press Run Runlight in this Craft site in the plugin’s settings.

Each plugin can also send its visits to a Runlight you run elsewhere, so one dashboard covers many sites.

Other languages

Runlight comes in each of these languages, with the same dashboard and the same tables. Each page has the install, the routes for its frameworks, the scheduled check, and what differs from the TypeScript library.

Language Install Runs in
PHP composer require runlight/runlight Laravel, Symfony, plain PHP, and a drop-in for a domain of its own
Python pip install runlight Django, Flask, FastAPI, and any WSGI or ASGI app
Rails bundle add runlight Rails 8.0 and 8.1, through an engine and a generator
Ruby bundle add runlight sqlite3 Sinatra, Hanami, Roda, and any other Rack app
Go go get runlight.sh/go net/http, chi, Echo, and any router that takes an http.Handler
Java sh.runlight:runlight from Maven Central The JDK’s own server, servlet containers, and Spring Boot
.NET dotnet add package Runlight.AspNetCore ASP.NET Core and any other .NET app
Elixir {:runlight, "~> 0.6"} in mix.exs Phoenix and any Plug app
Rust cargo add runlight runlight-sqlx axum, hyper, and any server that takes a tower service

Every language except Elixir and Rust also has a standalone server of its own, and the standalone server page covers the Node one.

Next.js

In the App Router, add a catch-all route.

app/runlight/[[...path]]/route.ts

import { rl } from "@/lib/runlight";

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

Add the script to your root layout.

app/layout.tsx

<head>
  <script defer src="/runlight/s.js"></script>
</head>

With SQLite, Postgres, or MySQL, Runlight needs the Node runtime, which is the default for route handlers. On the Edge runtime, use Turso over HTTP.

Express and plain Node

@runlight/sdk/node adapts the handler to Node’s http module, and so to Express, Connect, and Koa (through ctx.req and ctx.res).

server.ts

import express from "express";
import { toNodeHandler, observer, shortLinks } from "@runlight/sdk/node";
import { rl } from "./runlight.js";

const app = express();
app.use(shortLinks(rl)); // short links at /go and on custom domains
app.use(observer(rl)); // AI agents reading your pages; optional
app.use(toNodeHandler(rl.routes().handler));

The adapter can go before or after any body parser, because it also reads a body that Express has already parsed, and it leaves the bodies of your app’s own requests unread. It reads at most 16 KB for a tracker hit and 10 MB for anything else, and answers a larger body with 413. shortLinks goes before your own routes, so a link domain reaches Runlight first.

NestJS

Nest runs on Express by default, so the same middleware goes in main.ts, before listen.

src/main.ts

import { NestFactory } from "@nestjs/core";
import { toNodeHandler } from "@runlight/sdk/node";
import { AppModule } from "./app.module";
import { rl } from "./runlight";

const app = await NestFactory.create(AppModule);
app.use(toNodeHandler(rl.routes().handler));
await app.listen(3000);

Add app.use(shortLinks(rl)) before it for short links.

Fastify

Fastify reads request bodies itself, so give Runlight its own plugin scope with no body parsers, and hand it the raw request.

ts

import Fastify from "fastify";
import { toNodeHandler } from "@runlight/sdk/node";
import { rl } from "./runlight.js";

const app = Fastify();
const runlight = toNodeHandler(rl.routes().handler);

app.register(async (scope) => {
  scope.removeAllContentTypeParsers();
  scope.addContentTypeParser("*", (_req, _payload, done) => done(null));
  scope.all("/runlight", (req, reply) => { reply.hijack(); return runlight(req.raw, reply.raw); });
  scope.all("/runlight/*", (req, reply) => { reply.hijack(); return runlight(req.raw, reply.raw); });
});

Short links go in an onRequest hook, as Short links shows.

Koa

ts

import Koa from "koa";
import { toNodeHandler } from "@runlight/sdk/node";
import { rl } from "./runlight.js";

const app = new Koa();
const runlight = toNodeHandler(rl.routes().handler);

app.use(async (ctx, next) => {
  if (ctx.path !== "/runlight" && !ctx.path.startsWith("/runlight/")) return next();
  ctx.respond = false;
  await runlight(ctx.req, ctx.res);
});

For short links, add the middleware under Short links before this one.

Hono

ts

import { Hono } from "hono";
import { rl } from "./runlight";

const app = new Hono();
const runlight = rl.routes().handler;
app.all("/runlight/*", (c) => runlight(c.req.raw));
app.all("/runlight", (c) => runlight(c.req.raw));

Nuxt and Nitro

Put the instance in server/utils/runlight.ts (Nitro imports everything there for you), then add this route.

server/routes/runlight/[...path].ts

export default defineEventHandler((event) => rl.routes().handler(toWebRequest(event)));

Add the same file as server/routes/runlight.ts so /runlight itself answers too. The script tag goes in app.head in nuxt.config.ts.

nuxt.config.ts

export default defineNuxtConfig({
  app: { head: { script: [{ src: "/runlight/s.js", defer: true }] } },
});

SvelteKit

src/routes/runlight/[...path]/+server.ts

import { rl } from "$lib/runlight";

const { handler } = rl.routes();
export const GET = ({ request }) => handler(request);
export const POST = GET;
export const PUT = GET;
export const PATCH = GET;
export const DELETE = GET;
export const OPTIONS = GET;

Astro

Astro needs an adapter for server output.

src/pages/runlight/[...path].ts

import { rl } from "../../lib/runlight";

export const prerender = false;
export const ALL = ({ request }) => rl.routes().handler(request);

Remix and React Router

app/routes/runlight.$.ts

import { rl } from "~/runlight.server";

const { handler } = rl.routes();
export const loader = ({ request }) => handler(request);
export const action = ({ request }) => handler(request);

Bun

Bun cannot load better-sqlite3, so use its built-in SQLite through @runlight/sdk/bun.

server.ts

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

const rl = runlight({ store: bunSqlite({ path: "./data/runlight.db" }), site: { hostnames: ["example.com"] } });
const runlightRoutes = rl.routes().handler;

Bun.serve({
  port: 3000,
  fetch(request) {
    const { pathname } = new URL(request.url);
    if (pathname === "/runlight" || pathname.startsWith("/runlight/")) return runlightRoutes(request);
    return new Response("Your app");
  },
});

Elysia and other Bun frameworks pass request the same way.

Deno

Deno serves web Requests directly. Use libSQL (a local file or Turso) or Postgres for the store.

main.ts

import { runlight } from "npm:@runlight/sdk";
import { libsql } from "npm:@runlight/sdk/libsql";
import { createClient } from "npm:@libsql/client";

const rl = runlight({ store: libsql({ client: createClient({ url: "file:runlight.db" }) }), site: { hostnames: ["example.com"] } });
const runlightRoutes = rl.routes().handler;

Deno.serve((request) => {
  const { pathname } = new URL(request.url);
  if (pathname === "/runlight" || pathname.startsWith("/runlight/")) return runlightRoutes(request);
  return new Response("Your app");
});

Cloudflare Workers

Workers have no disk, so store the data in D1. Location comes from Cloudflare’s own headers with no setup. A Worker passes no connection address, so Runlight believes them with trustProxy left unset.

src/index.ts

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

let routes: ReturnType<ReturnType<typeof runlight>["routes"]> | undefined;

export default {
  fetch(request: Request, env: { DB: D1Database; RUNLIGHT_TOKEN: string }) {
    // Made once per Worker instance, so the tables are checked when the instance starts.
    routes ??= runlight({ store: d1({ database: env.DB }), site: { hostnames: ["example.com"] } }).routes({ token: env.RUNLIGHT_TOKEN });
    return routes.handler(request);
  },
};

A Worker keeps its secrets in env, which Runlight cannot read by itself, so pass the token to routes() as above. Set it with wrangler secret put RUNLIGHT_TOKEN.

Route only /runlight/* to this Worker (or check the path first, as in the Bun example), and schedule the hourly check with a Cron Trigger that calls rl.check().

Anything else

If your server gives you a web Request, pass it to rl.routes().handler and return the Response. If it gives you Node’s req and res, use toNodeHandler from @runlight/sdk/node.

Behind a proxy

Runlight reads the visitor’s address from the last entry in X-Forwarded-For, the one your proxy adds, then from X-Real-IP or CF-Connecting-IP. By default it believes those headers only on a connection from this computer or a private network, where proxies and load balancers connect from. A client that reaches your app straight from the internet cannot choose its own address, so an app with no proxy in front needs no setting.

A Next.js route handler, Hono, Bun, and the other mounts that hand Runlight only the Request pass no connection address. There Runlight believes the headers on a hosting platform it knows (Vercel, Netlify, Cloudflare, AWS Lambda, Cloud Run, Azure, Fly, Render, Railway, Deno Deploy, or Heroku), and anywhere NODE_ENV is not production. In production anywhere else, such as next start behind your own nginx or Caddy, set trustProxy: true or the name of the header your proxy sets, or pass the connection’s address as handler(request, { ip }). Until you do, Runlight warns once and every visitor with the same browser counts as one. The Node adapter and the standalone server pass the connection’s address, so they need none of this.

When a CDN or proxy connects to your app from public addresses, such as Cloudflare in front of your server with nothing between, set trustProxy: "cf-connecting-ip" or trustProxy: true, or every visitor shows the proxy’s address. Runlight warns once when it sees forwarding headers it did not believe.

When a request passes through two proxies, such as Cloudflare in front of nginx, name the header that holds the visitor’s own address, like trustProxy: "cf-connecting-ip". The address is used for the daily visitor hash and the location lookup, and the rate limit uses a hash of it. It is never stored.

trustProxy: false never believes the headers. Runlight then also ignores the host’s location headers, so use geo for the country.