Skip to content

Playbook · Experiments & Engineering

B2B SaaSE-commerceAgencies

Run flicker-free Next.js A/B tests tied to Stripe revenue

Assign Next.js App Router visitors on the server before first HTML paints, measure real Stripe subscription revenue per arm, and graduate winning code cleanly.

Free monthly allowances included. No credit card to start.

7 min read~15 min active setupUpdated
Full-stack software engineer writing Next.js TypeScript code on a sunlit oak studio desk
Render the winning arm on the very first server HTML byte, measure paid Stripe subscriptions instead of button clicks, and ship a clean graduation PR.

Interactive preview · SSR arms & Stripe MRR

Preview both SSR pricing arms and inspect the Stripe revenue readout.

Toggle between Control and Variant B as Next.js renders them on the first HTML byte, paired with 21-day Stripe subscription results for LedgerFlow.

Illustrative fixture · LedgerFlow
Apexapex / experiments / exp_ledgerflow_pricing_ssr

First-byte SSR pricing preview

SSR arm: variant_annual_roi0ms layout shift

Pro Plan · $149/mo (save 2 months on annual + ROI guarantee)

Server-rendered annual savings callout paired with average 4-hour monthly close time saved.

Control · Monthly default
3.09%
68 / 2,200 paid ($10,132 MRR)
Variant B · Annual savings + proof
4.5%
99 / 2,200 paid ($14,751 MRR)

Lift: +1.41 pts (95% CI: +0.28 to +2.54 pts, p = 0.014) · +31 incremental subscriptions in test (+$12,963/mo projected at 100%).

Calling useApexVariant without a server arm renders Control in the first HTML and swaps after /assign returns. Passing assignments from assignExperiments() renders Variant B on the very first byte.
Why server initialVariant eliminates React hydration flicker

Priya Nair

priya.nair@example.com

$149/mo

Harbor Freight Ops · Variant B

SSR assignment -> Stripe -> Graduation PR

  1. Graduation pr openedMay 28, 2026, 1:00 PM
  2. PurchaseMay 25, 2026, 3:00 PM
  3. Experiment assignedMay 25, 2026, 2:53 PM

    /pricing

The complete playbook

Step-by-step setup, worked math, and real limits.

Follow the steps below, check how this interacts with tools you already run, and inspect live Apex pricing before turning anything on.

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

  1. 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.

  2. 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.

  3. 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.

  4. 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

Two web engineers reviewing a Next.js pull request together on a laptop at a sunny wooden studio desk

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.

  1. Mint apex_vid in middleware: Install @apex-inc/next and @apex-inc/react and register apexVisitorMiddleware so every visitor has a durable anonymous cookie before the page renders.

  2. Assign on the server in page.tsx: Call assignExperiments() inside your React Server Component and pass assignments into &lt;ApexProvider&gt; (or initialVariant + search into useApexVariant). As noted in Running Experiments, calling useApexVariant alone without a server arm renders Control first and swaps after hydration.

  3. 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.

Record a Belief before activating

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)VisitorsPaid Stripe Pro subsConversion rateNew Stripe MRR
Control · Monthly default2,200683.09%$10,132/mo
Variant B · Annual savings + proof2,200994.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-tailed p = {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).
SaaS founder smiling at a sunlit oak desk reviewing Stripe experiment results on a laptop

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 meterScenario volumeFree monthly allowanceOverage rateApex cost
Events
Pricing page visits, plan toggle clicks, and Stripe Checkout subscription webhooks
37,440 / mo1M / month$5 per 100K (per unit)$0
Orchestrations
6,200 server-side SSR variant assignments via @apex-inc/next
6,200 / mo1M / 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)

ExpenseTypical rangeNotes
Next.js hostingExisting planRuns inside your existing Vercel, AWS ECS, or Node App Router deployment.
Stripe billing accountExisting accountApex 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_tests through 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.

For your Next.js developer or AI editor

Ship a flicker-free Next.js experiment via Apex MCP.

Connect Apex MCP in Cursor, VS Code, or Claude Code, then paste the prompt below. Your agent checks for overlapping live tests first, records your hypothesis as a Belief, wires @apex-inc/next server assignment, and captures arm screenshots before activation.

1Add Apex to your editor

Install in Cursor

Opens Cursor and adds Apex. Nothing to configure.

2Tell your agent

Paste this prompt into your AI editor (scroll to read full prompt)

Inspect this Next.js codebase and my connected Apex workspace before changing anything. Run check_live_tests on our pricing page first so we never collide with a running experiment. Then propose a plan to: (1) create a Belief and a code-mode Experiment in Apex targeting our Stripe subscription_started conversion, (2) install @apex-inc/next and @apex-inc/react and wire apexVisitorMiddleware + assignExperiments in the Server Component so the first HTML byte already renders the assigned arm with zero flicker and supports _apex_preview, (3) pass initialVariant into ApexProvider / useApexVariant in the client pricing view, and (4) wait for my deploy confirmation before activating the experiment. Report what code is ready, what preview URLs to inspect, and whether Stripe is already connected.

The first time your agent calls Apex, it gives you a link to approve in the browser. There is no key to paste. In Cursor you can also run /setup-apex.

See how editor setup works step by step

ledgerflow-next · CursorWaiting for approval
Agent
You

Wire a zero-flicker Next.js pricing test tied to Stripe upgrades.

Set up Apex · 0 of 4
  • Live test collision check passed
  • Belief & Stripe-goal experiment created
  • SSR assignExperiments wired
  • Preview & wiring verified before activate

Your move

Ship zero-flicker Next.js tests measured in Stripe MRR.

Assign variants in React Server Components via @apex-inc/next, judge winners on paid Stripe subscriptions, and graduate with an automated PR.