When the GetVariationName API is invoked, it follows a structured process to determine whether a variation should be allocated to the user. Below is a detailed breakdown of this process:
Audience Targeting
The API first evaluates whether the user qualifies for the experiment based on audience targeting conditions defined during experiment configuration. These conditions are typically based on user attributes such as browser, device type, operating system, or any custom user data passed in the userAttributes.
- If the user’s attributes match the audience targeting conditions, the API proceeds to the next step.
- If the user does not meet these conditions, the API immediately returns null, indicating that the user is not eligible to be included in the experiment.
User Storage Service
Next, the API checks whether the User Storage Service is enabled. This service helps ensure consistency in variation assignments for the user by remembering previously assigned variations for users across multiple sessions.
- If a variation has already been assigned and stored for the user in the User Storage Service, the API retrieves and returns that stored variation.
- If no stored variation exists, the API proceeds to allocate a new variation using the bucketing logic described below.
Hashing with MurmurHash
The next step is to determine if the user qualifies for the experiment based on the experiment’s traffic allocation settings.
- The API applies the MurmurHash algorithm to the user's ID (userId). This hashing algorithm consistently generates a unique numeric value between 0 and 9999 for each user ID, which serves as the user's hash value.
- MurmurHash algorithm always generate the same hash value for the User ID for a given experiment across different sessions. This ensures deterministic and sticky variation assignment to the user for a given experiment.
Variation Mapping
Each variation within the experiment is assigned a specific range of hash values that corresponds to the variation’s allocated traffic percentage.
For example:
- "Original" variation is assigned a hash range from 0–2000
- "Variation 1" is assigned a hash range from 2001–4000
- "Variation 2" is assigned a hash range from–6000 and so on.
These hash ranges are non-overlapping, ensuring a single variation is assigned per user and is collectively exhaustive, covering the entire allocated traffic range of the experiment.
The API checks if the user’s hash value falls within any of these defined ranges:
- If it does, the corresponding variation is allocated to the user.
- If the hash value falls outside all assigned ranges, it means the user is not within the experiment’s traffic allocation, and null is returned.
Return Value
- If the user qualifies for the experiment and a variation is successfully allocated, the API returns the name of the variation allocated.
- If the user fails to qualify for the experiment at any stage, the API returns null.
Using GetVariationName without user attributes
The GetVariationName API may also be invoked without providing any user attributes. The following code demonstrates how to call the API without passing any user attribute parameters.
Method
string variationName = pageSenseClient.GetVariationName(experimentName, userId);
Parameter details:
Parameter | Type | Description |
experimentName | String | The name of the experiment to activate. |
userId | String | A unique identifier for the user. |