JavaScript API
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 Web Experimentation and Optimizely Personalization execution.
- Function that can be used to develop experiences (see also JavaScript executionJavaScript 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 callsFind IDs for API calls. If you cannot find what you are looking for in the JavaScript API, see the Optimizely Experimentation logOptimizely Experimentation log.
Check the JavaScript API
- Open the developer consoleOpen the developer console.
- Paste the API calls into the console.
Note Unlike Web Experimentation and Optimizely Personalization, whose JavaScript API is exposed with window.optimizely, Performance Edge uses window.optimizelyEdge. See the Optimizely Performance Edge JavaScript APIOptimizely Performance Edge JavaScript API.
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.