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

# Events

> PostMessage events between the widget and your page

# Events

The Selektable SDK communicates with the widget iframe using the browser's `postMessage` API.

> [!NOTE]
>
> You don't need to handle these events directly. The SDK manages them automatically. This reference is for debugging purposes.

## Key events

The SDK handles several categories of events between your page and the widget:

| Category | Description |
| - | - |
| **Lifecycle** | Widget loading, opening, and closing |
| **Product data** | Sending product information to the widget |
| **Cart actions** | Add to cart, view cart, and checkout interactions |
| **Identity** | Passing visitor identity to the widget |

## Listening for widget close

You can listen for when a customer closes the widget, for example to trigger analytics:

```javascript theme={null}
window.addEventListener('message', function (event) {
  if (
    event.data &&
    event.data.type === 'widget:modal-close'
  ) {
    // Customer closed the widget
    console.log('Widget closed');
  }
});
```

## Security

The SDK validates the origin and structure of all incoming messages. Messages from untrusted sources are silently ignored.


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