Overview
The Activate Experiment API evaluates a visitor against the specified FullStack A/B Test experiment, assigns the visitor to a variation, records an experiment impression event in the PageSense server, and returns the assigned variation name.
If the visitor satisfies the experiment's audience targeting rules and traffic allocation criteria, the SDK uses the MurmurHash algorithm to deterministically assign the visitor to one of the configured variations. This ensures sticky visitor assignment, so the same visitor consistently receives the same variation across multiple requests. Once assigned, the same variation is consistently returned for the visitor across subsequent evaluations. Use this API when your application is ready to serve the experiment experience to the visitor.
When to Use
Call Activate Experiment API before rendering or executing variation-specific application logic. Typical use cases include:
Displaying different UI layouts
Serving different recommendation algorithms
Enabling or disabling application functionality
Personalizing application experiences
Method Signature
activate_experiment(
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 for experiment evaluation and variation assignment. |
Return Value
Type | Description |
str | Returns the variation assigned to the visitor. Returns an empty string if the visitor does not qualify for the experiment or 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
)
# Activate the Experiment
variation_name = pagesense_client.activate_experiment(
experiment_name,
user_context
)
How It Works
When Activate Experiment is called, the SDK performs the following operations:
Validates the specified experiment.
Evaluates the visitor against the configured audience targeting rules.
Determines whether the visitor falls within the experiment traffic allocation.
Assigns the visitor to a variation using the MurmurHash algorithm for deterministic bucketing.
Records an experiment impression event in the PageSense server.
Returns the assigned variation name.
The SDK uses the MurmurHash algorithm to generate a deterministic hash value based on the visitor identifier and experiment combination. This ensures that the same visitor is consistently assigned to the same variation for a given experiment, providing a reliable and sticky experimentation experience across multiple requests and application sessions. The SDK performs experiment evaluation locally using the synchronised in-memory project configuration.
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.