Recipes
“Tracking is working” on your setup screen#
Server
const { receiving, visitors_24h } = await stats.sites.status(website.id);
return receiving ? `Working: ${visitors_24h} visitors today` : 'Waiting for the first visit…'; A stats card in your own dashboard#
app/api/stats-token/route.ts
import { stats } from '@/lib/stats';
export async function GET() {
const user = await currentUser(); // your own sign-in
return Response.json(await stats.readToken({ client: user.id, ttl: 600, origins: ['https://app.example.com'] }));
} A client component
import { createReader } from 'nahnu-analytics-sdk/read';
const reader = createReader({ endpoint, token: async () => (await fetch('/api/stats-token')).json() });
const data = await reader.overview(siteId, { period: '7d', only: 'aggregate,timeseries' }); Billing your users by usage#
Monthly billing job
const { clients } = await stats.usage({ from: '2026-10-01', to: '2026-10-31' });
for (const c of clients) await billing.recordUsage(c.ref, c.pageviews); A nightly import that may run twice#
Import job
await stats.events.send(website.id, orders.map((o) => ({
name: 'Purchase',
id: o.number, // the same id twice counts once, and makes retries safe
revenue: { amount: o.total, currency: o.currency },
}))); Up to 50 events per call.
An Analytics button#
Was this helpful?
Thanks for your feedback!
✓ Feedback received. Thank you!



