> For the complete documentation index, see [llms.txt](https://docs.caf.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.caf.io/caf-docs/quick-start-guides/onboardings-integration/events.md).

# Events

#### Onboarding Event Codes

Here is the table with descriptions:

| EVENT                            | DESCRIPTION                                                                                                                                  | DETAIL                                                                       |
| -------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
| **STEP\_STARTED**                | General event to every begin of step of onboarding flow. (GENERICAL DETAIL)                                                                  | `{ "stepName":"INSTRUCTIONS", "stepIndex":0 }`                               |
| **STEP\_COMPLETED**              | General event trigger when setp finish. (GENERICAL DETAIL)                                                                                   | `{ "stepName":"INSTRUCTIONS", "stepIndex":0 }`                               |
| **GET\_CAMERA\_PERMISSIONS**     | The user clicked the button to enable camera access but has not yet granted permission.                                                      | `{}`                                                                         |
| **SDK\_CAMERA\_DENIED**          | The user denied camera access, preventing further progress until permissions are granted.                                                    | `{ "StepName":"LIVENESS_IPROOV" }`                                           |
| **LIVENESS\_CAPTURE**            | The user clicked the button to start the liveness detection capture. After capture, the liveness count will indicate the number of attempts. | `{ "livenessCount": X }`                                                     |
| **SDK\_CAPTURE\_DENIED**         | The user denied motion access, preventing the system from verifying their identity.                                                          | `{ "assuranceType":"liveness" }`                                             |
| **SDK\_CAPTURE\_FAILED**         | The liveness capture failed due to an issue such as poor lighting or improper movement, requiring the user to retry.                         | `{ "assuranceType":"liveness","reason":"Try again","passed":false }`         |
| **LIVENESS\_IPROOV\_ERROR**      | An error occurred while performing liveness verification. Contact the SDK team for further assistance.                                       | `{}`                                                                         |
| **SDK\_CAPTURE\_INVALID**        | The liveness capture was invalid, possibly due to improper user positioning or lighting issues.                                              | `{"assuranceType":"liveness","reason":"error_device_motion_unsupported"}}`   |
| **SDK\_CAPTURE\_RESULT**         | The result of the liveness capture, indicating whether the user is deemed alive or not.                                                      | `{ "isAlive":true/false }`                                                   |
| **LIVENESS\_PREVIEW\_RETRY**     | The user opted to retry the selfie capture, restarting the liveness verification process.                                                    | `{}`                                                                         |
| **DOCUMENT\_REUSE\_FLOW**        | The option that the user selected when finding their document in the Document Reuse step, which can be `REUSE` or `CAPTURE`.                 | `{ "selected":"REUSE" }`                                                     |
| **DOCUMENT\_TYPE\_SELECTED**     | The user selected a document type (e.g., CNH) to proceed with document verification.                                                         | `{ "type":"CNH" }`                                                           |
| **TERM\_ACCEPTED**               | The user checked the checkbox to accept the terms of use. If unchecked, an event with `false` is emitted.                                    | `{ "term":"DocumentType_0_Terms of Use and Privacy Policy","checked":true }` |
| **SELECT\_DOCUMENT\_TYPE**       | The user checked the checkbox to accept the terms of use. If unchecked, an event with `false` is emitted.                                    | `{ "option":upload/picture }`                                                |
| **SDK\_FRONT\_CAPTURE\_STARTED** | The front document image capture started                                                                                                     | `{ "assuranceType":"document_detector"}`                                     |
| **SDK\_BACK\_CAPTURE\_STARTED**  | Theb back document image capture started                                                                                                     | `{ "assuranceType":"document_detector"}`                                     |
| **SDK\_UPLOAD\_INVALID**         | The event is trigger when sdk retorns failed on the document upload                                                                          | `{"assuranceType":"document_detector","eventId":"DOCUMENT_NOT_SUPPORTED"}`   |
| **DD\_CAPTURE\_FINISH**          | The user canceled the document capture step.                                                                                                 | `{}`                                                                         |
| **DD\_PREVIEW\_RETRY**           | The document capture was successful.                                                                                                         | `{ "assuranceType":"document", "stepName":"DOCUMENT_CAPTURE" }`              |
| **SDK\_CAPTURE\_FAILED**         | The document capture failed due to image quality issues.                                                                                     | `{ "assuranceType":"document", "reason":"Blurred Image", "passed":false }`   |
| **FIELD\_CHANGE**                | The event is triggered when the user edits or enters a value in the text field                                                               | `{"field":"email"}`                                                          |
| **FAILED\_PHONE\_CODE**          | Incorrect code entered                                                                                                                       | `{}`                                                                         |
| **RESEND\_PHONE\_CODE**          | The event is triggered when the user ask to resend the phone code                                                                            | `{}`                                                                         |
| **FAILED\_EMAIL\_CODE**          | Incorrect code entered                                                                                                                       | `{}`                                                                         |
| **RESEND\_EMAIL\_CODE**          | The event is triggered when the user ask to resend the email code                                                                            | `{}`                                                                         |
| **ONBOARDING\_FINISHED**         | The onboarding process was completed successfully, and the user is now onboarded.                                                            | `{ "executionId":"67b27030a0e08600085f0c0f" }`                               |

***

The **STEP\_STARTED** and **STEP\_COMPLETED** events are indicators of the beginning and completion of various stages within the onboarding process. These events help to track the user's progress through each step.

* The **STEP\_STARTED** event signifies that a particular step has started. It contains two key parameters:
  * `stepName`: The name of the step, which could be one of several predefined stages in the onboarding process. Examples of possible values include:
    * `INSTRUCTIONS`
    * `CAMERA_ACCESS`
    * `LIVENESS_CAPTURE`
    * `DOCUMENT_TYPE`
    * `DISPATCH_ADDRESS`
    * `DOCUMENT_REUSE`
    * `DOCUMENT_REUSE_SEARCH`
    * `SEND_DOCUMENT_TYPE`
    * `COMPANY_ADDRESS`
    * `COMPANY_DATA`
    * `COMPANY_LISTING`
    * `COMPANY_SEARCH`
    * `COMPANY_LOCATION`
    * `BUSINESS_ADDRESS`
    * `INCOME`
    * `EMPLOYEE_DATA`
    * `PHONE_NUMBER_VALIDATION`
    * `EMAIL_VALIDATION`
    * `UPLOAD_DOCUMENT`
    * `WELCOME`
    * `NEW_ACCESS`
    * `FLOW_CHOICE`
    * `CUSTOM`
    * `QSA_CONTACT`
    * `QSA_CONTACT_INFO`
    * `QSA_NUMBER`
    * `PFL_PREVIEW`
    * `LIVENESS_CLEAR_SALE_PREVIEW`
    * `FA_PREVIEW`
    * `CUSTOM_FORM`
    * `DONE`
    * `USING_TERMS`
    * `DOCUMENT_ISSUED_COUNTRY`
    * `DD`
    * `PFL`
    * `LIVENESS_CLEAR_SALE`
    * `FA`
    * `FACE_AUTH_IPROOV`
    * `FACE_AUTH_FACETEC_3D`
    * `FACE_AUTH_FACETEC_2D`
    * `LIVENESS_IPROOV`
    * `LIVENESS_FACETEC_3D`
    * `LIVENESS_FACETEC_2D`
    * `DD_PREVIEW`
    * `FACE_AUTH_IPROOV_PREVIEW`
    * `LIVENESS_IPROOV_PREVIEW`
    * `LIVENESS_FACETEC_3D_PREVIEW`
    * `LIVENESS_FACETEC_2D_PREVIEW`
    * and others.
  * `stepIndex`: The index of the current step, which provides a numerical reference to the user's position within the overall onboarding flow. This allows for precise identification of which step is in progress.
* The **STEP\_COMPLETED** event signifies that a particular step has been completed successfully. Like the **STEP\_STARTED** event, it includes:
  * `stepName`: The name of the completed step.
  * `stepIndex`: The index of the completed step, which marks the successful progression to the next step in the process.

These events are crucial for monitoring the flow of the onboarding process, providing both the name of the current step and its index to help determine where the user is in the onboarding journey.

***

The Onboarding process communicates with an iFrame or WebView by emitting events through `window.postMessage()`. Event support is currently available for iFrame, Flutter\*, and React Native.

```javascript
window.addEventListener(
  "message",
  function (e) {
    console.log(e.data);
  },
  false
);
```

#### Example of a Returned Message:

```json
{
  "code": "ONBOARDING_FINISHED",
  "detail": {
    "executionId": "xxxxxxxxxxxxxxxxxxxxxxxxxx"
  }
}
```

{% hint style="warning" %}
Always listen to the `"message"` event, as communication with the onboarding link through an iFrame utilizes the `postMessage` API.
{% endhint %}

#### Using a Specific Event Code from Onboarding:

To handle specific event codes emitted by Onboarding, you can check the `code` property in the event data:

```javascript
window.addEventListener(
  "message",
  function (e) {
    if (e.data.code === "SDK_BACK_CAPTURE_STARTED") {
      console.log("The capture was started");
    }
  },
  false
);
```

{% hint style="info" %}
**If using** Web Message Listeners with Flutter, then [InAppWebView](https://inappwebview.dev/) should be used, with **`jsObjectName`** set as **`FutterOnboardingChannel`**
{% endhint %}

The events that can be issued by Onboarding are as follows:

* `SDK_CAPTURE_INVALID`: Will be triggered when capture is invalid, such as an incorrect document or poor image quality. (Document Detector and Passive Face Liveness)
* `SDK_CAPTURE_FAILED`: Some other failure in the capture. (Document Detector and Passive Face Liveness)
* `SDK_CAPTURE_RESULT`: Result of the capture. (Liveness and FaceAuthenticator)
* `SDK_BACK_CAPTURE_STARTED`: Started capturing the backside of the document (Document Detector)
* `SDK_FRONT_CAPTURE_STARTED`: Started capturing the front of the document (Document Detector)
* `DD_CAPTURE_FINISH`: Document Detector capture step in onboarding completed (If it has both sides, it will only be triggered when both sides are captured) in fact it is only triggered when you are already moving on to the next step, if everything is ok with the capture
* `ONBOARDING_FINISHED`: Onboarding finished


---

# 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://docs.caf.io/caf-docs/quick-start-guides/onboardings-integration/events.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.
