Skip to main content

We are currently experiencing an issue that is preventing customers from submitting support tickets. Please contact us at (866) 819-4486 if you need immediate assistance.

Optimizely Knowledge Base

Activation Mode: Activating an experiment dynamically after a page has loaded

relevant products:
  • Optimizely X Web Experimentation
  • Optimizely X Web Personalization
  • Optimizely Classic

This article will help you:
  • Activate an experiment or campaign dynamically after a page has loaded
  • Identify use cases for manual and conditional activation
  • Use Optimizely's Manual Activation mode to "re-run" Optimizely when an action is triggered
  • Use Optimizely's Conditional Activation mode to activate an experiment dynamically

By default, all Optimizely experiments are evaluated as soon as the Optimizely code snippet is loaded on the page, which means that a visitor must meet URL and Audience targeting at this point in the page load. Once a visitor is bucketed into an experiment, the actual code to change any elements on the page will run as soon as those elements appear in the DOM. To control when certain code changes run, see our article on how Optimizely evaluates code changes.

There are often times, however, where you may want to wait until a later point in time to activate your experiment. If your page displays dynamically-loaded content, for example, you may wish to activate an experiment after the page has loaded. You can do so by setting the experiment's activation mode to either Manual or Conditional


Manual Activation is available to all plan types. Mobile manual activation is outlined in our mobile SDK article. Conditional Activation is available to Enterprise customers only. If you're trying to activate an experiment conditionally, consider upgrading to our Enterprise plan, or use our workaround below.

Manual mode experiments are activated via the Optimizely JavaScript Activation API, and Conditional mode experiments accept a code condition that Optimizely uses to evaluate to determine when to activate the experiment.

Why would you use Manual Activation Mode?

  • You're easily able to deploy the Optimizely API call code to your site and would prefer calling activate from within your native JavaScript for finer-tuned control
  • Your site is set up such that all experiments need to be manually activated at some time after Optimizely loads
  • A very specific action must be taken on the page to activate an experiment, and that action can only be captured from within your site's native code

Why would you use Conditional Activation Mode? (Enterprise plan feature)

  • Your site is built on a single page app framework (like Angular.js or Ember.js) and you want to activate an experiment based on an event fired by that framework.
  • A visitor must take certain actions on a page before being bucketed into an experiment, such as triggering a modal, scrolling to a certain point, or activating a widget or other dynamic module
  • There is an AJAX request that happens long after the page has finished loading, and that AJAX request returns new content that needs to be modified

Do you need Manual/Conditional Activation?

If you're wondering whether Manual or Conditional Activation will be the solution to your issue, consider whether these telltale signs apply to you:

  • You’re testing a multi-step form, which appears in a modal and uses a “Next” button but doesn’t load a new page.
  • You’re testing a web application, which re-renders the page when visitors perform certain actions, but doesn’t re-load the page.
  • You’re testing an e-commerce site and want to run an experiment when customers modify the product.
  • You’re running an experiment that changes an object that appears at a certain scroll depth.
  • You need to run experiments on an AJAX site, where elements are dependent on ajaxComplete
  • You’re running an experiment on a site using Angular, Backbone, Ember, or Knockout.
An extremely common sign that your experiment might need manual or conditional activation is when you make changes to an element, the changes appear correctly in the Editor, but when the experiment runs live, you don't see your changes.
Here's what's going on:
  • When a visitor arrives at your experiment page, the Optimizely snippet executes immediately and tries to run the variation code. However, because the new element hasn't been triggered to appear, the selectors for this element do not exist yet on the page. 
  • Optimizely cannot make changes to the element if the selectors cannot be found on the page.
  • By the time a visitor clicks on the button to trigger the element, the Optimizely snippet has already finished executing and has stopped trying to find the selectors.

Change activation mode in Optimizely Classic

To change an experiment's activation mode in Optimizely Classic, go to the Editor, then click Options > Activation Mode.  Select Manual or Conditional.

Change activation mode in Optimizely X

In Optimizely X, activation modes apply to each page. You'll set the activation mode when you create or edit a page. Select ImmediatelyPollingCallback, or Manual. Polling and Callback expand on the functionality of Conditional Activation in Classic Optimizely by giving you more options.


Manual Activation Mode Configuration

Changing the Activation Mode to Manual will show you a bit of code that needs to be executed on your page at the time you want the experiment to start running.

In Optimizely Classic:

In Optimizely X:

That line of code tells Optimizely to execute the experiment manually. 

To activate all manual experiments on a given page, you can delete the parameter with the experiment ID, so that the call looks like this:

window.optimizely = window.optimizely || [];

This API call will activate any running manual experiments whose targeting conditions are satisfied by the current visitor on this page. You can also activate a specific running (manual) experiment like this:

window.optimizely = window.optimizely || [];
window.optimizely.push(["activate", EXPERIMENT_ID]);

This EXPERIMENT_ID will appear on the Activation Mode dialog for this experiment.


