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
Install: npm install peepless.
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.
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://<project-ref>.supabase.co/functions/v1/peepless.
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 { '<slug>': { origin: '<https://production-origin>', events: [<event names>], routes: [<page patterns>] } }. 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.
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.
import { start } from 'peepless'
start({ project: '<slug>', host: '<production hostname, no https://, no www.>', routes: [<same patterns as the server>] /*, endpoint: '<Edge Function URL>' 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 this app shares its hostname with another site (it lives under a path such as /tools/x/ on a bigger site): add base: '/tools/x/', so visitors arriving from the rest of the site count as visits.
Only if the user tags links (newsletters, launch posts) with ?ref=<tag> or ?utm_source=<tag>: 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.
Events: where an action finishes successfully (not when a button is clicked), add import { track } from 'peepless' and track('<event>'). 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<'<event>' | '<event>'>({...}) returns and call .track(...) on it, so a misspelled event is a type error.
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.
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:
import { readCounts, summarize, supabaseStore } from 'peepless/server'
const store = supabaseStore({ url: process.env.SUPABASE_URL!, key: process.env.SUPABASE_SERVICE_ROLE_KEY! })
const since = '<YYYY-MM-DD>', until = '<YYYY-MM-DD>' // UTC days, inclusive
const s = summarize(await readCounts(store, { project: '<slug>', 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 <token>. 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 <https://site> --project <slug> 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.