Retrieving A/B test variants in C#
Explore how to retrieve active A/B test variants for visitors using the Umbraco Engage C# API.
Retrieving Active A/B test variants
You can retrieve the active A/B test variants for a visitor in different ways depending on your specific scenario:
IAbTestingVisitorService.GetVisitorAbTestVariants(visitorExternalId, contentId, culture, contentTypeId)Namespace:
Umbraco.Engage.Infrastructure.AbTesting.Services.InterfacesRetrieves active A/B test variants on a specific page using numeric IDs, without requiring a request context.
The visitor external id can be retrieved using
IAnalyticsVisitorExternalIdHandler.GetExternalId()
IAbTestingVisitorService.GetVisitorAbTestVariants(visitorExternalId, contentKey, contentTypeKey, culture)Namespace:
Umbraco.Engage.Infrastructure.AbTesting.Services.InterfacesRetrieves active A/B test variants on a specific page using GUID keys, without requiring a request context.
Preferred for new implementations as it uses Umbraco's GUID-based identifiers.
IAbTestVisitorToVariantManager.GetActiveVisitorVariants(visitorExternalId)Namespace:
Umbraco.Engage.Infrastructure.AbTestingRetrieves all active A/B test variants for the given visitor throughout the website.
The visitor external id can be retrieved using
IAnalyticsVisitorExternalIdHandler.GetExternalId()
Example - Getting the A/B test variants for the current visitor
This example demonstrates how to create a service that retrieves the active A/B test variants for a specific visitor, content, and culture variation. The service wraps the IAbTestingVisitorService.GetVisitorAbTestVariants() method, using the current HttpContext and UmbracoContext to obtain the visitor ID and requested content.
Last updated
Was this helpful?