Learn how to integrate Trakg with your Next.js app β including both App Router and Pages Router setups.
<Script />
component for better performance.
π Replace YOUR_ID_GIVEN
with your actual Site ID found in your Trakg dashboard.
/app
directory), you can add the script inside your layout.tsx
or layout.js
file β which wraps all routes.
app/layout.tsx
/pages
directory), include the Trakg script in your custom _document.js
.
<script defer />
here β since Next.js does not support <Script />
from next/script
inside _document.js
.
defer
attribute β ensures the script loads after the HTML is parsed.<Script strategy="afterInteractive" />
from next/script
.<body>
for non-blocking performance.<form>
, <input>
, <textarea>
, and <select>
elements.