Next.js A/B testing
Add AB Splits to your root layout and test any page of your Next.js app. The snippet follows client-side navigation, so tests run on every route change, not just the first page load.
Free plan · 1,000 visitors / month · no card
Set up in 3 steps
- 01Add the script to app/layout.tsx with next/script and the beforeInteractive strategy.
- 02Deploy, then click Check install in AB Splits.
- 03Create a test with a URL pattern like /pricing* and a selector, ideally a data attribute such as [data-ab=hero-title].
app/layout.tsx
import Script from "next/script";
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>
{children}
<Script src="https://absplits.com/s.js" data-key="YOUR_SITE_KEY" strategy="beforeInteractive" />
</body>
</html>
);
}Your real site key is shown in the dashboard after you add your site.
- Read the visitor's variant in your own code with ABSplits.variant(testId) when you want to branch logic yourself.
- A server-side Next.js package for zero-flicker tests at the edge is on the roadmap.
What to test on Next.js
All 56 examples →Lead with the outcome, not the product category
Default the pricing toggle to annual
Highlight the middle plan as 'Most popular'
Make 'Continue with Google' the main sign-up option
Add risk-reversal microcopy under the button
One hero button instead of two
AI writes variants
Choose a headline or button and AI reads your real page to write 3–5 alternatives, each with its reasoning.
Honest stats
Chance to beat the original, 95% intervals, and a plain keep-running or stop verdict. No p-value guesswork.
Results in GA4
Every tested visitor is tagged in GA4, so any report can be split by variant.
Questions
Does it work with client-side navigation?+
Yes. The snippet listens for route changes and re-applies tests and page-view goals each time the URL changes.
Will React overwrite the variant during hydration?+
Give tested elements a stable data attribute, for example data-ab="hero-title", and use that as the selector. The snippet keeps applying changes while the page renders.
Can I see results in Google Analytics 4?+
Yes. Every visitor in a test sends an absplits_exposure event to GA4 with the test and variant name, so you can break down any GA4 report by variant. AB Splits also shows its own Bayesian results.
A/B testing on other platforms