Skip to main content
This guide is for Next.js projects with a /pages directory. If you have an /app directory, use the App Router guide

Step 1 — Install the SDK


Step 2 — Create components/analytics.jsx (One-time setup)

Create this file anywhere in your project. This is the only place Analytiq is configured.
components/analytics.tsx
Add your API key to .env.local:
The prefix must be NEXT_PUBLIC_. Without it, the key will be undefined on the client side.

Step 3 — Wrap your app in pages/_app

_app is a special Next.js file that wraps every page. Add your AnalyticsProvider there.
pages/_app.tsx
Setup is complete! You never need to touch _app again for analytics purposes.

What the setup handles automatically


Step 4 — Track Custom Events

For any specific action, import track() from your analytics.jsx file and call it where the action happens.
pages/dashboard.jsx

Step 5 — Verify it’s working

  1. Run: npm run dev
  2. Log into your app
  3. Open http://localhost:3000, press F12Network tab
  4. You should see POST /api/events/track requests for every track() call you make

Common Mistakes