Getting started with Optimizely's JS API
1. Create an Optimizely account
If you don't have an Optimizely account already, just sign up for a free developer account. This account will give you access to core Optimizely features and API access, but with limited traffic allocation. No credit card is required, but you can always upgrade your account to a paid plan later.
2. Implement the Optimizely Snippet
If you are not already running Optimizely, you'll need to add the Optimizely Snippet to the head section of your web page. See Implement the one-line snippet for Optimizely X for detailed instructions on how to add the Optimizely snippet for your project.
3. Start an experiment
4. Read from the Data Object
The API has a
window["optimizely"].get() function that gives you access to the
data that you have saved in your project (Campaigns, Experiments,
Pages, Events, Audiences). With this function you can also get information
about the current state of Optimizely in the browser.
To access data you have saved, open your browser console and type
You can also access data about the current visitor by typing
window["optimizely"].get('visitor') or get to the current state of the campaigns and experiments that are running by typing
5. Make an API call
The API function calls expose many of Optimizely's decisions and actions so you can take control.
One example is starting experiments manually rather than upon page load, which is useful for testing dynamic web pages. Your application can tell Optimizely when to activate these "manual activation mode" experiments with the activate API function. Another example is using the bucketVisitor API function to assign visitors to a specific variation if you wanted to incorporate inputs that Optimizely's traffic allocation algorithm does not.