@spoar/sdk
Privacy-first analytics you host yourself.
Typed, cookie-free analytics for the browser, server and React, sent to your own Postgres.
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 pageviews: false,10 plugins: [speedInsights(), errors()]11})1213analytics.track('signup', { plan: 'pro' })The Next component sends each pageview with its route template, such as /blog/[slug]. With debugConsole set, project admins open the debug console with Ctrl+Shift+K, and visitors load nothing for it.
1'use client'23import type { ReactNode } from 'react'4import { AnalyticsProvider } from '@spoar/sdk/react'5import { Analytics } from '@spoar/sdk/next'6import { analytics } from '@/lib/analytics'78export function Providers({ children }: { children: ReactNode }) {9 return (10 <AnalyticsProvider client={analytics}>11 <Analytics debugConsole />12 {children}13 </AnalyticsProvider>14 )15}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}