A console for admins on their own site that shows the numbers and the events of the page in front of them. It ships as @spoar/debugtools and visitors never download it.
@spoar/debugtools opens a console over your live site. Only you see it. It answers questions about the page you are on and the browser you are using:
data-spoar-click and pins its click count to it.SQL is an opt-in tab through the tabs option, and the dashboard shows it. It is a separate package from @spoar/sdk, so the SDK's size budgets do not change.
This site runs the console. Signed in as an admin of this site's project, you see live data. Anyone else sees sample data.
Or press Ctrl Shift KOn a Next.js site that already uses @spoar/sdk, set debugConsole on <Analytics>. @spoar/sdk depends on @spoar/debugtools, so there is nothing else to install.
import { Analytics } from "@spoar/sdk/next";
<Analytics debugConsole />;Then turn on Debug console in the project's settings in the dashboard. Visitors get a keyboard listener and send no request. Press Ctrl+Shift+K (Cmd+Shift+K on a Mac) on the site: a popup on the API checks your session and hands the site a widget token, then closes. After that, the console opens on its own in that browser until the session ends. The popup works on any domain, because the session cookie is sent to the API's own page.
The console talks to the API behind an absolute endpoint, or to the hosted API when events go through the /_ra proxy. Pass debugConsole={{ api: "https://api.example.com" }} for a self-hosted API.
The console opens with a status line under its title bar: the project, whether the widget token is live and until when, and when each key was last used and from which origin. The key lines need a token that may read the project's settings; without one they are left out. Escape closes the console and puts focus back on the launcher.
If you press the shortcut and the browser blocks the popup, a notice asks you to allow pop-ups. When this browser opened the console before and the API now refuses it, such as when the project's Debug console switch is off, a notice shows the API's reason. A visitor who never opened the console sees nothing.
npm install @spoar/debugtoolsreact and react-dom 19 or later are peer dependencies of the React and Next entries.
The entries below call GET /v2/widget/session for an admin check on every page load. The check passes when all four hold:
debugConsole switch is on.Visitors without that session load nothing past the loader.
A passing check returns a widget token (wt_) for that one project. The console sends it with every query and fetches a new one a minute before it expires. Queries need the project's sqlEnabled switch on. Without it the console shows the 403.
import { mount } from "@spoar/debugtools";
mount(options: DebugtoolsOptions): () => voidStarts the console on any page, with no React on the host. The loader runs the admin check, then downloads the console chunk, which brings its own React. It returns a function that removes the console.
const unmount = mount({ endpoint: "https://api.example.com", project: "example.com" });import { Debugtools } from "@spoar/debugtools/react";A component that takes the same options as mount. It uses your app's React.
import { Debugtools } from "@spoar/debugtools/next";
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
{children}
<Debugtools endpoint="https://api.example.com" project="example.com" />
</body>
</html>
);
}For the App Router. It loads the console with next/dynamic and ssr: false.
import { Console } from "@spoar/debugtools/console";The console alone, with no loader and no admin check. Use it to embed the console in your own page. It needs one of the stylesheet entries below.
@spoar/debugtools/tailwind.css: the console's theme tokens and base styles, for an app that runs Tailwind v4.@spoar/debugtools/styles.css: the compiled stylesheet, for an app without Tailwind.import { consoleFixture } from "@spoar/debugtools/fixtures";Sample data for <Console /> and for the data option.
type DebugtoolsOptions = {
endpoint: string;
project: string;
auth?: "widget" | "session";
launcher?: "left" | "right";
fetch?: Fetcher;
data?: ConsoleData;
sections?: ConsoleSections;
theme?: "dark" | "light" | "system";
demo?: boolean;
open?: boolean;
tabs?: ("page" | "events" | "sql")[];
host?: ConsoleHost;
};endpoint is the API origin. project is the project id.
Default "widget". With "widget", the console runs the admin check and sends the widget token. With "session", it skips the check and sends the browser's session cookie. Use "session" on a page on the API's own domain, such as the dashboard.
Default "left". The corner the Console pill sits in, "left" or "right".
Replaces fetch for the admin check and the queries.
Shows this fixture data instead of the project's.
Turns parts of the console on or off: nav, toolbar, editor, results, library, recent and agent. Every section is on except agent.
mount({
endpoint: "https://api.example.com",
project: "example.com",
sections: { agent: true, library: false },
});Default "dark". Use "light", or "system" to follow the visitor's prefers-color-scheme.
Default false. When the admin check fails, shows the console on fixture data instead of nothing. Use it on a page that shows the console to everyone, such as these docs.
Default false. Opens the console as soon as it mounts, instead of showing the launcher.
Default ["page", "events"]. The tabs to show, always in the order This page, My events, SQL. Add "sql" for the SQL console; sections applies to it.
The page's @spoar/sdk client, created with createAnalytics. My events and Count my visits read it, so without it they explain that the page gave the console no client. <Analytics debugConsole /> passes its own client.
mount({ endpoint: "https://api.example.com", project: "example.com", host: analytics });A Console pill sits at the bottom left of the page. Click it, or press Ctrl+Shift+K (Cmd+Shift+K on a Mac), to open the console. Escape or the close button closes it.
The console opens as a panel docked to the bottom of the page. Drag its top edge to resize it. The title bar has three buttons:
The browser remembers the mode, height, position and size.
This page follows the page as you navigate. Type another path to look at it instead, and press Follow page to go back.
On the SQL tab, write SQL in the editor and press Run or Ctrl+Enter. :from and :to are bound to the time range in the toolbar, and :project to the project. The dataset library lists the views and columns you can query. A dataset's quick query fills the editor with its latest rows.
The console renders in a Shadow DOM root on a <spoar-debugtools> element, so your site's CSS and the console's never meet.
<Console /> uses plain Tailwind utilities and injects no CSS. In an app on Tailwind v4, import the tokens into your stylesheet:
@import "tailwindcss";
@import "@spoar/debugtools/tailwind.css";Without Tailwind, import the compiled stylesheet once:
import { Console } from "@spoar/debugtools/console";
import "@spoar/debugtools/styles.css";
<Console theme="system" />;