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
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
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