Skip to content

createAbTestingMiddleware

createAbTestingMiddleware is a middleware helper for projects using React Bricks A/B Testing.

Use it in:

  • Next.js Pages projects
  • Astro projects

It resolves the active A/B Testing variant for a request, so your application can render the correct page variant and track analytics consistently.

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

Use createAbTestingMiddleware when your project uses A/B Testing and Multischeduling and does not need to chain the A/B Testing middleware with the Next.js App i18n middleware.

For Next.js App projects that need to chain with i18n, use createWithAbTestingMiddleware.

The exact middleware file and request/response types depend on your framework.

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