Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideProduct feedbackGitHubNuGetDev CommunitySubmit a ticketLog In

Wait for origin sync

Wait for data to be received from other origins before Optimizely Web Experimentation activates.




Parameter and TypeChild AttributeDescription
N/AAn object with the type field set to waitForOriginSync. The other fields are the function arguments. Required.
Child attribute of type WaitForOriginObjectThe argument indicating that you're using the waitForOriginSync function. Required.
Child attribute of type WaitForOriginObjectAn array of origins from which data should be received before Optimizely Web Experimentation activates. These origins should be listed in priority order, with the highest-priority origin first. Optimizely Web Experimentation will wait for data from all listed origins (using substring match) before activating. Origins will match if any of the canonicalOrigins you specify are present as a substring anywhere in the origin.

Example Call

  "type": "waitForOriginSync",
  "canonicalOrigins": ["", ""]


You can use the waitForOriginSync API to make Optimizely Web Experimentation wait for cross-origin data and sync before activating the snippet. When using this API, the visitor's ID will be set based on existing data, if any, from the specified origins, so that a single visitor will keep the same visitor ID, and relevant data, when moving back and forth across schemes or domains/TLDs. Since this will make the snippet wait for cross-domain data for up to one second, it could cause a "flash" (if the page renders and an experiment activates afterward, causing the snippet to apply visual changes). Because of this, we don't recommend using this API on pages that have above-the-fold visual experiments. Learn more about cross-origin targeting.

Optimizely Web Experimentation uses an iframe to persist localStorage from one website "origin" to another. Thus anything that prevents the iframe from loading or initializing will cause waitForOriginSync to timeout and not emit the originsSynced event. There are three known ways this can happen:

  1. The origin setting in your account is set incorrectly.
  2. The user's browser blocks all iframes or iframes specifically from *
  3. The browser's privacy settings prevent setting or retrieving localStorage keys from iframe origins (see below).

Some browsers block cross-origin iframe localStorage if "third-party cookies" are disabled. When a browser does this, the Optimizely Web Experimentation iframe will not function when a user is on your website (because in this situation, the Optimizely Web Experimentation iframe is from a separate website, i.e., a "third-party" origin).