Explore how to retrieve active A/B test variants for visitors using the Umbraco Engage C# API.
You can retrieve the active A/B test variants for a visitor in different ways depending on your specific scenario:
IAbTestingService.GetCurrentVisitorActiveAbTestVariants()
Namespace: Umbraco.Engage.Web.AbTesting
Returns the active variants for the current visitor on the current page.
Can only be used with an active request context
IAbTestingVisitorService.GetVisitorAbTestVariants(visitorExternalId, pageId, culture, contentTypeId)
Namespace: Umbraco.Engage.Business.AbTesting
Retrieves active A/B test variants on a specific page, without requiring a request context.
The visitor external id can be retrieved using IAnalyticsVisitorExternalIdHandler.GetExternalId()
IAbTestVisitorToVariantManager.GetActiveVisitorVariants(visitorExternalId)
Namespace: Umbraco.Engage.Business.AbTesting
Retrieves all active A/B test variants for the given visitor throughout the website.
The visitor external id can be retrieved using IAnalyticsVisitorExternalIdHandler.GetExternalId()
To use these services, inject the specified service into your code. The example below uses IAbTestingService.GetCurrentVisitorActiveAbTestVariants()
by injecting the service into a controller:
Umbraco Engage offers multiple ways for performaing A/B tests on your website.
Learn more about each option and how to configure them in the Marketing and Editors A/B Testing section.