Skip to main content
The fastest way to add Subtext to a Next.js App Router project is to drop the capture snippet into your root layout file. Because app/layout.tsx wraps every route in your application, the snippet loads once and records sessions across your entire site. The <Script> component from next/script handles deferred loading cleanly, keeping it out of the critical render path.
You can also run npx @subtextdev/subtext-wizard in your project root to have Subtext detect your framework and insert the snippet automatically. Follow this guide if you prefer to wire things up by hand.
1

Find your Org ID

Log in to Subtext and open Settings. Your Org ID is listed in the Capture section. Copy it — you will paste it in place of YOUR_ORG_ID in the snippet below.
2

Open your root layout

Open app/layout.tsx (or app/layout.jsx) in your editor. This file exports the RootLayout component that wraps every page in your application.
3

Import the Script component

Add the following import at the top of app/layout.tsx, alongside your existing imports:
4

Add the capture snippet

Place a <Script> element with strategy="afterInteractive" inside your <body> tag, before any other children. Replace YOUR_ORG_ID with the Org ID you copied from Subtext settings.
app/layout.tsx
The id prop on <Script> is required by Next.js for any inline script. You can use any unique string — "subtext-capture" is a good default.
5

Deploy and verify

Deploy your application (or run next dev locally), then open it in a browser. Navigate to Subtext → Sessions and confirm that a new session appears within a minute or two.
Sessions typically appear within 30–60 seconds of page load. If nothing shows up after a few minutes, double-check that YOUR_ORG_ID was replaced with your actual Org ID and that the layout file is being served for the route you visited.
The snippet records full production sessions and masks all form inputs by default. Your agent can flag additional PII and propose masking rules for your review from within Subtext.