# Widget Hooks

#### On Survey Loaded

This action will trigger the given callback function when the survey is loaded and shown.

```javascript
FBLY.action("onSurveyLoaded", () => { /* Your code */})
```

#### On Response

This action will trigger the given callback function immediately after a customer answers a question of the survey. This means, if the survey has 3 questions the function will be called each time a question in answered, in this case 3 times. \
\
The response object will be passed as the first argument of the function. Available fields include:

|              |                                  |
| ------------ | -------------------------------- |
| surveyId     | 12 byte ObjectId                 |
| questionId   | 12 byte ObjectId                 |
| touchpointId | 12 byte ObjectId                 |
| language     | string (ISO 639-1 language code) |
| data         | varies                           |

```javascript
FBLY.action("onResponse", (r) => { /* Your code */})
```

#### On Survey Finished

This action will trigger the given callback function after the survey is completed.

```javascript
FBLY.action("onSurveyFinished", () => { /* Your code */})
```

#### on Survey Close

This action will trigger the given callback function if the survey closes either by user or programmatically. "isDeclined" flag is true only if the user closed the survey or if  `FBLY.close(userDeclined)` called with userDeclined = true

```javascript
FBLY.action("onClose", (isDeclined) => { /* Your code */})
```


---

# Agent Instructions: 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:

```
GET https://docs.feedbackly.com/website-widgets/widget-hooks.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
