This guide is for Next.js projects with a
/pages directory. If you have an /app directory, use the App Router guideStep 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.
- TypeScript (analytics.tsx)
- JavaScript (analytics.js)
components/analytics.tsx
.env.local:
Step 3 — Wrap your app in pages/_app
_app is a special Next.js file that wraps every page. Add your AnalyticsProvider there.
- TypeScript (pages/_app.tsx)
- JavaScript (pages/_app.js)
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, importtrack() from your analytics.jsx file and call it where the action happens.
- Track a page view
- After a login / API call
pages/dashboard.jsx
Step 5 — Verify it’s working
- Run:
npm run dev - Log into your app
- Open
http://localhost:3000, press F12 → Network tab - You should see
POST /api/events/trackrequests for everytrack()call you make