Events
The Consent Prompt emits a number of events that you can listen for using the addEventListener
method. The following events are available:
hide
- Javascript
- Typescript
/**
* @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)
function onHide(path: string): void {
// 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
- Javascript
- Typescript
/**
* @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)
function onShow(path: string): void {
// 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
- Javascript
- Typescript
/**
* @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)
function onSubmit(path: string, data: Record<string,boolean>): void {
// 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.