Skip to main content
Before starting: Get your API key from the Settings page

What you’ll need

  • React app (Vite or Create React App)
  • Your Analytiq API key
  • An existing auth state (like useAuth(), a useState, or a Context)

Step 1 — Install the SDK


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

Create a new file in your src/ folder called analytics.jsx. This is the only place Analytiq is configured. You never touch it again after this.
src/analytics.jsx
Add your API key to .env:

Step 3 — Wrap your app with AnalyticsProvider

Open src/App.jsx (or App.tsx) and wrap your existing app with the provider you just created. Make sure it goes inside your Auth provider.
src/App.jsx
That’s the entire setup! You never touch these files again for analytics purposes.

What the setup handles automatically


Step 4 — Track Custom Events

For any specific action you want to measure (page views, clicks, purchases), import track() from your analytics.jsx file and call it where the action happens.
src/pages/Home.jsx
Rule of thumb: Always import track from your local analytics.jsx file, not directly from analytiq. This ensures your tracking is always correctly initialized before it fires.

Step 5 — Verify it’s working

  1. Run your app: npm run dev
  2. Log into your app (so your useAuth returns a user)
  3. Open browser DevTools (F12) → Network tab, filter by track
  4. You should see a POST /api/events/track request for every event you fire

Common Mistakes