window.optimizely.push(["activate",12345]); would activate experiment 12345, but not any other experiments that are set to be activated manually. When the Optimizely snippet is on a page and the activation API call fires then the normal process of running the experiment will begin. The activation call can be triggered as many times as necessary, so if there are multiple pages that get rendered using AJAX then you can run the experiment each time new content loads.

Conditional Activation Mode Configuration

Conditional activation mode is available on Enterprise plans.

Changing the activation mode to conditional will show a code input box to enter in the code condition that will be evaluated to determine when to activate your experiment.

In Optimizely X, select Polling or Callback and Optimizely will generate sample code for you.

In Optimizely Classic, you'll need to enter your own code:

  • Polling Type: Any code condition entered which does not evaluate as a function will be treated as a polling type, meaning Optimizely will poll every 50ms for this condition to evaluate as truthy, upon which the experiment will be activated.

  • Function Type: Any code condition which does evaluate as a function will be treated as a function type, meaning the function entered will be called immediately when the snippet loads and will need to activate the experiment using the provided callback when necessary.

Function Type Usage:

When using the function type of conditional activation, Optimizely will expect a function entered with the following type definition, passing an activation function and an options object as arguments:

 * Conditional Activation Function
 * @param {Function} activate - Activate this experiment
 * @param {Object=} options {
 *                    isActive : {Boolean} - Current activation status
 *                    experimentId : {Integer} - This experiment's Id
 *                  } 
function(activate, options) {
  // Do some logic
  if (/* CONDITION */) {


Here is a simple example of using the function type to activate an experiment after an AJAX call is made. See our developer site for several additional use cases:

 * Condition: Activate when an Ajax load contains my element
 *            and the experiment is not already active
function(activate, options) {
  $(document).ajaxComplete(function(event, xhr, settings) {
    if (xhr.responseText.indexOf('rightRailModule') != -1 &&
        !options.isActive) {

The above code will work if you are including the full jQuery library in your Optimizely snippet (find this option in the JavaScript settings for your project). If you have opted to include a trimmed version of jQuery in your snippet, but your own jQuery is included on your website, make sure that this function is scoped to the window level, by adding the window. prefix like so: window.$(document).ajaxComplete

This is because the trimmed version of jQuery, which is by default included in the Optimizely Snippet, does not include the ajaxComplete method. This method will only work with the full jQuery library.

Which method should you use, polling or function? See below:

Polling Type Use Cases: 

  • Activate an experiment when a DOM element appears
  • Activate an experiment based on JavaScript variables or metadata that load after the Optimizely Snippet
  • Activate an experiment based on a dynamically changing variable or DOM element

Function Type Use Cases:

  • Activate an experiment everytime a specific AJAX call returns
  • Activate an experiment everytime a single page app changes pages
  • Activate an experiment everytime a modal pops up

If you're conditionally activating a multi-page experiment, make sure that the conditional activation will work for every page. Otherwise, it will activate only on one page of the experiment.

Activate an experiment when you don't have access to your site's code

Sometimes you'll want to set up Manual Activation, but you don't have access to your site's code. Or, if you want to set up Conditional Activation and aren't on an Enterprise plan, you'll need a workaround to get the experiment to activate.

If you aren't able to place the manual activation calls on your site directly, you can "bootstrap" an experiment that will run on pageload and bind the activate call(s) to the desired event(s). In other words, you can use an experiment to populate the manual activation calls, then use a second experiment to make the changes that you want to test.

Here's how to set this "bootstrap experiment" up:

  1. Create your manually activated experiment as normal.
  2. Create a new experiment with 100% of traffic allocated to one variation.
  3. Make sure that the new experiment's URL Targeting and Audience conditions match the original, manually activated experiment's conditions.
  4. In the variation where you're directing traffic, open the Edit Code box and paste in one of the following code snippets, depending on whether you want to activate the original experiment on ajaxComplete or a click event.
  5. If you're binding to a click event, use this code:
    //Click Event: 
    $('SELECTOR').bind('click', function() { 
     window.optimizely.push(["activate", XXXXXXX]); 
    Make sure to replace XXXXXXX with the experiment ID of the manually activated experiment (not the new bootstrap experiment), and replace SELECTOR with the actual selector you want to bind to.
  6. If you're binding to ajaxComplete, use this code:
    $(document).ajaxComplete(function() { 
     window.optimizely.push(["activate", XXXXXXX]); 

    Note that this will activate the experiment upon completion of every AJAX request. If you have many AJAX requests on your site, you'll want to pass in an argument specifying which AJAX request to listen for.
  7. Now, start both experiments.

Miscellaneous Notes

  • A manually or conditionally activated experiment will only activate as a result of these API calls if the experiment is running AND the current visitor and the current page satisfy the experiment's targeting conditions.
  • An experiment may be activated more than once.
  • A visitor satisfying a manual experiment's targeting conditions will only be bucketed for that experiment when it is activated.
  • You do not need to activate the experiment on pages used as goals.
  • If you're running a multi-page experiment across a combination of JavaScript-driven content and normal HTML pages, you'll need to add the activation call after the Optimizely snippet on each page that you want to test.
  • You cannot put the activation call inside the script tags that load your Optimizely JS file.