getAbTestingCookie
getAbTestingCookie reads the A/B Testing variant name stored in the request cookies.
Use it when rendering a page on the server so the same visitor keeps receiving the same variant.
Signature
Section titled “Signature”import { cookies } from 'next/headers'
type CookieStore = Awaited<ReturnType<typeof cookies>>
const getAbTestingCookie = ({ slug, locale, cookieStore,}: { slug: string locale: string cookieStore: CookieStore}): string | undefined| Property | Definition |
|---|---|
slug | The page slug for the current request. |
locale | The current locale. |
cookieStore | The cookie store returned by cookies(). |
Usage example
Section titled “Usage example”In a Next.js App route, get the cookie store using cookies() from next/headers, then pass the variant name to fetchPage.
import { cookies } from 'next/headers'import { fetchPage, getAbTestingCookie } from 'react-bricks/rsc'
const cookieStore = await cookies()const variantName = getAbTestingCookie({ slug: cleanSlug, locale, cookieStore,})
const page = await fetchPage({ slug: cleanSlug, language: locale, variantName, config,})