Before starting: Get your API key from Settings
Step 1 — Install the SDK
Step 2 — Create components/analytics.tsx (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 app/layout.tsx
Open your existing app/layout.tsx and wrap the children with the provider. Make sure it goes inside your Auth provider.
- TypeScript (layout.tsx)
- JavaScript (layout.js)
app/layout.tsx
Setup is complete! You never need to touch these two files again for analytics purposes.
What the setup handles automatically
Step 4 — Track Custom Events
For specific actions (page views, button clicks, purchases), importtrack() from your analytics.tsx file and call it where the action happens. Always add 'use client' at the top since track() is browser-only.
- Track a page view
- After API call
app/page.tsx
Step 5 — Verify it’s working
- Run:
npm run dev - Log into your app (so your
useAuthreturns a user) - Open
http://localhost:3000, press F12 → Network tab, filter bytrack - You should see a
POST /api/events/trackrequest for any event you fire manually