Skip to content

createWithAbTestingMiddleware

createWithAbTestingMiddleware is a middleware helper for Next.js App projects where A/B Testing must be chained with i18n routing.

It lets one request flow resolve both:

  • the active locale
  • the active A/B Testing variant

The selected variant is stored in a cookie. When rendering the page, read it with getAbTestingCookie and pass it to fetchPage as variantName.

Use createWithAbTestingMiddleware when:

For Next.js Pages or Astro projects, use createAbTestingMiddleware.

Middleware chaining is project-specific, because it depends on your routing, locales, and analytics setup.

Use the starter implementation as the recommended reference: https://github.com/ReactBricks/reactbricks-starters/tree/feature/ab-testing/apps/nextjs-app