> ## 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.

# Installation

> How to install the Selektable embed script

# Installation

The Selektable SDK is loaded via a script tag. No npm packages or build tools required.

## Script tag

Add the embed script before the closing `</body>` tag on every page where you want the widget available. Replace `store_xxx` with your Store ID from the Selektable dashboard:

```html theme={null}
<script src="https://app.selektable.com/widgets/embed.js" data-store-id="store_xxx" async></script>
```

<Note>
  Replace `app.selektable.com` with your instance URL if self-hosting.
</Note>

The script:

* Loads asynchronously (`async`) so it doesn't block page rendering
* Creates the global `window.Selektable` object
* Auto-discovers `data-selektable-widget` elements on the page
* Initializes visitor identity tracking

## Verifying installation

Open your browser's developer console and check that the SDK is loaded:

```javascript theme={null}
console.log(window.Selektable);
// Should output an object with: open, close, preload, discover, identify, reset, getIdentity, setVisitorId
```

## Loading order

Since the script loads asynchronously, `window.Selektable` may not be available immediately. If you're calling SDK methods from inline scripts, ensure the SDK has loaded first:

```html theme={null}
<script>
  // Option 1: Check before calling
  function openWidget() {
    if (window.Selektable) {
      Selektable.open('widget_abc123', { ... });
    }
  }
</script>
```

```html theme={null}
<script>
  // Option 2: Wait for load event
  window.addEventListener('load', function () {
    Selektable.preload('widget_abc123');
  });
</script>
```

<Tip>
  For click handlers on buttons, the SDK will almost always be loaded by the time a user clicks. The guard is mainly needed for code that runs immediately on page load.
</Tip>

## Multiple widgets

You only need one script tag per page, even if you have multiple widgets. The SDK manages all widget instances through a single registry.

```html theme={null}
<!-- One script tag -->
<script src="https://app.selektable.com/widgets/embed.js" data-store-id="store_xxx" async></script>

<!-- Multiple widgets -->
<button onclick="Selektable.open('widget_room')">Room Visualizer</button>
<button onclick="Selektable.open('widget_tryon')">Virtual Try-On</button>
```

## Re-execution safety

The script is safe to re-execute (e.g., in SPA navigations). The widget instance registry persists across re-executions, and the message handler is only registered once.
