@spoar/sdk
Privacy-first analytics you host yourself.
Typed, cookie-free analytics for the browser, server and React, sent to your own Postgres.
What it replaces
Use it when you want product analytics on a site or app but do not want cookies, consent banners or a vendor in the loop. Create one client, list your events once, and add plugins only for what you need.
Quick start
1import { createAnalytics } from '@spoar/sdk'2import { errors, speedInsights } from '@spoar/sdk/plugins'3import type { Events } from './events'45export const analytics = createAnalytics<Events>({6 project: 'my-site',7 key: 'pk_live_...',8 endpoint: '/_ra',9 plugins: [speedInsights(), errors()]10})1112analytics.track('signup', { plan: 'pro' })API examples
The Next component sends each pageview with its route template, such as /blog/[slug].
1import { AnalyticsProvider } from '@spoar/sdk/react'2import { Analytics } from '@spoar/sdk/next'3import { analytics } from './analytics'45export default function RootLayout({ children }) {6 return (7 <html lang="en">8 <body>9 <AnalyticsProvider client={analytics}>10 <Analytics />11 {children}12 </AnalyticsProvider>13 </body>14 </html>15 )16}Record events that happen on the backend and never reach the browser.
1import { createServerAnalytics } from '@spoar/sdk/server'23const serverAnalytics = createServerAnalytics<Events>({4 secret: process.env.RA_SECRET,5 endpoint: 'https://api.analytics.remcostoeten.nl'6})78export async function POST(request: Request) {9 await createUser()10 await serverAnalytics.track('signup', { plan: 'pro' }, { request })11 return Response.json({ ok: true })12}