/tools/peepless/setup/Folio 2 of 7SetupDaybook of peepless 1.0.0-rc.2Days kept in UTC
2.0

The two-minute setup

Six entries, in order. You'll need a Supabase project and your site's production URL. Or skip to 2.7 and hand the whole recipe to your AI tool.

2.1

Install

npm install peepless

Zero dependencies. The browser part is under 2 KB gzipped, held under a 2 KB budget by the build.

2.2

Rule the book: make the table

In Supabase, open the SQL editor and run starters/supabase/schema.sql once (on Lovable or Bolt, as a new migration). It creates peepless.counts in a schema the public API can't reach. Only your server writes to it, through peepless_add.

create table if not exists peepless.counts (
  day date not null,
  project text not null check (project ~ '^[a-z0-9][a-z0-9-]{0,63}$'),
  counter text not null check (counter ~ '^[A-Za-z0-9_:/*.\[\]-]{1,120}$'),
  count bigint not null default 0 check (count >= 0),
  primary key (day, project, counter)
);

Don't expose the peepless schema in the API settings. One row per day, project and counter, holding a number and nothing else.

Not on Supabase? Run starters/postgres/0001_peepless.sql on any Postgres and use postgresStore, or the D1 migration in the Cloudflare starter with d1Store. Something else? Write a store and check it with testStore from peepless/testing.

2.3

Add the endpoint

Pick the one that fits. In each, list your site's origin, the events it may count, and its page patterns.

// peepless's counter as a Next.js route handler: app/api/peepless/route.ts.
// The client's default endpoint is /api/peepless, so start() needs no endpoint option.
// Set SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY (server-only; never NEXT_PUBLIC_).
// On Vercel, visits are counted by country from the x-vercel-ip-country header.
import { createHandler, supabaseStore } from 'peepless/server'

const handler = createHandler({
  projects: {
    'my-app': { origin: 'https://example.com', events: ['signed_up', 'exported'], routes: ['/', '/blog/*', '/app/*'] },
  },
  store: supabaseStore({ url: process.env.SUPABASE_URL!, key: process.env.SUPABASE_SERVICE_ROLE_KEY! }),
})

export const POST = handler
export const OPTIONS = handler

A wrong setting throws when the handler is created, so a typo fails at deploy time instead of silently counting nothing.

2.4

Start the client

Call start once, in the browser, as early as you can: src/main.tsx in Vite, or a 'use client' component in your root layout on Next.js. It counts the first page and every client-side navigation after it.

import { start } from 'peepless'

start({
  project: 'my-app',
  host: 'example.com', // counts only here: not on localhost or preview URLs
  routes: ['/', '/blog/*', '/app/*'], // page types, never the real path
  // endpoint: 'https://<ref>.supabase.co/functions/v1/peepless', // with the Edge Function
})

No bundler? Copy node_modules/peepless/dist/peepless.js into public/ and load it from your own site:

<script src="/peepless.js" data-project="my-app" data-host="example.com" data-routes="/ /blog/* /app/*" defer></script>
2.5

Count the things that matter

Where an action finishes successfully (not when a button is clicked), call track. Every event name must be listed in events on the server, or it's refused.

import { track } from 'peepless'

track('exported')
track('signed_up', user.id) // with a key: at most once per key per page load. The key is never sent.
2.6

Test it on the live site

Nothing is counted on localhost, on preview URLs, or in Playwright and Puppeteer. Open the live site and look in the network tab for a POST to the endpoint answering 204. Or ask the book directly:

select counter, sum(count) from peepless.counts
where day > current_date - 30 group by counter order by 2 desc;

Visit any page with ?peepless-ignore once to stop counting your own device (?peepless-ignore=off undoes it).

2.7

Or hand this to your AI tool

llms.txt is the whole recipe, written for coding assistants: which starter fits your stack, where each file goes, and what not to change. Paste this into Lovable, Bolt, Cursor, Claude Code or similar:

Add privacy-first analytics with the peepless npm package. Follow https://unpkg.com/peepless/llms.txt exactly. My site is https://example.com. Count these actions: signed_up, exported.