.NET Backend SDK for Feature Experimentation
The Hyppot .NET Backend SDK enables server-side feature experimentation in your .NET applications. This approach is particularly useful for backend logic, API behavior changes, and consistent cross-client experiences.
After you have successfully installed and configured Hyppot, you can start resolving and tracking your experiments:
Resolving Experiments
You can resolve experiments for the user using IExperimentationResolver
defined in Hyppot.Resolving
namespace:
// obtain the resolver from the IoC
var experimentVariant = resolver.ResolveForUser(new ExperimentId("three-columns"), new UserId("user-id"));
Method returns object containing name of the variant and values of all variables defined for experiment if the user is assigned to an experiment or null
otherwise.
You can also obtain all experiments assigned to the user:
resolver.ResolveAll(new UserId("user-id"));
Getting variable values
Resolved experiment object exposes variant variables via Variables
collection property. To get the value of the variable:
// Get the experiment resolver from dependency injection
var resolvedExperiment = resolver.ResolveForUser(
new ExperimentId("your-experiment-id"),
new UserId("user-id")
);
if (resolvedExperiment != null)
{
var columnCount = resolvedExperiment.Variables
.First(x => x.Name == new VariableName("column-count"))
.Value.Get<double>();
}
Impression and conversion tracking
Use the IExperimentTracker
interface from Hyppot.Measurement
namespace to track impressions and conversions:
// track impression when the user sees the experiment
_experimentTracker.TrackImpression(ExperimentImpression.Create(_experimentId,
_variantId, userId, eventDate, deduplicationKey));
// track conversion
_experimentTracker.TrackConversion(
ExperimentConversion.Create("add-to-cart", eventDate, userId, deduplicationKey));
Impressions are deduplicated using either the deduplication key or by user ID within the impression length window (by default, 24 hours). This prevents the same user from being counted multiple times in a short period. To learn more about impression and conversion tracking, see the tracking experiment data section.
Adding metrics to conversions
To define metrics for a conversion:
using Hyppot.Measurement;
// ...
var metrics = new VariableInstance[] {
new VariableInstance(
new VariableName("revenue"),
new VariableValue<double>(125.50)
),
new VariableInstance(
new VariableName("product-type"),
new VariableValue<string>("electronics")
),
new VariableInstance(
new VariableName(""),
new VariableValue<bool>(true)
)
};
await tracker.TrackConversionAsync(
ExperimentConversion.Create(
"purchase-completed",
DateTime.UtcNow,
"user-id",
deduplicationKey: null,
metrics: metrics
)
);