> For the complete documentation index, see [llms.txt](https://developers.didomi.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.didomi.io/api-and-platform/widgets/privacy-widgets/headless-widgets/event-listeners.md).

# Event listeners

Event listeners are JavaScript methods that set up a function to run whenever the specified event is delivered to the target.

You can use event listeners to provide UI feedback to your end-users, handle retries, and more. Since custom events do not support callbacks, event listeners give you access to the current status (loading, success, error) of any action carried out.

* [didomi:save-pending-consents-loading](#didomi-save-pending-consents-loading)
* [didomi:save-pending-consents-error](#didomi-save-pending-consents-error)
* [didomi:save-pending-consents-success](#didomi-save-pending-consents-error)
* [didomi:set-consents-loading](#didomi-set-consents-loading)
* [didomi:set-consents-error](#didomi-set-consents-error)
* [didomi:set-consents-success](#didomi-set-consents-success)
* [didomi:send-authentication-loading](#didomi-send-authentication-loading)
* [didomi:send-authentication-success](#didomi-send-authentication-success)
* [didomi:send-authentication-error](#didomi-send-authentication-error)
* [didomi:verify-otp-code-loading](#didomi-verify-otp-code-loading)
* [didomi:verify-otp-code-success](#didomi-verify-otp-code-success)
* [didomi:verify-otp-code-error](#didomi-verify-otp-code-error)
* [didomi:init-authentication-error](#didomi-init-authentication-error)

#### didomi:save-pending-consents-loading

`didomi:save-pending-consents-loading` is triggered when the "save pending consents" action is waiting for SDK response.

```javascript
document.addEventListener("didomi:save-pending-consents-loading", () => {
  // your callback
});
```

#### didomi:save-pending-consents-error

`didomi:save-pending-consents-error` is triggered when saving pending consents fails.

```javascript
document.addEventListener("didomi:save-pending-consents-error", () => {
  // your callback
});
```

**didomi:save-pending-consents-success**

`didomi:save-pending-consents-success` is triggered when saving pending consents succeeds.

```javascript
document.addEventListener("didomi:save-pending-consents-success", () => {
  // your callback
});
```

#### didomi:set-consents-loading

`didomi:set-consents-loading` is triggered when saving consents is waiting for SDK response.

```javascript
document.addEventListener("didomi:set-consents-loading", () => {
  // your callback
});
```

#### didomi:set-consents-error

`didomi:set-consents-error` is triggered when saving consents fails.

```javascript
document.addEventListener("didomi:set-consents-error", () => {
  // your callback
});
```

#### didomi:set-consents-success

`didomi:set-consents-success` is triggered when saving consents succeeds.

```javascript
document.addEventListener("didomi:set-consents-success", function);
```

#### didomi:send-authentication-loading

`didomi:send-authentication-loading` is triggered when authentication is waiting for SDK response.

```javascript
document.addEventListener("didomi:send-authentication-loading", () => {
  // your callback
});
```

#### didomi:send-authentication-success

`didomi:send-authentication-success` is triggered when authentication succeeds.

```javascript
document.addEventListener("didomi:send-authentication-success", () => {
  // your callback
});
```

#### didomi:send-authentication-error

`didomi:send-authentication-error` is triggered when authentication fails.

```javascript
document.addEventListener("didomi:send-authentication-error", () => {
  // your callback
});
```

#### didomi:verify-otp-code-loading

`didomi:verify-otp-code-loading` is triggered when authentication is waiting for SDK response.

```javascript
document.addEventListener("didomi:verify-otp-code-loading", () => {
  // your callback
});
```

#### didomi:verify-otp-code-success

`didomi:verify-otp-code-success` is triggered when authentication succeeds.

```javascript
document.addEventListener("didomi:verify-otp-code-success", () => {
  // your callback
});
```

#### didomi:verify-otp-code-error

`didomi:verify-otp-code-error` is triggered when authentication fails.

```javascript
document.addEventListener("didomi:verify-otp-code-error", () => {
  // your callback
});
```

#### didomi:init-authentication-error

`didomi:init-authentication-error` is triggered when the authentication initiate function fails while SDK is loading.

```javascript
document.addEventListener("didomi:init-authentication-error", () => {
  // your callback
});
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://developers.didomi.io/api-and-platform/widgets/privacy-widgets/headless-widgets/event-listeners.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
