AI agents: the content index is at /llms.txt. Every page is also available as Markdown — send the request header Accept: text/markdown, or append .md to the page URL.
Xperience Docs

Cookie consent

We use necessary cookies (opens in a new tab) to run our website and improve your experience while browsing. Additional cookies are only used with your consent. You may revoke your consent on the Cookies Policy (opens in a new tab) page or in your browser at any time.

Configure (opens in a new tab)
  • Documentation
    InstallationUsing the Xperience interfaceDeveloping websitesConfiguring XperienceManaging usersSecuring websitesDeploying websitesManaging website contentMultilingual websitesMacro expressionsExternal utilitiesIntegrating 3rd party systemsCustom developmentE-commerce featuresOn-line marketing featuresRelease notes - Xperience 13Xperience terminology glossary
  • Tutorial
    Using the Xperience interfaceDeveloper tutorialBusiness tutorialResource hub for marketers
  • API Examples
    ConfigurationContent managementDevelopmentE-commerceOn-line marketingSocial media
  1. Home
  2. On-line marketing
  3. A/B testing

A/B testing


Was this page helpful?

Send us feedback Go back to top
  • Community Questions & Answers (opens in a new tab)
  • Contact support (opens in a new tab)

List of examples:

  • A/B tests
    • Creating an A/B test
    • Configuring conversions for an A/B test
    • Starting an A/B test
    • Deleting an A/B test
  • A/B test page variants
    • Getting variants for a page
    • Adding a variant
    • Renaming a variant
    • Deleting a variant
    • Selecting a variant as the A/B test winner

A/B tests

Creating an A/B test

C#
// Gets a page to A/B test
TreeNode page = new DocumentQuery<TreeNode>()
                        .Path("/LandingPage", PathTypeEnum.Single)
                        .OnSite("MySite")
                        .Culture("en-us")
                        .TopN(1)
                        .FirstOrDefault();

if (page != null)
{
    // Gets an instance of the A/B test management service
    var abTestManager = Service.Resolve<IABTestManager>();

    // Creates a new A/B test for the page
    abTestManager.CreateABTest(page);

    // Creates the original page variant for the A/B test and an additional variant
    // (both have content identical to the original page)
    abTestManager.AddVariant(page, null);

    // Saves the new variant configuration into the page
    page.Update();
}
> Back to list of examples

Configuring conversions for an A/B test

C#
// Gets the A/B test created for the "/LandingPage" page
ABTestInfo test = ABTestInfo.Provider.Get()
                            .WhereEquals("ABTestOriginalPage", "/LandingPage")
                            .OnSite("SiteCodeName")
                            .TopN(1)
                            .FirstOrDefault();

if (test != null)
{
    // Prepares a conversion definition of the 'Purchase' conversion type, using the default conversion Value
    var purchaseConversion = new ABTestConversion(ABTestConversionNames.PURCHASE);

    // Prepares a conversion definition of the 'Page visit' conversion type
    // Sets the conversion's Page URL to '/SpecialOffers' and the Value to 5
    var pageVisitConversion = new ABTestConversion(
                                    conversionName: ABTestConversionNames.PAGE_VISIT,
                                    relatedItemIdentifier: "/SpecialOffers",
                                    value: 5
                                );

    // Gets the A/B test's conversion configuration
    ABTestConversionConfiguration testConversionConfig = test.ABTestConversionConfiguration;

    // Adds the defined conversions to the configuration
    testConversionConfig.AddConversion(purchaseConversion);
    testConversionConfig.AddConversion(pageVisitConversion);

    // Saves the updated test
    ABTestInfo.Provider.Set(test);
}
> Back to list of examples

Starting an A/B test

C#
// Gets the A/B test created for the "/LandingPage" page
ABTestInfo test = ABTestInfo.Provider.Get()
                            .WhereEquals("ABTestOriginalPage", "/LandingPage")
                            .OnSite("MySIte")
                            .TopN(1)
                            .FirstOrDefault();

// Checks that the test exists and is not already running
// Starts the test at the current time if it is scheduled to start in the future
if ((test?.ABTestOpenFrom == DateTime.MinValue) || (test?.ABTestOpenFrom > DateTime.Now))
{
    // Configures the test to start at the current time and end in a month
    test.ABTestOpenFrom = DateTime.Now;
    test.ABTestOpenTo = DateTime.Now.AddMonths(1);

    // Saves the test - the test automatically switches to the Running status when the start time is in the past
    ABTestInfo.Provider.Set(test);
}
> Back to list of examples

Deleting an A/B test

C#
// Gets the A/B test created for the "/LandingPage" page
ABTestInfo test = ABTestInfo.Provider.Get()
                            .WhereEquals("ABTestOriginalPage", "/LandingPage")
                            .OnSite("MySite")
                            .TopN(1)
                            .FirstOrDefault();

