Wait for origin sync
Wait for data to be received from other origins before Optimizely activates.
Syntax
window["optimizely"].push(waitForOriginSync);
Parameters
Parameter and Type | Child Attribute | Description |
---|---|---|
waitForOriginSync | An object with the type | |
type | Child attribute of type WaitForOriginObject | The argument indicating that you're using the waitForOriginSync function. Required. |
canonicalOrigins | Child attribute of type WaitForOriginObject | An array of origins from which data should be received before Optimizely activates. These origins should be listed in priority order, with the highest-priority origin first. Optimizely will wait for data from all listed origins (using substring match) before activating. Origins will match if any of the |
Example Call
window["optimizely"].push({
"type": "waitForOriginSync",
"canonicalOrigins": ["optimizely.com", "developers.optimizely.com"]
});
Description
You can use the waitForOriginSync
API to make Optimizely 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 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:
- 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
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 iframe will not function when a user is on your website (because in this situation, the Optimizely iframe is from a separate website, i.e., a "third-party" origin).
Updated about 3 years ago