> ## Documentation Index
> Fetch the complete documentation index at: https://docs.usertick.com/llms.txt
> Use this file to discover all available pages before exploring further.

# SDK events

> The four widget events, when each one fires and the data it carries.

Handlers subscribe with [`Usertick.on`](https://docs.usertick.com/developers/sdk/reference#on--off) and receive one data object. The fields below are the ones to rely on.

## open

Fires when a survey becomes visible, whatever opened it: a trigger, the side button, `Usertick.show()` or an embedded survey appearing on the page.

```js theme={null}
Usertick.on("open", ({ survey_id }) => {
  console.log("Survey opened", survey_id);
});
```

**survey\_id** `string`

The survey that opened.

## close

Fires when a survey closes: through its close button, Escape, selecting the backdrop of a centered popup, `Usertick.hide()`, or the thank-you screen of a popup closing on its own after a response. Minimizing a popup doesn't fire it.

```js theme={null}
Usertick.on("close", ({ survey_id }) => {
  console.log("Survey closed", survey_id);
});
```

**survey\_id** `string`

The survey that closed.

## submit

Fires when the visitor submits a response, before the response is sent.

```js theme={null}
Usertick.on("submit", ({ survey_id, answers }) => {
  if (window.gtag) gtag("event", "survey_submit", { survey_id });
});
```

> [!TIP]
>
> Google Analytics, FullStory and UXCam can receive an event for each completed response without any code. To switch a tool on for a site, open the tool under **Settings → Integrations**. See [Google Analytics, FullStory and UXCam](https://docs.usertick.com/integrations/page-events.md).

**survey\_id** `string`

The survey that was answered.

**answers** `object`

The answers keyed by question ID. Each value has the question's own shape: a number for a scale, a string for text, an array for several choices and an object for structured types.

> [!NOTE]
>
> `submit` fires before delivery is confirmed. A network error is retried from the offline queue, while a response the server refuses, or a file that can't be uploaded, fires `error`. To process confirmed responses on a server, use a [webhook](https://docs.usertick.com/developers/webhooks/overview.md).

## error

Fires when a response can't be sent. The form stays on screen with every answer, so the visitor can submit again.

```js theme={null}
Usertick.on("error", ({ survey_id, type, reason }) => {
  console.warn("Usertick error", survey_id, type, reason);
});
```

**survey\_id** `string`

The survey whose response couldn't be sent.

**type** `string`

`submission_unsendable` when the server refused the response, or `attachment_upload_failed` when a file couldn't be uploaded.

**reason** `string`

Only with `attachment_upload_failed`: `size` when the file is too large, `type` when its file type isn't accepted, `not_accepted` when the question takes no files, or `failed` for any other refusal.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.