Subscribe to SDK events
Allow developers to subscribe to specific events of the SDK.
What are we talking about?
This document outlines available events that can be listened using the Goodays Web SDK. The methods
window.GoodaysSDK.on
andwindow.GoodaysSDK.off
allow developers to subscribe and unsubscribe, respectively, to specific events of the SDK.These events trigger the execution of provided listener functions when certain actions occur.
As of today, two events exist :
open
andclose
.
Subscribe to a specific event of the SDK
The on
method allows you to subscribe to a specific event of the SDK. When the specified event is triggered, the provided listener
function is called.
window.GoodaysSDK.on(event, listener);
Parameters
Name | Type | Description |
---|---|---|
event | string | The name of the event to subscribe to. Available events are open and close . |
listener | function | The function to execute when the event is triggered. |
Example
// Subscribe to the 'open' event
window.GoodaysSDK.on('open', function() {
console.log('Widget opened');
// do whatever you want when the widget open
});
// Subscribe to the 'close' event
window.GoodaysSDK.on('close', function() {
console.log('Widget closed');
// do whatever you want when the widget close
});
Unsubscribe to a specific event of the SDK
The off
method allows you to unsubscribe from a specific event of the SDK. The provided listener
function will be removed from the list of listeners for the specified event.
window.GoodaysSDK.off(event, listener);
Parameters
Name | Type | Description |
---|---|---|
event | string | The name of the event to subscribe to. Available events are open and close . |
listener | function | The function to execute when the event is triggered. |
Example
function onWidgetOpen() {
console.log('Widget opened');
}
// Subscribe to the 'open' event
window.GoodaysSDK.on('open', onWidgetOpen);
// Unsubscribe from the 'open' event
window.GoodaysSDK.off('open', onWidgetOpen);
Updated 7 months ago