📦 Installation Overview
All you need is to embed the Trakg tracking script. We recommend using Next.js’s built-in<Script /> component for better performance.
🔁 Replace YOUR_ID_GIVEN with your actual Site ID found in your Trakg dashboard.
⚙️ App Router (Next.js 13+)
If you’re using the App Router (/app directory), you can add the script inside your layout.tsx or layout.js file — which wraps all routes.
Example: app/layout.tsx
📁 Pages Router
If you’re using the traditional Pages Router (/pages directory), include the Trakg script in your custom _document.js.
Example: `pages/_document.js
🛡 Best Practices
⚠️ You must use a standard<script defer /> here — since Next.js does not support <Script /> from next/script inside _document.js.
Recommendations
- Always use the
deferattribute — ensures the script loads after the HTML is parsed. - For App Router, prefer
<Script strategy="afterInteractive" />fromnext/script. - Keep the script at the end of
<body>for non-blocking performance. - No need to modify your forms — Trakg supports native
<form>,<input>,<textarea>, and<select>elements. - Works with any form library or custom UI inputs — as long as native HTML form elements are rendered in the DOM.
🚀 You’re Ready!
Once the script is added, Trakg will automatically:- 🔍 Track user interactions on your forms
- 📝 Capture partially filled form data
- ✅ Log completed submissions
- 📊 Display real-time analytics in your dashboard
- 🔁 Help you recover abandoned leads