Wait for data to be received from other origins before Optimizely Web Experimentation activates.
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 is set based on existing data, if any, from the specified origins, so that a single visitor keeps the same visitor ID, and relevant data, when moving back and forth across schemes or domains or top-level domains (TLDs).
Because this makes 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, you should not use this API on pages that have above-the-fold visual experiments. Learn more about cross-origin targeting.
Web Experimentation uses an iframe to persist localStorage from one website "origin" to another. Thus anything that prevents the iframe from loading or initializing causes waitForOriginSync to timeout and not emit the originsSynced event. The following are are three known ways this can happen:
- The origin setting in your optimizely.com account is set incorrectly.
- The user's browser blocks all iframes or iframes specifically from
*.cdn.optimizely.com. - The browser's privacy settings prevent setting or retrieving
localStoragekeys from iframe origins.
Some browsers block cross-origin iframe localStorage if "third-party cookies" are disabled. When a browser does this, the Web Experimentation iframe does not function when a user is on your website (because in this situation, the Web Experimentation iframe is from a separate website, for example, a "third-party" origin).
Syntax
window["optimizely"].push(waitForOriginSync);
Parameters
| Parameter and type | Child attribute | Description |
|---|---|---|
| waitForOriginSync WaitForOriginObject | N/A | An object with the type field set to waitForOriginSync. The other fields are the function arguments. Required. |
| type string | Child attribute of type WaitForOriginObject. | The argument indicating that you're using the waitForOriginSync function. Required. |
| canonicalOrigins array[string] | Child attribute of type WaitForOriginObject. | An array of origins from which data should be received before Web Experimentation activates. These origins should be listed in priority order, with the highest-priority origin first. Web Experimentation waits for data from all listed origins (using substring match) before activating. Origins match if any of the |
Example call
window["optimizely"].push({
"type": "waitForOriginSync",
"canonicalOrigins": ["optimizely.com", "developers.optimizely.com"]
});