All functions of the JS API will run reliably only when the VWO Engage API is ready. You need to register a callback function which will get executed once the API gets ready. The same is pushed into the global _pcq queue.

Parameters:

  1. APIReady: Command to register the callback function to be executed when the API gets ready.
  2. callBackOnSuccessFunctionName: Name of the callback function to be executed when the API gets ready.
  3. callBackOnFailureFunctionName: Name of the callback function to be executed when API did not get ready due to some reason(for example :- browser not supported, private browsing etc)

Refer to the syntax below:

_pcq.push(['APIReady', callBackOnSuccessFunctionName, callBackOnFailureFunctionName]);

window._pcq = window._pcq || [];
_pcq.push(['APIReady', callbackOnSuccessFunction,callbackOnFailureFunction]); //will execute callback function when VWO Engage API is ready

function callbackOnSuccessFunction() {
    //now api is ready
}

function callbackOnFailureFunction(values) {
    console.log(values.reasons) //It will give you the array of reasons why VWO Engage API could not get ready .For eg:- ["PRIVATE_BROWSING", "BROWSER_NOT_SUPPORTED"] etc.
}

In addition to this, pushcrew.isAPIReady denotes whether the API is ready or not. Refer to below syntax:

if(pushcrew.isAPIReady) {
    console.log('API is ready');
}