# 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 */})
```
