A/B testing identifiers

I am conducting an A/B test experiment and I need to identify which variation is currently being used. How can I do this from within my codebase?

Hi @yuval222,

Which variation is going to serve is decided on the client side but you can certainly configure your code to access it in the content object as shown below

 import { BuilderComponent } from '@builder.io/react'

 <BuilderComponent 
   model="page" 
   contentLoaded={(data, content) => {
   amplitude.track('builderImpression', {
      contentId: content.id,
      contentName: content.name,
      testVariationId: content.testVariationId,
      // Make sure to edit the variant name in Builder with a descriptive name
      testVariationName: content.testVariationName
     })
   }
 />

You can find more about this at Using Builder with Customer Data Platforms - Builder.io

Hi @manish-sharma

Im printing the content object and get this:

{
  "id": "0889bbd7a4a740449b24830bd48f60e1",
  "data": {
      "inputs": [],
      "themeId": false,
      "previewLink": "http://localhost:3000",
      "noIndex": true,
      "title": "Marble Life | Wills",
      "blocks": [
        // ...
      ]
  }
}

i dont see any information regarding the ab test variartion

any idea?

Just a question @neri , are you using SSG/ISR or SSR for this page? FWIW, I’ve found that using SSR for pages with advanced logic (like A/B Testing) is far more reliable as it’s not a static page that gets overridden by client logic after it’s been pre-generated.

@chtbks-jason We use SSG/ISR. We use builder.io for our landing pages which are static pages so there’s no reason to use SSR

Thanks for the Tip :slight_smile:

Is this still up to date ? My content object doesn’t contain testVariationId or testVariationName.

Hello,
I thing variation of your A/B test is currently active within your codebase, you can utilize tracking mechanisms tailored to differentiate between variations. You can try this methods such as storing variation assignments in cookies or local storage for web applications, using distinct URL parameters for each variation, or leveraging session data or user profiles for authenticated users.
Thanks

Hi Yuval,

To identify which variation is currently being used in an A/B test experiment, you can track this within your codebase by utilizing JavaScript and the dataLayer or by storing the variation information in session/local storage. Here’s an approach:

  1. Using JavaScript to detect the variation:
  • If you’re using an A/B testing tool like Optimizely or Convert, they typically provide a JavaScript API to get the current variation. For example, in Optimizely, you could use optimizely.get('state').getActiveExperimentIds() to retrieve the active variation.
  1. Storing the variation in session or local storage:
  • You can store the variation in the sessionStorage or localStorage to persist the choice across the user’s session or visits. Here’s a simple code snippet:

javascript

Copy

sessionStorage.setItem('currentVariation', 'Variation A'); // Set this based on the experiment
const currentVariation = sessionStorage.getItem('currentVariation');
console.log(`The current variation is: ${currentVariation}`);
  1. Using Google Tag Manager:
  • You can push the active variation into the dataLayer and capture it using Google Tag Manager for further analysis or tracking.

Let me know if you’d like further details on the implementation.

As part of our A/B testing services, Team Brillmark offers tailored solutions to help optimize your conversion rates. Feel free to check out our services here: (A/B Test Development | BrillMark).

Best regards,
Team Brillmark"