The Full Stack Developer Guide Developer Hub

Welcome to the Full Stack Developer Guide developer hub. You'll find comprehensive guides and documentation to help you start working with the Full Stack Developer Guide as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    

Activates an A/B test for the specified user to start an experiment: determines whether they qualify for the experiment, buckets a qualified user into a variation, and sends an impression event to Optimizely.

Version

3.1.1

Description

This method requires an experiment key, user ID, and (optionally) attributes. The experiment key must match the experiment key you created when you set up the experiment in the Optimizely app. The user ID string uniquely identifies the participant in the experiment.

If the user qualifies for the experiment, the method returns the variation key that was chosen. If the user was not eligible—for example, because the experiment was not running in this environment or the user didn't match the targeting attributes and audience conditions—then the method returns null.

Activate respects the configuration of the experiment specified in the datafile. The method:

  • Evaluates the user attributes for audience targeting.
  • Includes the user attributes in the impression event to support results segmentation.
  • Hashes the user ID or bucketing ID to apply traffic allocation.
  • Respects forced bucketing and whitelisting.
  • Triggers an impression event if the user qualifies for the experiment.

Activate also respects customization of the SDK client. Throughout this process, this method:

  • Logs its decisions via the logger.
  • Triggers impressions via the event dispatcher.
  • Raises errors via the error handler.
  • Remembers variation assignments via the User Profile Service.
  • Alerts notification listeners, as applicable.

Note

For more information on how the variation is chosen, see How bucketing works.

Parameters

The parameter names for Python are listed below.

Parameter
Type
Description

experiment_key
required

string

The experiment to activate.

user_id
required

string

The user ID.

attributes
optional

map

A map of custom key-value string pairs specifying attributes for the user that are used for audience targeting and results segmentation. Non-string values are only supported in the 3.0 SDK and above.

Returns

Variation key representing the variation in which the user will be bucketed. None if user is not in experiment or if experiment is not running.

Example

attributes = {
  'device': 'iPhone',
  'lifetime': 24738388,
  'is_logged_in': True,
}

variation_key = optimizely_client.activate('my_experiment_key', 'user_123', attributes)

Side effects

The table lists other other Optimizely functionality that may be triggered by using this method.

Functionality
Description

Impressions

Accessing this method triggers an impression if the user is included in an active A/B test.

See Implement impressions for guidance on when to use Activate versus Get Variation.

Notification Listeners

In SDKs v3.0 and earlier: Activate invokes the ACTIVATE notification listener if the user is included in an active A/B test.

In SDKs v3.1 and later: Invokes the DECISION notification listener if this listener is enabled.

Notes

Activate versus Get Variation

For details on whether to use Activate or Get Variation, see Activate versus Get Variation.

Source files

The language/platform source files containing the implementation for Python is optimizely.py.

Updated 9 months ago


Activate


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.