Next.js SDK
The Next.js SDK is optimized for both App Router and Pages Router.
Installation
Section titled “Installation”npm install @analyze.swiss/nextjsApp Router
Section titled “App Router”import { AnalyzeProvider } from '@analyze.swiss/nextjs';
export default function RootLayout({ children }) { return ( <html> <body> <AnalyzeProvider apiKey="YOUR_API_KEY"> {children} </AnalyzeProvider> </body> </html> );}Server Components
Section titled “Server Components”Track server-side events:
import { track } from '@analyze.swiss/nextjs/server';
export async function POST(request: Request) { const body = await request.json();
await track('server_event', { userId: body.userId, properties: body.properties });
return Response.json({ success: true });}