Disclaimer: This website requires Please enable JavaScript in your browser settings for the best experience.

The availability of features may depend on your plan type. Contact your Customer Success Manager if you have any questions.

Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
API Reference

JavaScript API

The Optimizely Web Experimentation JavaScript API has many useful functions that can be used to control Optimizely Web Experimentation.

Products

  • Optimizely Web Experimentation
  • Optimizely Performance Edge
  • Optimizely Personalization

The Optimizely Web Experimentation JavaScript API gives you access to data saved in your projects. It contains optimizely.push and optimizely.get functions that let you see what is in your experiments and campaigns.

The API functions can be grouped into the following three types:

  • Functions that have a global effect on Optimizely Web Experimentation and Optimizely Personalization execution.
  • Function that can be used to develop experiences (see also JavaScript execution).
  • Function that can be used to monitor what Optimizely is doing.

This article provides a short list of the most common API calls and shows you how to use them.

📘

Note

Often, you need experiment or campaign IDs when troubleshooting with the JavaScript API. See Find IDs for API calls.

If you cannot find what you are looking for in the JavaScript API, see the Optimizely Experimentation log.

Check the JavaScript API

  1. Open the developer console.
  2. Paste the API calls into the console.

📘

Note

Unlike Optimizely Web Experimentation and Optimizely Personalization, whose JavaScript API is exposed with window.optimizely, Optimizely Performance Edge uses window.optimizelyEdge. See the Optimizely Performance Edge API Reference.

Common API calls

  • optimizely.get('state').getActiveExperimentIds()

    • Returns an array of active experiment IDs on a page.
    • In Optimizely Performance Edge, there are multiple experiments within a single campaign.
    • In Optimizely Web Experimentation and Optimizely Personalization, there is only one experiment for each campaign.
  • optimizely.get('data').revision

    • Returns the revision that the snippet on the page is on. Useful in determining whether you are looking at the most updated changes made within a campaign.
  • optimizely.get('state').getVariationMap()

    • Returns an object containing the mapping of all experiment variations a user is bucketed into in its lifetime. The experiment IDs are the object keys. The object contains the corresponding variation a user is bucketed into for each experiment, where the "id" and "name" values correspond to the variation.
  • optimizely.get('state').getPageStates({"isActive": true});

    • Returns an object of the pages that are active on the URL you are on.

See the Push and Get sections for documentation on all of the API functions.