# peepless > Privacy-first analytics: daily totals of page views, visits, sources, countries, engaged ("human") visits and named events. No cookies, IDs, IPs, URLs or user agents are stored. An under-2 KB browser client (`peepless`) posts beacons to a server handler (`peepless/server`), which adds +1 to daily counters in one Supabase table. These are instructions for an AI coding assistant adding peepless to an app. Follow them exactly. Ask the user only for what's missing: the site's production URL and the actions to count. ## Steps 1. Install: `npm install peepless`. 2. Database (Supabase): run the SQL from https://unpkg.com/peepless/starters/supabase/schema.sql once (Lovable/Bolt: as a new migration). Don't edit it, and don't expose the `peepless` schema in the API settings. It creates `peepless.counts` and the server-only functions `peepless_add` and `peepless_counts`. 3. Endpoint. Choose ONE: - Next.js (App Router): create `app/api/peepless/route.ts` from https://unpkg.com/peepless/starters/nextjs/app/api/peepless/route.ts. Its env vars are SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY. They are server-only: never prefix them with NEXT_PUBLIC_ or VITE_, and never import this file into client code. - Vite/React SPA on Supabase (Lovable, Bolt, plain Vite): create `supabase/functions/peepless/index.ts` from https://unpkg.com/peepless/starters/supabase/functions/peepless/index.ts and deploy it with JWT verification OFF (`supabase functions deploy peepless --no-verify-jwt`, or `verify_jwt = false` under `[functions.peepless]` in supabase/config.toml). The client's endpoint is then `https://.supabase.co/functions/v1/peepless`. - SvelteKit: create `src/routes/api/peepless/+server.ts` from https://unpkg.com/peepless/starters/sveltekit/src/routes/api/peepless/+server.ts, with SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY as private env vars. - Cloudflare Workers with static assets (no Supabase): use https://unpkg.com/peepless/starters/cloudflare/src/index.ts, wrangler.jsonc and migrations/0001_peepless.sql from the same folder. It counts into D1 with `d1Store`; skip step 2. - Plain Postgres instead of Supabase (Neon, RDS): run https://unpkg.com/peepless/starters/postgres/0001_peepless.sql and use `postgresStore((text, params) => )` as the store in any starter. - Any other server with web-standard Request/Response (Remix, Astro, Hono, Deno, Bun): `export` a POST (and OPTIONS) route at `/api/peepless` that calls `createHandler({...})(request)`. In that file, set `projects` to `{ '': { origin: '', events: [], routes: [] } }`. The slug is lowercase letters, digits and dashes. The origin is scheme and host only, with no path and no trailing slash. Event names are lowercase snake_case, and never `pageview`, `visit` or `human`. 4. Client: call `start` once, in the browser, at app start-up. - Vite/React: in `src/main.tsx`, before or after `createRoot(...)`. - Next.js App Router: in a `'use client'` component with `useEffect(() => { start(...) }, [])`, rendered once from the root layout. ```ts import { start } from 'peepless' start({ project: '', host: '', routes: [] /*, endpoint: '' when using Supabase Edge Functions */ }) ``` If the site is served on more than one domain, `host` takes a list: `host: ['example.com', 'example.org']`. Only if the user tags links (newsletters, launch posts) with `?ref=` or `?utm_source=`: list those tags, lowercase, as `campaigns: ['newsletter']` both here and in the server's project. Never put referral codes or user ids in the list. Route patterns are "/" for one exact path, "/blog/*" for everything under /blog, and "/posts/[id]" for one dynamic segment. Use the app's real page types. Leave routes out if unsure. 5. Events: where an action finishes successfully (not when a button is clicked), add `import { track } from 'peepless'` and `track('')`. Add every event name to `events` on the server, or it's refused. To count something once per item per page load, pass a key: `track('exported', fileId)`. The key never leaves the browser. In TypeScript, you can instead export what `start<'' | ''>({...})` returns and call `.track(...)` on it, so a misspelt event is a type error. 6. CSP: if the app sets a Content-Security-Policy and uses the Edge Function, add its URL to `connect-src`. The no-bundler script, `public/peepless.js`, needs no CSP change. 7. Privacy page: if the app has one, add the text below. If it has a setting for analytics, wire it to `optOut()` / `optIn()` / `isOptedOut()` from `peepless`; don't gate `start` on it. Add: "We count visits with peepless, which keeps daily totals only: how many pages were viewed, which sites, tagged links and countries visits came from, and how many times features were used. No cookies, identifiers, IP addresses or browsing history are stored, and nothing is shared with anyone else." ## Showing the numbers (only if the user asks for a stats page) Read on the server, never in the browser, with the same env vars as the endpoint: ```ts import { readCounts, summarize, supabaseStore } from 'peepless/server' const store = supabaseStore({ url: process.env.SUPABASE_URL!, key: process.env.SUPABASE_SERVICE_ROLE_KEY! }) const since = '', until = '' // UTC days, inclusive const s = summarize(await readCounts(store, { project: '', since, until }), { since, until }) ``` `s` has `pageviews`, `visits`, `humans` (engaged visits), maps `sources`, `countries`, `pages` and `events` (name → count, largest first), and `days` (`[{ day, pageviews, visits, humans }]`, zeros included). Render those; don't parse counter names yourself. - Next.js: do this in a Server Component or route handler. Protect the page (it's the owner's data) unless the user wants it public. - Vite/React SPA on Supabase: the browser can't hold the key, so deploy `supabase/functions/peepless-stats/index.ts` from https://unpkg.com/peepless/starters/supabase/functions/peepless-stats/index.ts with `--no-verify-jwt`, set the secret `PEEPLESS_STATS_TOKEN` to a long random value, and call it from a server or another Edge Function with `Authorization: Bearer `. Never put that token in client code. ## Don'ts - Don't send user IDs, emails, file names, search terms or URLs as event names, and don't add new fields to the beacon. The server ignores them, and the privacy promise depends on it. - Don't call `start` on the server or more than once. - Don't put the service-role key in client code or a public env var. - Don't wrap peepless in a cookie banner: it sets no cookies and stores nothing about a person. ## Testing Nothing is counted on localhost, on preview URLs, or in Playwright/Puppeteer (navigator.webdriver). To see what it would send while developing, add `debug: true` to `start` (or `data-debug` to the script tag): each beacon is logged to the console as `peepless (debug, not sent): ...` instead of sent. Remove it before deploying. `start(...).reason` says why nothing is sent. To see it working for real, open the live site and check the network tab for a POST to the endpoint with status 204, then run `npx peepless report`. If nothing shows up, run `npx peepless doctor --site --project ` and fix what it reports. Or run `select * from peepless.counts order by day desc` in Supabase. Add `?peepless-ignore` to the live URL once to stop counting your own device. ## Reference - README: https://github.com/mtblck/peepless#readme - Counters: pageview, visit, human, from:, country:, page:, and your events. Full grammar: https://unpkg.com/peepless/docs/counters.md - HTTP contract for the endpoint and the stats endpoint: https://unpkg.com/peepless/openapi.yaml - In a terminal: `npx peepless report` (last 30 days) and `npx peepless doctor --site --project ` (finds why nothing is counted).