Add-on Packages
react-clickmap ships first-party add-on packages for common integrations. The core library stays lightweight — install only what you need.
react-clickmap ships first-party add-on packages for common integrations. The core library stays lightweight — install only what you need.
`@react-clickmap/next`
Next.js App Router integration.
Shell
npm install @react-clickmap/nextWhat it provides
| Export | Description |
|---|---|
createNextFetchAdapter() | Client-side adapter with Next.js defaults (/api/clickmap endpoint) |
createClickmapRouteHandlers() | Pre-built GET/POST/DELETE/OPTIONS route handlers for your API route |
useNextRouteKey() | Hook that tracks the current route via history.pushState patching |
Quick setup
TypeScript
// app/api/clickmap/route.ts
import { createClickmapRouteHandlers } from "@react-clickmap/next";
import { createPostgresAdapter } from "@react-clickmap/postgres";
import { Pool } from "pg";
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
export const { GET, POST, DELETE, OPTIONS } = createClickmapRouteHandlers(
createPostgresAdapter({ sql: pool })
);TSX
// app/providers.tsx
"use client";
import { ClickmapProvider } from "react-clickmap";
import { createNextFetchAdapter } from "@react-clickmap/next";
const adapter = createNextFetchAdapter();
export function Providers({ children }: { children: React.ReactNode }) {
return (
<ClickmapProvider adapter={adapter} projectId="my-app" capture={["click", "scroll"]}>
{children}
</ClickmapProvider>
);
}See the full Next.js App Router guide for detailed setup instructions.
`@react-clickmap/postgres`
Direct Postgres persistence with parameterized queries.
Shell
npm install @react-clickmap/postgresWhat it provides
| Export | Description |
|---|---|
createPostgresAdapter() | Adapter that reads/writes to a Postgres table via SqlExecutor |
Key features
- Idempotent inserts —
ON CONFLICT (event_id) DO NOTHINGprevents duplicates - Server-side aggregation —
loadAggregated()bins coordinates in SQL for large datasets - Parameterized queries — All values are parameterized (
$1,$2, ...) to prevent SQL injection - Custom table name — Validated against
[a-zA-Z_][a-zA-Z0-9_]*for safety - Works with any Postgres client — Accepts any object with
query(text, params)(pg, postgres.js, Drizzle, etc.)
See the Persistence Guide for the full SQL schema and client-specific setup.
`@react-clickmap/supabase`
Supabase REST API adapter. No custom backend code needed.
Shell
npm install @react-clickmap/supabaseWhat it provides
| Export | Description |
|---|---|
createSupabaseAdapter() | Adapter that talks to Supabase's PostgREST API |
Key features
- Direct client-to-Supabase — No API route needed; the client saves/loads events directly
- Idempotent inserts — Uses
Prefer: resolution=ignore-duplicatesheader - Custom schema support — Set
schemaoption for non-publicschemas - RLS compatible — Works with Row Level Security policies
Quick setup
TSX
import { createSupabaseAdapter } from "@react-clickmap/supabase";
const adapter = createSupabaseAdapter({
url: process.env.NEXT_PUBLIC_SUPABASE_URL!,
anonKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
});`@react-clickmap/dashboard`
Pre-built analytics dashboard components.
Shell
npm install @react-clickmap/dashboardWhat it provides
- KPI cards — Total events, rage rate, dead-click rate, scroll depth
- Event distribution panels — Breakdown by event type
- Device mix — Desktop/tablet/mobile distribution with ratios
- Top pages — Most-viewed pages sorted by event count
- Hourly activity — 24-hour timeline of event volume
- Dashboard snapshot builder —
buildDashboardSnapshot(events)computes all metrics from raw events
Usage
TSX
import { buildDashboardSnapshot } from "@react-clickmap/dashboard";
const events = await adapter.load({ projectId: "my-app" });
const snapshot = buildDashboardSnapshot(events);
console.log(snapshot.totalEvents); // 45892
console.log(snapshot.rageRate); // 0.032
console.log(snapshot.deadRate); // 0.014
console.log(snapshot.averageScrollDepth); // 71.2
console.log(snapshot.uniqueSessions); // 3241
console.log(snapshot.topPages); // [{ pathname: "/pricing", count: 12340 }, ...]
console.log(snapshot.deviceMix); // [{ device: "desktop", count: 30201, ratio: 0.66 }, ...]
console.log(snapshot.timeline); // [{ hour: "00:00", count: 120 }, ...]`@react-clickmap/cli`
Local development preview tool.
Shell
npx @react-clickmap/cli --port 3334What it provides
- Self-hosted API at
/api/clickmap— accepts the same HTTP contract asfetchAdapter - Browser dashboard — Live event metrics and canvas-rendered heatmap preview
- File-backed storage — Events persist to a local JSON file for replay
- Zero config — Just run the CLI and point your
fetchAdapterat it
Usage for development
- Start the CLI:
Shell
npx @react-clickmap/cli --port 3334- Point your adapter at it:
TypeScript
const adapter = fetchAdapter({ endpoint: "http://localhost:3334/api/clickmap" });- Open
http://localhost:3334to see the dashboard
This lets you develop and test heatmap features without setting up a database.