Get Variation Name

Get Variation Name

Overview  

The Get Variation Name API evaluates the specified experiment and returns the variation assigned to the visitor without recording an experiment impression. This API is useful when the application needs to determine the assigned variation without considering the experiment as viewed.

When to Use  

Use Get Variation Name API when you need to retrieve the visitor's assigned variation without activating the experiment. Example scenarios include:
  • Previewing variation assignments.
  • Performing backend decision-making.
  • Experiment activation in the Home page and the variation should be used in other pages
  • Internal application logic that should not record an experiment impression.

Method Signature  

get_variation_name(
    experiment_name: str,
    user_context: PageSenseUserContext
) -> str

Parameters  

Parameter
Type
Required
Description
experiment_name
str
Yes
Name of the FullStack A/B Test experiment.
user_context
PageSenseUserContext
Yes
Visitor information used during experiment evaluation.

Return Value  

Type
Description
str
Returns the assigned variation without recording an experiment impression. Returns an empty string if no variation is assigned.

Usage Example  

from pagesense import PageSenseUserContext
# Create the user attributes
user_attributes = {
    "Browser": "Chrome",
    "Device": "Desktop"
}
# Create the PageSenseUserContext object
user_context = PageSenseUserContext(
    user_id="USER_001",
    user_attributes=user_attributes
)
# Get the Variation details
variation_name = pagesense_client.get_variation_name(
    experiment_name,
    user_context
)

How It Works  

The SDK performs the same visitor evaluation process used by the Activate Experiment API except for tracking the experiment impression event.
  1. Validates the specified experiment.
  2. Evaluates the visitor against the configured audience targeting rules.
  3. Determines whether the visitor falls within the experiment traffic allocation.
  4. Assigns the visitor to a variation using the MurmurHash algorithm for deterministic bucketing.
  5. Returns the assigned variation name.
Unlike Activate Experiment API, this API does not record an experiment impression event.

 Notes  

  • Use a stable visitor identifier to ensure consistent variation assignment.
  • The same PageSenseUserContext should be reused throughout the visitor's request lifecycle.
  • Audience targeting is evaluated using the attributes available in the PageSenseUserContext.
  • The returned variation name can be used to execute variation-specific application logic.