Skip to main content
Add PostMetric to your Next.js App Router project in minutes.

Installation

Step 1: Add the tracking script

Add the tracking script to your root layout (app/layout.tsx):
Replace YOUR_TRACKING_CODE with your tracking code from the dashboard.

Step 2: Verify installation

  1. Start your development server: npm run dev
  2. Visit your website
  3. Check your PostMetric dashboard - you should see your visit

Track custom goals

Track custom goals in your Next.js components:

User identification

Identify users when they log in:

TypeScript types

Add TypeScript types for better type safety:

Server-side tracking

For server-side tracking, use the API directly:

Next steps

Track custom goals

Learn how to track custom user actions