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

# Form Filling SDK Event Handling

> Subscribe to FormFillingClient emitter events for analytics, logging, and persistent handlers across multiple sessions

This example shows how to subscribe to Form filling SDK events with `client.on()`. You register listeners once when you create `FormFillingClient`, then use them for analytics, logging, or saving background results across every session on the page.

Callbacks such as `onSubmit` run for one session at a time. Event listeners stay active until you unsubscribe. Refer to [Events](/form-filling-sdk/api-reference/events) for when each event fires.

```javascript JavaScript theme={"theme":{"light":"github-dark","dark":"material-theme-darker"}}
import { FormFillingClient, SukiFormFillingError } from "@suki-sdk/form-filling";

const client = new FormFillingClient({ authManager });

const unsubscribers = [
  client.on("form-filling:ready", () => {
    analytics.track("form_filling_ready");
  }),
  client.on("form-filling:session-started", (payload) => {
    analytics.track("form_filling_session_started", {
      ambient_session_id: payload.ambient_session_id,
      correlation_id: payload.correlation_id,
    });
  }),
  client.on("form-filling:submitted", (result) => {
    analytics.track("form_filling_submitted", {
      ambient_session_id: result.ambient_session_id,
      form_count: result.structured_data.generated_values.length,
    });
  }),
  client.on("form-filling:background-submitted", (result) => {
    persistToBackend(result);
  }),
  client.on("form-filling:error", (err) => {
    if (err instanceof SukiFormFillingError) {
      analytics.track("form_filling_error", { code: err.code, reason: err.reason });
    }
  }),
];

// On app teardown:
// unsubscribers.forEach((off) => off());
```

<Note>
  `form-filling:submitted` removes the iframe for a foreground session. `form-filling:background-submitted` does not: it means results arrived for a session that is no longer the foreground session (for example after replace or reopen), not merely that processing took longer than 60 seconds.
</Note>

## Next steps

<Icon icon="file-lines" iconType="solid" /> Refer to [Events](/form-filling-sdk/api-reference/events) for all event names and lifecycle

<Icon icon="file-lines" iconType="solid" /> Refer to [Webhook handler](/form-filling-sdk/examples/webhook-handler) for server-side saves

<Icon icon="file-lines" iconType="solid" /> Refer to [EHR handoff](/form-filling-sdk/examples/ehr-handoff) to map `structured_data` to your EHR