if (test != null)
{
    // Gets an A/B tested page
    TreeNode page = new DocumentQuery<TreeNode>()
                            .Path("/LandingPage", PathTypeEnum.Single)
                            .OnSite("MySite")
                            .Culture("en-us")
                            .TopN(1)
                            .FirstOrDefault();

    if (page != null)
    {
        // Deletes the A/B test
        ABTestInfo.Provider.Delete(test);

        // Clears the A/B testing variant configuration of the related page
        page.SetValue("DocumentABTestConfiguration", null);
        page.Update();
    }
}
> Back to list of examples

A/B test page variants

Getting variants for a page

C#
// Gets an A/B tested page
TreeNode page = new DocumentQuery<TreeNode>()
                        .Path("/LandingPage", PathTypeEnum.Single)
                        .OnSite("MySite")
                        .Culture("en-us")
                        .TopN(1)
                        .FirstOrDefault();

if (page != null)
{
    // Gets an instance of the A/B test management service
    var abTestManager = Service.Resolve<IABTestManager>();

    // Gets a collection of the page's A/B testing variants
    var variants = abTestManager.GetVariants(page);

    // Gets the variant named "Variant B"
    IABTestVariant variantB = variants.Where(x => x.Name == "Variant B").FirstOrDefault();
}
> Back to list of examples

Adding a variant

C#
// Gets an A/B tested page 
TreeNode page = new DocumentQuery<TreeNode>()
                        .Path("/LandingPage", PathTypeEnum.Single)
                        .OnSite("MySite")
                        .Culture("en-us")
                        .TopN(1)
                        .FirstOrDefault();

if (page != null)
{
    // Gets an instance of the A/B test management service
    var abTestManager = Service.Resolve<IABTestManager>();

    // Gets the page's first existing A/B test variant
    IABTestVariant existingVariant = abTestManager.GetVariants(page)
                                                  .FirstOrDefault();

    // Creates a new variant for the given page
    // The variant's content is copied from the existing variant and can later be adjusted in the Pages application
    // The name of the new variant is generated automatically
    abTestManager.AddVariant(page, existingVariant?.Guid);

    // Saves the new variant configuration into the page
    page.Update();
}
> Back to list of examples

Renaming a variant

C#
// Gets an A/B tested page 
TreeNode page = new DocumentQuery<TreeNode>()
                    .Path("/LandingPage", PathTypeEnum.Single)
                    .OnSite("MySite")
                    .Culture("en-us")
                    .TopN(1)
                    .FirstOrDefault();

if (page != null)
{
    // Gets an instance of the A/B test management service
    var abTestManager = Service.Resolve<IABTestManager>();

    // Gets the variant named "Variant B"
    IABTestVariant variantB = abTestManager.GetVariants(page).Where(x => x.Name == "Variant B").FirstOrDefault();

    if (variantB != null)
    {
        // Renames the variant to "Renamed variant"
        abTestManager.RenameVariant(page, variantB.Guid, "Renamed variant");

        // Saves the new variant configuration into the page
        page.Update();
    }
}
> Back to list of examples

Deleting a variant

C#
// Gets an A/B tested page
TreeNode page = new DocumentQuery<TreeNode>()
                    .Path("/LandingPage", PathTypeEnum.Single)
                    .OnSite("MySite")
                    .Culture("en-us")
                    .TopN(1)
                    .FirstOrDefault();

if (page != null)
{
    // Gets an instance of the A/B test management service
    var abTestManager = Service.Resolve<IABTestManager>();

    // Gets the variant named "Variant B"
    IABTestVariant variantB = abTestManager.GetVariants(page).Where(x => x.Name == "Variant B").FirstOrDefault();

    if (variantB != null)
    {
        // Deletes the variant
        abTestManager.RemoveVariant(page, variantB.Guid);

        // Saves the new variant configuration into the page
        page.Update();
    }
}
> Back to list of examples

Selecting a variant as the A/B test winner

C#
// Gets the A/B test created for the "/LandingPage" page
ABTestInfo test = ABTestInfo.Provider.Get()
                            .WhereEquals("ABTestOriginalPage", "/LandingPage")
                            .OnSite("SiteCodeName")
                            .TopN(1)
                            .FirstOrDefault();

if (test != null)
{
    // Gets an A/B tested page
    TreeNode page = new DocumentQuery<TreeNode>()
                            .Path("/LandingPage", PathTypeEnum.Single)
                            .OnSite("MySite")
                            .Culture("en-us")
                            .TopN(1)
                            .FirstOrDefault();

    if (page != null)
    {
        // Gets an instance of the A/B test management service
        var abTestManager = Service.Resolve<IABTestManager>();

        // Gets the variant named "Variant C"
        var variant = abTestManager.GetVariants(page).Where(x => x.Name == "Variant C").FirstOrDefault(); ;

        // Checks whether the A/B test is finished
        // An error occurs if you attempt to select a winner for an unfinished test
        if (ABTestStatusEvaluator.ABTestIsFinished(test) && variant != null)
        {
            // Selects "Variant C" as the A/B test winner
            // Automatically updates the page's widget and page template configuration,
            // and clears the A/B testing variant configuration
            abTestManager.PromoteVariant(page, variant.Guid);

            // Saves the cleared A/B testing variant configuration into the page
            page.Update();
        }
    }
}
> Back to list of examples