Get Variation Name

Get Variation Name

The Get Variation Name API allows you to retrieve the variation assigned to a user for a specific Full Stack A/B experiment without re-evaluating or re-activating the experiment.

This is useful when you want to:

  • Fetch the already assigned variation

  • Apply variation-specific logic at a later point in the user flow

  • Ensure consistency across multiple screens or actions

What this allows you to do  

Using this API, you can:

  • Retrieve the variation already assigned to a user

  • Avoid duplicate experiment activation calls

  • Apply consistent behavior across different parts of your app

  • Safely handle users who are not part of the experiment

When to use Get Variation Name  

You should use this API when:

  • The experiment has already been activated for the user

  • You want to check the assigned variation again

  • You need variation information outside the initial activation flow

If the experiment has not been activated earlier, this API may return null.

Get variation name with user attributes  

User attributes can be passed when retrieving the variation name to ensure audience conditions are evaluated correctly.

KOTLIN

  1. // Create a map to hold user attributes
  2. val userAttributes = mutableMapOf(
  3. "DeviceType" to "Phone",
  4. "OS" to "Android",
  5. "OSVersion" to "14",
  6. "DeviceModel" to "Pixel 8 Pro"
  7. )
  8. // Get the variation name for the user
  9. val variationName = pageSenseClient.getVariationName(
  10. experimentName,
  11. userId,
  12. userAttributes
  13. )
  14. // Handle variation-specific logic
  15. if (variationName == "Original") {
  16. // Handle Original variation
  17. } else if (variationName == "Variation 1") {
  18. // Handle Variation 1
  19. } else if (variationName == "Variation 2") {
  20. // Handle Variation 2
  21. } else if (variationName == "Variation 3") {
  22. // Handle Variation 3
  23. } else {
  24. // User is not part of the experiment
    }

JAVA

  1. import java.util.HashMap;
  2. // Create a map to hold user attributes
  3. HashMap<String, String> userAttributes = new HashMap<>();
  4. userAttributes.put("DeviceType", "Phone");
  5. userAttributes.put("OS", "Android");
  6. userAttributes.put("OSVersion", "14");
  7. userAttributes.put("DeviceModel", "Pixel 8 Pro");
  8. // Get the variation name for the user
  9. String variationName = pageSenseClient.getVariationName(
  10. experimentName,
  11. userId,
  12. userAttributes
  13. );
  14. // Handle variation-specific logic
  15. if ("Original".equals(variationName)) {
  16. // Handle Original variation
  17. } else if ("Variation 1".equals(variationName)) {
  18. // Handle Variation 1
  19. } else if ("Variation 2".equals(variationName)) {
  20. // Handle Variation 2
  21. } else if ("Variation 3".equals(variationName)) {
  22. // Handle Variation 3
  23. } else {
  24. // User is not part of the experiment
  25. }
Parameter

Parameter

Type

Required

Description

experimentName

String

Yes

Name of the Full Stack experiment configured in PageSense.

userId

String

Yes

Unique and stable identifier for the user. Must remain consistent across sessions.

userAttributes

Map<String, String>

No

Optional user attributes used for audience targeting and segmentation.

  

When To Use activateExperiment() vs getVariationName()

Use Case

Recommended Method

First-time evaluation

activateExperiment

Retrieve already assigned variation

getVariationName

 

Get variation name without user attributes  

If no user attributes are available, you can retrieve the variation using only the experiment name and user ID.
Only experiments targeting All Visitors will qualify in this case.

  1. // Get the variation name without user attributes
  2. val variationName = pageSenseClient.getVariationName(
  3. experimentName,
  4. userId
  5. )

How the API Works    

When activateExperiment() method is invoked, it follows a series of steps to determine whether a variation should be assigned to the user:

1. Audience Targeting

The API first checks whether the user meets the experiment’s audience targeting rules defined in PageSense. These rules can include user attributes like browser, device type, OS, or any custom properties passed in the user attributes.
  • If the user’s attributes match the audience targeting conditions, the evaluation proceeds.

  • If they don’t match, the API immediately returns null, indicating the user is not eligible for the experiment.

2. User Storage Service

User Storage Service stores the variation allocated to the users for a given experiment in the user provided storage layer such as Database, Redis Cache or File System. It ensures that the user is always assigned the same variation for a given A/B Test across different sessions and browsers.
  • If a stored variation already exists for the given user Id for the experiment, it is retrieved from the storage and returned.

  • If not, the SDK proceeds to assign a new variation via hashing algorithm.

3. Hashing with MurmurHash

The user ID and the experiment key is combined to form a unique key and the API applies the MurmurHash algorithm to this unique key to produce a deterministic numeric value between 0 and 9999.

This hash value determines the user’s position in the experiment’s traffic allocation range and assign a variation.

  • MurmurHash always generates the same hash value for a given user  ID and  the experiment key combination.

  • This ensures that users always receive a consistent variation assignment across different sessions and browsers.


4. Variation Mapping

Each variation within an experiment is assigned a value range based on its allocated traffic percentage. For example, in an A/B Test experiment with 80% traffic allocation and four variations, each variation being allocated individual traffic split of 25%, the value ranges for the four variations will be assigned as shown below :

Variation

Value Range

Original

0 – 2000

Variation 1

2001 – 4000

Variation 2

4001 – 6000

Variation 3

6001 – 8000

 These ranges are non-overlapping and collectively cover the experiment’s total traffic allocation.

  • If the user’s hash value falls within a particular variation’s range, that variation will be allocated to the user.

  • If the user’s hash value falls outside all assigned ranges for the variations, no variation will be assigned to the user and the user will not qualify for the experiment, and NULL will be returned for the variation.

5. Tracking and Analytics

Once a variation is assigned:
The API triggers the tracking events for the user visit to PageSense, recording the experiment name, user ID, variation name and user attribute details if passed.

6. Return Value  

Outcome

Return Value

User qualifies and variation allocated

Returns the variation name

User does not match the audience targeting rules

Returns NULL

User falls outside traffic allocation

Returns NULL

Important notes  

  • This API does not activate an experiment

  • It only returns the variation already assigned to the user

  • If the user does not qualify or the experiment was never activated, null is returned

  • Always handle the null case safely

Best practices  

  • Activate the experiment once per user session

  • Use getVariationName for subsequent checks

  • Use a stable user identifier for consistent results

  • Pass user attributes only when available