Skip to main content

Events

The Consent Prompt emits a number of events that you can listen for using the addEventListener method. The following events are available:

hide

/**
* @param {string} path - The path of the Consent Prompt that was hidden
* @returns {void}
*/
function onHide(path) {
// Do something after the Consent Prompt is hidden
}

window.Osano.prompt.addEventListener('hide', onHide)

The hide event is emitted when the Consent Prompt is hidden from view. The event listener receives one argument: the path of the Consent Prompt that was hidden.

show

/**
* @param {string} path - The path of the Consent Prompt that was shown
* @returns {void}
*/
function onShow(path) {
// Do something after the Consent Prompt is shown
}

window.Osano.prompt.addEventListener('show', onShow)

The show event is emitted when the Consent Prompt is shown to the user. The event listener receives one argument: the path of the Consent Prompt that was shown.

submit

/**
* @param {string} path - The path of the Consent Prompt that was submitted
* @param {Record<string, boolean>} data
* - A object of key-value pairs where the key is the protocol ID and the
* value is a boolean indicating whether the user accepted or rejected
* the protocol.
* @returns {void}
*/
function onSubmit(path, data) {
// Do something after a successful submission
}

window.Osano.prompt.addEventListener('submit', onSubmit)

The submit event is emitted when the user has submitted their consent selections. The event listener receives two arguments: the path of the Consent Prompt that was submitted, and a data object containing the user's selections. The data object is a key-value pair where the key is the protocol ID and the value is a boolean indicating whether the user accepted or rejected the protocol.