To add Obsidesk to a Next.js app, put one script tag in your root layout with next/script. You get visitors, routes, referrers, signups from forms and, once you connect Stripe, revenue by channel. Client-side navigation is picked up as pages change.
What you get
- Visitors, pages, referrers and UTM campaigns on every route
- Signups detected from forms with an email field, no extra code
- Custom events with
window.obsidesk.track() - Revenue by landing page and channel once a revenue source is connected
- Web Vitals per page on the Growth plan
- No cookies
Set it up
- 1Create your account and add your domain
Sign up, add the domain you want to track and copy your site ID from Settings. Every plan has a 14-day money-back guarantee; there is no free trial.
- 2Add the script to your root layout
In the App Router put it in
app/layout.tsx. In the Pages Router put the sameScriptinpages/_app.tsx.import Script from "next/script"; export default function RootLayout({ children }) { return ( <html lang="en"> <body> {children} <Script src="https://obsidesk.com/script.js" data-site="YOUR_SITE_ID" strategy="afterInteractive" /> </body> </html> ); } - 3Deploy and check
Open your site in a normal browser window and check that the visit appears in the live view. Visits on localhost are not counted unless you add
data-allow-localhost, and your own visits can be excluded by opening#obsidesk-ignoreonce. - 4Send a custom event
Call it from a client component, or use the no-code attribute
data-obsidesk-event="Pricing CTA"on any link or button.window.obsidesk?.track("Upgrade clicked", { plan: "pro", from: "pricing" }); - 5Connect revenue
Connect Stripe or another source under Settings, then Revenue. Also available as an npm package (
@obsidesk/analytics) with an<Analytics />component, but the script tag above is all you need.
Next.js specifics
- Server components are unaffected: the script runs in the browser only
strategy="afterInteractive"loads it after hydration so it does not block rendering- Visits on localhost are ignored unless you add
data-allow-localhost - To avoid ad blockers, proxy the script with
rewrites(): see the docs
Pass the visitor to Stripe Checkout
If you create Checkout sessions in a Route Handler or server action, send window.obsidesk?.id from the client and set it as client_reference_id. This is how a sale is tied to the first visit. Full example in the Stripe guide.
FAQ
What is the best analytics for a Next.js SaaS?
One that connects traffic to revenue. Obsidesk adds a single script and a read-only Stripe key and shows which channel brings paying customers. See vs Vercel Analytics.
Does it work with the App Router and server components?
Yes. The script is rendered once in the root layout and tracks in the browser, so server components are unaffected.
Can I use it alongside Vercel Analytics?
Yes, they do not conflict.
How do I track signups in Next.js?
Any submitted form with an email field is detected as a signup. For OAuth sign-ins call window.obsidesk?.identify(user.email, user.name) after login.
Works with
Connect Next.js in about a minute.
14-day money-back guarantee. Installed in 30 seconds. Read-only revenue connections.