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

# setListeners

> Configure callbacks for connector link events and sync schedule saves

## setListeners

The `setListeners` function allows you to set event listeners for connector link operations and for **sync schedule** changes inside the widget.

### Parameters:

* **listeners**: `object`
  * `onConnectorLink`: `(event: ConnectorLinkEvent) => void`
    * Callback for when a connector is successfully linked.
  * `onConnectorRelink`: `(event: ConnectorLinkEvent) => void`
    * Callback for when a connector is relinked.
  * `onConnectorUnlink`: `(event: ConnectorUnlinkEvent) => void`
    * Callback for when a connector is unlinked.
  * `onConnectorLinkFail`: `(event: ConnectorLinkFailEvent) => void`
    * Callback for when a connector link fails.
  * `onFieldMapSave`: `(event: FieldMapSaveEvent) => void`
    * Callback for when a field map is successfully saved.
  * `onScheduleSave`: `(event: ScheduleEvent) => void` *(optional)*
    * Callback when the **sync schedule** is saved or disabled in the widget. Your app can mirror schedule state, trigger backend syncs, or run analytics. For how the schedule UI behaves, see [Sync Schedule](/widget-v3/reference/sync-schedule).
    * If you omit `onScheduleSave`, the widget skips it. If your callback throws, the widget catches the error and logs `onScheduleSave listener failed` to the console without breaking the save flow in the UI.

#### Event Types:

* `ConnectorLinkEvent`:
  * **connectorId**: `string`
  * **connectorType**: `'connector' | 'source' | 'target'`
  * **connectorDetail**: `Record<string, unknown>`
  * **flowId**: `string`
  * **tenantId**: `string`

* `ConnectorUnlinkEvent`:
  * **connectorId**: `string`
  * **connectorType**: `'connector' | 'source' | 'target'`
  * **flowId**: `string`
  * **tenantId**: `string`

* `ConnectorLinkFailEvent`:
  * **error**: `string`
  * **connectorId**: `string`
  * **connectorType**: `'connector' | 'source' | 'target'`
  * **flowId**: `string`
  * **tenantId**: `string`
  * **type**: `'failed' | 'cancelled'` *(optional)*

* `ScheduleEvent`:
  * **type**: `'save' | 'disabled'` — `'save'` when the user saves with scheduling **enabled**; `'disabled'` when they save with scheduling **turned off** in the schedule UI.
  * **oldSchedule**: `string | null` — Previous schedule expression before the change; `null` if none applied.
  * **newSchedule**: `string | null` — Schedule after the change; `null` if cleared or not applicable.
  * **connectorId**: `string` *(optional)* — Present when your environment has **[Enable connector schedules](/environment-settings/widget-settings#enable-connector-schedules)** on **and** the user saved a **connector-level** schedule (the widget scoped the save to that connector). Omitted for **flow**-only schedule updates. See [Sync Schedule — flow vs connector](/widget-v3/reference/sync-schedule#flow-level-vs-connector-level-schedules).
  * **flowId**: `string`
  * **tenantId**: `string` — May be an empty string when no tenant id is available (the widget passes `tenantId || ''`).

* `FieldMapSaveEvent`:
  * **connectorId**: `string`
  * **connectorType**: `'connector' | 'source'`
  * **flowId**: `string`
  * **tenantId**: `string`

### Example:

```javascript theme={null}
// Alternatively exported by useHotglue in the React package
const hotglue = new Hotglue({
    // Configuration
});

hotglue.setListeners({
    onConnectorLink: (event) => {
        console.log("Connector linked:", event);
    },
    onConnectorRelink: (event) => {
        console.log("Connector relinked:", event);
    },
    onConnectorUnlink: (event) => {
        console.log("Connector unlinked:", event);
    },
    onConnectorLinkFail: (event) => {
        console.error("Connector link failed:", event);
    },
    onFieldMapSave: (event) => {
        console.log("Field map saved:", event);
    },
    onScheduleSave: (event) => {
        if (event.type === "save") {
            console.log("Schedule saved", {
                flowId: event.flowId,
                connectorId: event.connectorId,
                from: event.oldSchedule,
                to: event.newSchedule,
            });
        } else {
            console.log("Schedule disabled", event);
        }
    }
});
```
