How should I use builder.tests with Next SSR for A/B testing?

Hey! I’m trying to set up A/B testing with Builder and NextJS.
In the examples I could find, only personalization is used.

As I understood from the code, builder.tests.<contentId> cookies should be used for A/B rendering. But I’m struggling with setting them up.

Currently, I pass req and res in builder.get inside getServerSideProps, variations object exists in the model I fetch, but nothing happens with the cookies.

What are you trying to accomplish
I have several questions!

  1. Currently, I have only builderSessionId. What else cookies do I need for A/B tests working and how could I set them up?
  2. What is the desired way of setting builder.tests cookies and using them?
  3. Is there any example of working A/B tests with NextJS or any other framework?

Code I have

export const getServerSideProps: GetServerSideProps = async ({ req, res, params, locale }) => {
  builder.init(process.env.NEXT_PUBLIC_BUILDER_PUBLIC_KEY ?? '', true, req, res);
  const { attributes } = getPersonalizedURL(params?.page || []);
  const result = await builder.get('header-navigation', {req, res, locale, userAttributes });

Thank you a lot!

Hi @khomenok, Welcome to Forum!

I recommend checking out A/B Testing and Personalization with Next.js Edge Middleware and feel free to reach out if this blog doesn’t answer your questions!