Waiting for the Banner SDK to initialize

Fatos Bediu
Founder & Developer answerly.io
It might take a few milliseconds for the banner widget to load on your website and initialize the SDK fully.
Since this is the case, accessing the SDK directly on your website will throw errors since your code might run before the SDK has been initialized.
Fortunately, banner widget emits an event Banner:Loaded
to the main window, which you should listen to and only use the SDK after that event has been fired.
For example:
window.addEventListener('Banner:Loaded', () => {
// SDK is available here
// example code
Answerly.Banner.onLinkClick(e => {
console.log('You have clicked ' + e.text + ' inside the banner');
});
});
Did we answer your question?
😃 🤔 ☹️
How can we improve this answer?