Skip to main content
menu_icon.png

Everything you need to learn Optimizely X in one place: See our resource pages for Web Experimentation and Personalization.

x
Optimizely Knowledge Base

The JavaScript API in Optimizely X

This article is about Optimizely X. If you're using Optimizely Classic, check this article out instead.
 
RELEVANT PRODUCTS:
  • Optimizely X Web Experimentation
  • Optimizely X Web Personalization
  • Optimizely X Web Recommendations

THIS ARTICLE WILL HELP YOU:
  • Find out what experiments or campaigns are active on a page
  • Check whether the snippet has updated to include the latest revisions
  • Check which variation a visitor is bucketed into

The Optimizely X JavaScript API gives you access to data saved in your projects. It containsoptimizely.pushandoptimizely.getfunctions that let you see what's in your experiments and campaigns.

The JavaScript API is a simpler way to check: 

  • Which experiments and campaigns are active on the current page

  • Which variation you're bucketed into

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

Often, you'll need experiment or campaign IDs when troubleshooting with the JavaScript API. Here's how to find them under API Names.

If you can't find what you're looking for in the JavaScript API, you can also use the Optimizely X log.

Check the JavaScript API

  1. Open the developer console.

  2. Paste the API calls into the console. Below, we provide a list of the most common API calls for troubleshooting.

    For a complete list, see our developer documentation.

Common API calls

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

Returns an array of active experiment IDs on a page.

In Personalization, there are multiple experiments within a single campaign. But in Experimentation 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 of experiment IDs and the corresponding variation ID a user has been bucketed into. Equivalent of classic Optimizely Testing's optimizelyBuckets cookie (which is no longer available within Optimizely X Web).

Related articles