{"_id":"55e59fddd101191900f30b82","githubsync":"","version":{"_id":"55e58b63d101191900f30b16","__v":3,"project":"55e58b63d101191900f30b13","createdAt":"2015-09-01T11:26:27.668Z","releaseDate":"2015-09-01T11:26:27.668Z","categories":["55e58b65d101191900f30b17","55e58d16f493c11700584314","55e58d1bd101191900f30b1d"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"category":{"_id":"55e58d16f493c11700584314","project":"55e58b63d101191900f30b13","__v":9,"pages":["55e58d21f11ba80d003238be","55e59fddd101191900f30b82","55e5a218f11ba80d00323911","55e5a28bf11ba80d00323915","55e5a2adf11ba80d00323917","55e5a335a603d62300f8926f","55e5a4cad101191900f30b9d","55e5a5396015ce1900eadb54","55e81c700f5df10d004a9c10"],"version":"55e58b63d101191900f30b16","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-09-01T11:33:42.203Z","from_sync":false,"order":1,"slug":"js-api","title":"JavaScript API"},"user":"5554788cb450630d00041dbc","parentDoc":null,"project":"55e58b63d101191900f30b13","__v":18,"metadata":{"title":"","description":"","image":[]},"updates":["584fa1235f70af2d00855012","592b6091ee283a19006da490"],"next":{"pages":[],"description":""},"createdAt":"2015-09-01T12:53:49.400Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"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.\n\n**Parameters:**\n\n1) APIReady: Command to register the callback function to be executed when the API gets ready.\n2) callBackOnSuccessFunctionName: Name of the callback function to be executed when the API gets ready.\n3) 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)\n\nRefer to the syntax below:\n\n_pcq.push(['APIReady', callBackOnSuccessFunctionName, callBackOnFailureFunctionName]);\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"window._pcq = window._pcq || [];\\n_pcq.push(['APIReady', callbackOnSuccessFunction,callbackOnFailureFunction]); //will execute callback function when VWO Engage API is ready\\n\\nfunction callbackOnSuccessFunction() {\\n    //now api is ready\\n}\\n\\nfunction callbackOnFailureFunction(values) {\\n    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.\\n}\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nIn addition to this, pushcrew.isAPIReady denotes whether the API is ready or not. Refer to below syntax:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"if(pushcrew.isAPIReady) {\\n    console.log('API is ready');\\n}\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"is-api-ready","type":"basic","title":"Is API Ready?"}
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]); [block:code] { "codes": [ { "code": "window._pcq = window._pcq || [];\n_pcq.push(['APIReady', callbackOnSuccessFunction,callbackOnFailureFunction]); //will execute callback function when VWO Engage API is ready\n\nfunction callbackOnSuccessFunction() {\n //now api is ready\n}\n\nfunction callbackOnFailureFunction(values) {\n 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.\n}", "language": "javascript" } ] } [/block] In addition to this, pushcrew.isAPIReady denotes whether the API is ready or not. Refer to below syntax: [block:code] { "codes": [ { "code": "if(pushcrew.isAPIReady) {\n console.log('API is ready');\n}", "language": "javascript" } ] } [/block]