The short answer (native method)
Client-side A/B testing scripts inject DOM changes after hydration, which causes visible layout flicker, slows Core Web Vitals, and breaks React hydration in Next.js App Router apps. You can roll your own middleware cookie bucketing in Next.js, but you still have to build sticky visitor assignment, Stripe webhook revenue joining, two-proportion significance math, and preview URLs yourself.
How Apex automates it
Apex provides @apex-inc/next (apexVisitorMiddleware + assignExperiments) and @apex-inc/react (useApexVariant) so the server renders the assigned arm on first HTML with zero flicker, joins directly to Stripe revenue, and opens a graduation PR when the test concludes.
How to set this up in 4 steps
Install @apex-inc/next and mint the apex_vid visitor cookie in middleware
Install @apex-inc/next and @apex-inc/react, then register apexVisitorMiddleware so every first-time visitor receives a sticky apex_vid cookie before your React Server Component renders.
Assign the experiment in your Server Component and pass assignments down
Call assignExperiments() in your App Router page.tsx and pass the returned map into <ApexProvider assignments={assignments}> (or initialVariant on useApexVariant) so the first HTML byte already matches the assigned variant.
Connect Stripe and link subscription_started as the conversion goal
Authorize Stripe in Apex Integrations and set your paid subscription event as the experiment's primary conversion so Apex scores variants on real revenue rather than pricing-button clicks.
Verify previews, activate, and graduate the winner via pull request
Preview each arm cleanly using ?_apex_preview=<variantKey>, deploy, activate in Apex, and once significance holds, open a graduation PR to remove the losing branch permanently.
What you already have (and why client-side A/B scripts flicker on Next.js)
Traditional A/B testing tools load a blocking script in <head> or hide the page with an anti-flicker timeout until the browser fetches a variant and mutates the DOM. On Next.js App Router pages, mutating server-rendered HTML triggers visible layout jumps, degrades Largest Contentful Paint, and causes React hydration warnings.
Rolling your own cookie split in Next.js middleware solves flicker, but leaves you maintaining sticky visitor identity, Stripe webhook revenue attribution, two-proportion confidence intervals, preview URLs, and post-test cleanup PRs by hand.
Zero-flicker Next.js App Router wiring with @apex-inc/next

Middleware mints the sticky apex_vid cookie, the Server Component assigns the variant before HTML streams, and the client component hydrates cleanly with zero flash.
Mint
apex_vidin middleware: Install@apex-inc/nextand@apex-inc/reactand registerapexVisitorMiddlewareso every visitor has a durable anonymous cookie before the page renders.Assign on the server in
page.tsx: CallassignExperiments()inside your React Server Component and passassignmentsinto<ApexProvider>(orinitialVariant+searchintouseApexVariant). As noted in Running Experiments, callinguseApexVariantalone without a server arm renders Control first and swaps after hydration.Link Stripe subscriptions & graduate via PR: Connect Stripe so paid subscriptions score each arm automatically, then use Apex's Graduation Pipeline to open a pull request that deletes the losing branch once the test concludes.
import { cookies } from "next/headers";
import { assignExperiments } from "@apex-inc/next";
import { PricingClient } from "./PricingClient";
export default async function PricingPage({
searchParams,
}: {
searchParams: Promise<Record<string, string | string[] | undefined>>;
}) {
const cookieStore = await cookies();
const visitorId = cookieStore.get("apex_vid")?.value;
const search = await searchParams;
const assignments = await assignExperiments({
workspaceKey: process.env.NEXT_PUBLIC_APEX_WORKSPACE_KEY!,
visitorId,
experimentIds: ["exp_ledgerflow_pricing_ssr"],
});
return <PricingClient assignments={assignments} search={search} />;
}
Log your hypothesis as a Belief before you turn the test on. When the experiment concludes, Apex updates your Belief confidence automatically so future teammates know what worked and why.
Worked 21-day Stripe revenue test (illustrative assumptions)
All figures below are illustrative assumptions for the same fictional B2B SaaS (LedgerFlow, $149/mo Pro plan) running a 50/50 server-rendered pricing page test over 21 days:
| Variant arm (21d 50/50) | Visitors | Paid Stripe Pro subs | Conversion rate | New Stripe MRR |
|---|---|---|---|---|
| Control · Monthly default | 2,200 | 68 | 3.09% | $10,132/mo |
| Variant B · Annual savings + proof | 2,200 | 99 | 4.5% | $14,751/mo |
Statistical readout & honest monthly projection:
- Absolute conversion lift:
+{(props.fixture.stats.absoluteLift * 100).toFixed(2)} percentage points(95% CI:+{(props.fixture.stats.ci95Low * 100).toFixed(2)}to+{(props.fixture.stats.ci95High * 100).toFixed(2)}pts, two-tailedp = {props.fixture.stats.pValue.toFixed(3)}). - Incremental paid subscriptions during test: +31 subscriptions (95% CI: 6 to 56).
- Projected monthly MRR impact at 100% rollout (
{props.fixture.projectedMonthly.visitors.toLocaleString("en-US")}monthly pricing visitors): +$12,963/mo (95% CI: $2,533 to $23,393/mo).

Pair pricing page experimentation with our B2B SaaS onboarding milestone playbook to verify that higher trial volume still activates and retains.
Live Apex pricing for this workflow
The pricing table below reads directly from Apex's published rate card for {props.fixture.apexUsage.monthlyEvents.toLocaleString("en-US")} monthly events and {props.fixture.apexUsage.monthlyAssignments.toLocaleString("en-US")} SSR assignments ($0 / month inside Apex's free monthly allowances).
Live Apex pricing · Pay-as-you-go
Estimated Apex cost for 6,200 monthly pricing visitors (50/50 SSR test)
$0 / month
Fully inside Apex's free monthly allowances (resets every calendar month).
| Apex meter | Scenario volume | Free monthly allowance | Overage rate | Apex cost |
|---|---|---|---|---|
Events Pricing page visits, plan toggle clicks, and Stripe Checkout subscription webhooks | 37,440 / mo | 1M / month | $5 per 100K (per unit) | $0 |
Orchestrations 6,200 server-side SSR variant assignments via @apex-inc/next | 6,200 / mo | 1M / month | $5 per 100K (per unit) | $0 |
The @apex-inc/next SDK, Stripe connector, GitHub Graduation Pipeline, and unlimited team seats carry no extra Apex fee. Individual event history stays queryable for 13 months without a card, 3 years with a card on file, and 7 years once you've paid an invoice. See the live pricing page.
Third-party and campaign costs (not paid to Apex)
| Expense | Typical range | Notes |
|---|---|---|
| Next.js hosting | Existing plan | Runs inside your existing Vercel, AWS ECS, or Node App Router deployment. |
| Stripe billing account | Existing account | Apex reads paid subscription webhooks via OAuth with no connector surcharge. |
Limitations, Next.js caching tradeoffs, and collision guards
Dynamic SSR vs static CDN caching: Reading
cookies()in a Next.js App Router page switches that route to dynamic rendering per request. Keep static marketing pages cached, and run server-assigned experiments on high-leverage conversion routes (or handle variant routing at the edge).Never edit a live test by accident: Run
check_live_teststhrough Apex MCP before editing or pushing changes to any file hosting a running experiment so you never contaminate an active arm mid-test.Respect sample size before graduating: Early peeks produce false positives. Wait until both arms accumulate enough paid Stripe subscriptions that the 95% confidence interval stays cleanly above zero.

