> For the complete documentation index, see [llms.txt](https://docs.elitebundleapp.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.elitebundleapp.com/reference/events.md).

# Events

Reference for the six elite:byob:\* DOM events Elite Bundle Builder fires on Shopify bundle pages, with payloads and listener examples.

All events are dispatched on `document` as `CustomEvent` instances with `bubbles: true`. Listen with `document.addEventListener`, or with `window.eliteBundle.on` / `.off` once the bundle script has loaded.

These six events cover **both** bundle types — a multi-option bundle fires the same `elite:byob:*` events as a build-your-own bundle. See the [Bundle SDK](/reference/sdk.md) for why the two share one surface.

```js
document.addEventListener('elite:byob:ready', () => {
  const sdk = window.eliteBundle.sdk?.byob;
});
```

> `window.eliteBundle.on` is added by the bundle script, which loads deferred. Theme code that runs earlier should use `document.addEventListener` directly — the events fire on `document` either way.

***

### `elite:byob:ready`

Fired once the bundle has finished loading its products and rendered. This is the safe point to start reading `window.eliteBundle.sdk.byob`.

It can fire again if the bundle reloads its products, so make your handler safe to run more than once.

**Detail:**

```ts
{
  bundleId: string;   // Shopify product ID
  stepCount: number;  // number of steps (options, for a multi-option bundle)
}
```

```js
document.addEventListener('elite:byob:ready', (event) => {
  const { bundleId, stepCount } = event.detail;
  const sdk = window.eliteBundle.sdk?.byob;
  if (sdk) renderMySteps(sdk.steps);
});
```

***

### `elite:byob:error`

Fired when the bundle fails to load — a Storefront API error, a network failure, or a missing configuration.

**Detail:**

```ts
{
  error: string; // a shopper-facing message, safe to display as-is
}
```

The detail is a single generic message. The diagnostic detail is logged to the browser console instead, so there is nothing more specific to surface.

***

### `elite:byob:cart-change`

Fired whenever the selection or the checkout state changes — including once on first load, so a handler alone is enough to render your initial UI.

**Detail:**

```ts
{
  cart: CartItem[];
  cartTotal: number;    // rounded to 2 decimals
  cartCount: number;
  canCheckout: boolean;
}
```

The detail carries the **raw** total. Use `sdk.formatPrice(cartTotal)`, or read `sdk.cartTotalFormatted`, to display it.

```js
document.addEventListener('elite:byob:cart-change', (event) => {
  const { cart, cartTotal, cartCount, canCheckout } = event.detail;
  const sdk = window.eliteBundle.sdk?.byob;

  document.querySelector('#cart-count').textContent = cartCount;
  document.querySelector('#cart-total').textContent = sdk.formatPrice(cartTotal);
  document.querySelector('#checkout-btn').disabled = !canCheckout;
});
```

***

### `elite:byob:checkout-start`

Fired when the bundle starts being added to the Shopify cart. Use it to show a loading state.

**Detail:**

```ts
{
  cart: CartItem[];
  cartTotal: number;
  cartCount: number;
}
```

***

### `elite:byob:checkout-success`

Fired after the bundle is added to the cart, before any redirect.

**Detail:**

```ts
{
  redirectTarget: "stay_on_page" | "cart" | "checkout";
}
```

The bundle is emptied at this point and a new bundle session begins. With `stay_on_page`, expect a follow-up `cart-change` with an empty cart.

***

### `elite:byob:checkout-error`

Fired when adding to the cart fails — for example a variant that sold out between selection and checkout.

**Detail:**

```ts
{
  error: string;
}
```

***

## Event timing

`elite:byob:ready` may fire before your own script runs. Handle both cases by checking whether the SDK is already populated:

```js
function onBundleReady(callback) {
  const sdk = window.eliteBundle?.sdk?.byob;
  if (sdk && !sdk.isLoading && !sdk.error) {
    callback();          // already loaded
  } else {
    document.addEventListener('elite:byob:ready', callback, { once: true });
  }
}
```

Do not gate this on `window.eliteBundle.sdk` existing — the bundle script is deferred, so `sdk` appears later than `window.eliteBundle` itself. Listening on `document` always works.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.elitebundleapp.com/reference/events.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
