BETA
This feature is currently in beta, and only available starting v2.7.4. Validate the functionality before pushing to production.
A/B testing allows you to optimize the performance of your consent banner.
Enabling A/B testing
Go to the Implementation section in your Configuration Dashboard and select the A/B Testing tab. Here you will find a toggle to enable the feature.

Once enabled, you will see the A/B testing configuration options.
Using Usercentrics
Activate with Usercentrics
To use Usercentrics for A/B testing, under Settings select Activate with Usercentrics.
Defining variants
Using the JSON input field, define the variants names with an empty values.
{
"variantA": {},
"variantB": {}
}Now, in your project, fetch the variant names programmatically, and return a Banner Configuration for each one using the BannerSettings object:
switch UsercentricsCore.shared.getABTestingVariant() {
case "variantA": return BannerSettings(/* variantA configuration */)
case "variantB": return BannerSettings(/* variantB configuration */)
default: return BannerSettings(/* default configuration */)
}val bannerSettings = when (Usercentrics.instance.getABTestingVariant()) {
"variantA" -> BannerSettings(/* variantA configuration */)
"variantB" -> BannerSettings(/* variantB configuration */)
else -> BannerSettings(/* default configuration */)
}final variant = await Usercentrics.aBTestingVariant;
switch(variant) {
case "variantA": {_showFirstLayer(/* variantA Settings */);}
break;
case "variantB": {_showFirstLayer(/* variantB Settings */);}
break;
default: {_showFirstLayer(/*Default*/);}
break;
} const variant = await Usercentrics.getABTestingVariant()
let bannerSettings: BannerSettings;
switch (variant){
case "variantA":
return bannerSettings = {/* settings for the banner with variantA */};
case "variantB":
return bannerSettings = {/* settings for the banner with variantB */};
default:
return bannerSettings = {/* default banner settings*/};string variant = Usercentrics.Instance.getABTestingVariant();
var bannerSettings = new BannerSettings(variantName: variant);
switch(variant) {
case "variantA":
Usercentrics.Instance.ShowFirstLayer(bannerSettings, (userResponse) => {
// Handle userResponse
});
break;
case "variantB":
Usercentrics.Instance.ShowFirstLayer(bannerSettings, (userResponse) => {
// Handle userResponse
});
break;
default:
Usercentrics.Instance.ShowFirstLayer(bannerSettings, (userResponse) => {
// Handle userResponse
});
break;
}Always fall back to a default
Always have a default fallback configuration. This will allow you to turn off or change the variants you are testing dynamically.
Even distribution
The distribution between variants will be even. Example: 50:50 for two variants, 33:33:33 for three variants.
Tracking results
Once you have generated variant interactions, all results will be available in the Analytics section of the Admin Interface.
Interaction Analytics
Overview your Interaction and Acceptance rates by filtering for specific Variants.

Comparison Analytics
Get a direct comparison of interactions and acceptance rates for each variant.

Download Raw Data
For in-depth insights and custom analysis, we recommend downloading a raw-data report available at the bottom of the Interaction Analytics section. In this report, an additional "variant" column will tell you which variant was used for each entry in the data.

Keep A/B Testing feature ON
To see variant analytics data, the A/B Testing feature needs to be ON. If you wish to stop running specific variants. Just delete the variants in the JSON input field.
Using a third-party tool
Activate with third-party tool
To use a third-party tool for A/B testing, select the Activate with third-party tool checkbox at the bottom of the A/B testing configuration options.
Defining variants
When using a third-party tool, you may pass variant names directly to UsercentricsCore:
let variant = AnyABTestTool.getVariants()
switch variant {
case "variantA": return BannerSettings(/* variantA configuration */ variantName: "variantA")
case "variantB": return BannerSettings(/* variantA configuration */ variantName: "variantB")
default: return BannerSettings(/* default configuration */)
}val variant = AnyABTestTool.getVariants()
val bannerSettings = when (variant) {
"variantA" -> BannerSettings(variantName = "variantA", /* variantA configuration */)
"variantB" -> BannerSettings(variantName = "variantB", /* variantB configuration */)
else -> BannerSettings(/* default configuration */)
}final variant = await AnyABTestTool.aBTestingVariant;
switch(variant) {
case "variantA": {_showFirstLayer(/* variantA Settings */);}
break;
case "variantB": {_showFirstLayer(/* variantB Settings */);}
break;
default: {_showFirstLayer(/*Default*/);}
break;
} const variant = await AnyABTestTool.getABTestingVariant()
let bannerSettings: BannerSettings;
switch (variant){
case "variantA":
return bannerSettings = {/* settings for the banner with variantA */};
case "variantB":
return bannerSettings = {/* settings for the banner with variantB */};
default:
return bannerSettings = {/* default banner settings*/};string variant = AnyABTestTool.aBTestingVariant;
var bannerSettings = new BannerSettings(variantName: variant);
switch(variant) {
case "variantA":
Usercentrics.Instance.ShowFirstLayer(bannerSettings, (userResponse) => {
// Handle userResponse
});
break;
case "variantB":
Usercentrics.Instance.ShowFirstLayer(bannerSettings, (userResponse) => {
// Handle userResponse
});
break;
default:
Usercentrics.Instance.ShowFirstLayer(bannerSettings, (userResponse) => {
// Handle userResponse
});
break;
}Supporting your programmatic UI
If you have your own UI and you want Usercentrics to know which A/B Testing variant from your Third-Party Tool you are using, so that the events you track in the Usercentrics analytics API (track()) have the variant data. Then you have to inject the variant programmatically with this API:
UsercentricsCore.shared.setABTestingVariant(variant: <VariantName>)Usercentrics.instance.setABTestingVariant(<VariantName>)UsercentricsCore.setABTestingVariant(variant: <VariantName>)Usercentrics.setABTestingVariant(<VariantName>)Usercentrics.Instance.setABTestingVariant(variant: <VariantName>)Tracking results
Implement the tracking mechanism of your third-party tool, when processing the UsercentricsConsentUserResponse, available in the callback of the banner presentation.