<script> tag in the document <head>, with data-await-hydration="true". pagent recognizes Next.js hydration in both routers, and follows client-side navigation on its own.
App Router
Add the tag to the<head> of your root layout:
app/layout.tsx
Pages Router
Add the tag to the<Head> of your custom document:
pages/_document.tsx
Recommendations
- Keep
data-await-hydration="true". Without it, hydration can undo a variant right after pagent applied it. - Slow pages: if your pages hydrate slowly, raise the wait with
data-hydration-timeout="800". Try it first on a preview link with?pagent_hydration_timeout=800. - Streaming and Suspense: pagent waits for Suspense boundaries that have already arrived, not for ones that are still streaming. Test variants on content inside late Suspense boundaries with a preview link.
- Navigation: route changes with
<Link>androuter.pushare tracked automatically. Don’t callnavigateyourself, or the page view counts twice.
Check it worked
- Deploy, then open your site in a private browser window.
- Back in pagent, click Check connection in the install step.
- Open a test’s preview link and check that the variant shows and stays after the page has finished loading.