← All articlesInfra and cloud

How I built Klickbee Tracking

Next.js, Postgres, an npm SDK and no queue. What holds, what changed and what broke in production.

Julien Mauclair · ~4 min · intermediate
StackNext.jsPostgreSQLPrismaVercelTypeScript

Klickbee Tracking is the cookieless analytics I build for Klickbee. The first commit is dated 25 June 2026, and the repository had 489 commits by 9 November. The architecture has three parts: a Next.js application that receives events and serves the dashboards, a Postgres database, and an SDK published on npm. No queue, no specialised analytics database.

01The real architecture

The repository is a pnpm monorepo with Turborepo. The main parts:

·apps/web: the Next.js 16 application with React 19. It handles event ingestion, dashboards, scheduled jobs, billing and an MCP server to query the data from an assistant;
·packages/sdk: the SDK, published on npm as @klickbee-agency/tracking, also usable through a plain script tag;
·packages/contracts: the schema shared between the SDK and the API, so both speak exactly the same format.

Events are written straight to the database. A single Prisma transaction creates or updates the visitor, then the session, then inserts the batch of events. Duplicates are dropped thanks to a unique id per message. Only server-side conversions go through a jobs table, drained every five minutes by a scheduled job.

The database is managed Postgres at Neon, in Frankfurt. The application runs on Vercel in the fra1 Region, right next to it. Session recordings are compressed and stored in S3.

02What "cookieless" means here

The SDK sets no cookie. It does keep a random anonymous id in the browser's local storage, renewed after 395 days to stay under the 13-month limit set by the CNIL, the French data protection authority. The IP address is truncated before geolocation and never stored in full.

I prefer to be precise here: cookieless does not mean no identifier at all in the browser. It is a distinction many tools leave vague.

Heatmaps are built from automatically captured clicks with their coordinates, capped at 4,000 points per map. The page background comes from the session recording. AI summaries and insights go through the Vercel AI SDK with Claude models, capped at 30 calls per hour and 3 at a time.

03Choices revisited along the way

Two decisions changed very early. On the day of the first commit, the whole stack moved to the latest major versions: Next 16, React 19.2, Prisma 7. Better to start up to date than to migrate later with production data.

Five days later, on 30 June, the application left the Singapore Region for Frankfurt. The database was in Frankfurt, and every request paid the round trip between continents. Since each request's time was dominated by the database, moving compute next to it was the obvious call.

04The three production bugs that taught me the most

None came from the architecture. All came from a configuration detail.

14 September 2026Most ingestion calls returned 403 in production, with nothing in the logs
29 October 2026The last batch of events on every page was lost, spotted on this site
4 November 2026No scheduled job had ever run

The second is the nastiest. When a page closes, the SDK sends its last batch with sendBeacon, which always goes out with browser credentials. The CORS preflight response did not return the Access-Control-Allow-Credentials header, so the browser dropped the request with no visible error. On a short visit, that was often the only batch.

The third comes down to a misplaced file. The Vercel project reads its configuration from apps/web, and the vercel.json file sat at the repository root. Vercel ignored it silently: neither the scheduled jobs nor the security headers were applied. Here is the core of the file, once in the right place:

apps/web/vercel.jsonTEXTCopy
{
"regions": ["fra1"],
"buildCommand": "pnpm build",
"crons": [
{ "path": "/api/internal/cron/purge", "schedule": "0 3 * * *" },
{ "path": "/api/internal/cron/conversions", "schedule": "*/5 * * * *" }
]
}

The common lesson: ignored configuration produces no error. Since then, a test checks that the file sits where Vercel reads it. I cover this more broadly in my article on monitoring.

05What it costs

In October 2026, Klickbee Tracking's share of the team's Vercel bill was $1.00 of usage, on top of the Pro plan shared by all our projects. The Neon database and S3 storage are billed separately. A simple architecture on Vercel stays cheap while traffic remains reasonable, as I explain in why Vercel for a SaaS.

The tool is live at tracking.klickbee.com, with a free plan up to 1,000 sessions a month.

06FAQ

Why Postgres rather than an analytics database like ClickHouse?

Because at this stage, Postgres with good indexes is enough, and a single database is simpler to run. A specialised database will make sense when volumes require it, not before.

Why no queue for events?

One transaction per batch, with deduplication on a unique id, covers today's needs. Only server-side conversions go through a jobs table, because they call external services that can fail.

Is cookieless analytics exempt from consent?

Not automatically. The CNIL exemption for audience measurement depends on specific conditions, including how long identifiers live, which the SDK respects with its 395-day renewal. Each site remains responsible for its own compliance.

In short

Klickbee Tracking runs on a deliberately simple architecture: a Next.js app, a Postgres database and an SDK. The real problems came from configuration details, not from the architecture.

Talk about your project ↗
Julien MauclairJulien Mauclair is the co-founder and CTO of Klickbee, where he builds the agency’s websites, tracking and AI automations, and develops Klickbee Tracking. He also runs Stralya, which designs and runs AWS infrastructure for scale-ups. Before that, he built the entire AWS infrastructure of an e-commerce business, since sold.

Read next