π¦ 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