> For the complete documentation index, see [llms.txt](https://docs.liquidcommerce.cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.liquidcommerce.cloud/elements-v2/overview.md).

# Overview

A lightweight, developer-facing guide to integrate LiquidCommerce Elements SDK into your site or app.

### What it is <a href="#what-it-is" id="what-it-is"></a>

Elements SDK is a Web Components-based e-commerce SDK that embeds product, cart, address, and checkout experiences into any website. It works with plain HTML or any framework and exposes a simple client + actions API.

### Core components <a href="#core-components" id="core-components"></a>

* Product: product detail display + add to cart
* Cart: slide-out cart drawer + promo codes
* Checkout: full checkout flow (drawer or hosted page)
* Address: delivery location and availability

### Quick start (CDN) <a href="#quick-start-cdn" id="quick-start-cdn"></a>

```html
<script
  defer
  data-liquid-commerce-elements
  data-token="YOUR_API_KEY"
  data-env="production"
  data-container-1="product"
  data-product-1="00619947000020"
  type="text/javascript"
  src="https://elements.reservebar-worker.workers.dev/all/elements.js"
></script>

<div id="product"></div>
```

> The host `elements.reservebar-worker.workers.dev` is the same for every partner. Each partner has a partner code that goes in the URL path as the first segment — e.g. `https://elements.reservebar-worker.workers.dev/angel/all/elements.js`, where `angel` identifies the partner. The script also works without the partner code (as in the snippet above), but including it is recommended. If you copy your script tag from the partner app, your partner code is already included. The remaining path selects the bundle and sits after the partner code — `/all/elements.js` (full), `/checkout/checkout.js` (checkout-only), `/all/beta/elements.js` (beta) — e.g. `/<partner-code>/all/elements.js`.

### Quick start (NPM) <a href="#quick-start-npm" id="quick-start-npm"></a>

```bash
npm install @liquidcommerce/elements-sdk
```

```js
import { Elements } from '@liquidcommerce/elements-sdk';

const client = await Elements('YOUR_API_KEY', { env: 'production' });
await client.injectProductElement([
  { containerId: 'product', identifier: '00619947000020' }
]);
```

### Initialization modes <a href="#initialization-modes" id="initialization-modes"></a>

* Declarative (auto-setup): data attributes on the script tag shown in **Quick start (CDN)** above, auto-initialized
* Programmatic (NPM or CDN): call `Elements(...)` and inject components

The client is available globally under `window.LiquidCommerce.elements` as soon as the SDK is ready.

> `Elements()`, `ElementsBuilder()`, and `ElementsCheckout()` never reject — on any initialization failure in the browser (bad API key, an auth error, or a config error) the returned promise resolves to `null` instead. Always null-check before using the client.
>
> `ElementsBuilder()` powers LiquidCommerce's internal builder/theme-editor tooling; typical partner integrations use `Elements()` or `ElementsCheckout()`.

```js
const client = await Elements('YOUR_API_KEY', { env: 'production' });
if (!client) {
  // initialization failed — check the console for details
  return;
}
```

### Quick start guide (auto-setup) <a href="#quick-start-guide-auto-setup" id="quick-start-guide-auto-setup"></a>

This is the same declarative CDN script tag from **Quick start (CDN)** above — "auto-setup" is just the name for the SDK reading the `data-*` attributes off that tag to configure itself. Most partners use it because it is the fastest to implement, and it supports rich configuration via data attributes, including product injection, cart buttons, checkout, query param handling, and more.

See [Quick Start Guide](file:///Users/alban/Desktop/syntacticops/repos/liquidcommerce/elements-sdk/docs/gitbook/quick-start-guide.md) for the complete list of supported attributes and combinations.

### Configuration basics <a href="#configuration-basics" id="configuration-basics"></a>

```js
const client = await Elements('YOUR_API_KEY', {
  env: 'production', // staging | production
});
```

### Client surface (exposed methods) <a href="#client-surface-exposed-methods" id="client-surface-exposed-methods"></a>

After initialization, the client exposes three main groups: injection methods, `actions`, and `ui` helpers, plus component management.

#### Injection methods <a href="#injection-methods" id="injection-methods"></a>

Use these to mount SDK components into your DOM. Each method is shown with a minimal example.

> Make sure a component's target container already exists in the DOM before injecting — behavior on a missing container varies by method. `injectAddressElement`, `injectCartElement`, and `injectCheckoutElement` treat it as a no-op, logging a warning and returning `null` rather than throwing; `injectProductElement` skips the missing container and injects the rest; the product-list methods (`injectProductList`, `injectProductListSearch`, `injectProductListFilters`) throw an `SDKError`.

**`injectProductElement(params[])`**

Inject one or more product components by container ID + product identifier. Limited to 20 products per call — extras are **silently dropped**. The diagnostic goes through the SDK logger, which is disabled in production and at the default `debugMode: 'none'`, so in a live storefront there is no console output at all. Batch your calls, or use `injectProductList` for larger grids.

```js
await client.injectProductElement([
  { containerId: 'product-1', identifier: '00619947000020' },
  { containerId: 'product-2', identifier: '08504405135' }
]);
```

**`injectAddressElement(containerId, options?)`**

Inject a standalone address component. Listen for address changes via the published `lce:actions.address_updated` event.

```js
await client.injectAddressElement('address', {
  showLabel: true
});

window.addEventListener('lce:actions.address_updated', (event) => {
  console.log(event.detail.data);
});
```

**`injectCartElement(containerId)`**

Inject a standalone cart component (rare; cart drawer is automatic).

```js
await client.injectCartElement('cart');
```

**`injectCheckoutElement(params)`**

Inject a hosted checkout into a container.

```js
await client.injectCheckoutElement({
  containerId: 'checkout',
  checkoutId: 'checkout_abc123',
  hideHeader: false
});
```

#### Actions (`client.actions.*`) <a href="#actions-clientactions" id="actions-clientactions"></a>

Actions are programmatic controls for state changes and flows. The full list with details is in [Actions](file:///Users/alban/Desktop/syntacticops/repos/liquidcommerce/elements-sdk/docs/gitbook/actions.md).

```js
// Example: add to cart and open cart
await window.LiquidCommerce.elements.actions.cart.addProduct([
  { identifier: '00619947000020', fulfillmentType: 'shipping', quantity: 1 }
], true);
```

#### UI helpers (`client.ui.*`) <a href="#ui-helpers-clientui" id="ui-helpers-clientui"></a>

Helpers for common cart UI elements that stay in sync automatically.

**`ui.cartButton(containerId, showItemsCount?)`**

Renders a cart button in a container.

```js
window.LiquidCommerce.elements.ui.cartButton('header-cart', true);
```

**`ui.floatingCartButton(showItemsCount?)`**

Renders a floating cart button (bottom-right).

```js
window.LiquidCommerce.elements.ui.floatingCartButton(true);
```

**`ui.cartSubtotal(elementId)`**

Keeps a DOM element updated with cart subtotal.

```html
<span id="cart-total"></span>
```

```js
window.LiquidCommerce.elements.ui.cartSubtotal('cart-total');
```

**`ui.cartItemsCount(elementId, { hideZero })`**

Keeps a DOM element updated with item count.

```html
<span id="items-count"></span>
```

```js
window.LiquidCommerce.elements.ui.cartItemsCount('items-count', { hideZero: true });
```

#### Component management <a href="#component-management" id="component-management"></a>

You can inspect and re-render injected components.

* `getInjectedComponents()`\
  Returns a map of injected components keyed by container ID.

```js
const components = client.getInjectedComponents();
const productComponent = components.get('product-1');

productComponent.getType();    // 'product'
productComponent.getElement(); // underlying element
productComponent.rerender();   // force re-render
productComponent.destroy();    // remove from DOM and clean up
```

* `destroy()` Removes the client and all injected components, cleaning up event listeners and internal state.

```js
client.destroy();
```

### Recommended flow <a href="#recommended-flow" id="recommended-flow"></a>

1. Initialize the client
2. Inject product(s)
3. Let the cart drawer handle checkout by default
4. Use actions + events to track analytics and UI updates

***

**Next:** [Quick Start Guide](https://docs.liquidcommerce.cloud/elements-v2/quick-start-guide.md)

**Components:** [Product](https://docs.liquidcommerce.cloud/elements-v2/product.md) · [Address](https://docs.liquidcommerce.cloud/elements-v2/address.md) · [Cart](https://docs.liquidcommerce.cloud/elements-v2/cart.md) · [Checkout](https://docs.liquidcommerce.cloud/elements-v2/checkout.md)

**Reference:** [Actions](https://docs.liquidcommerce.cloud/elements-v2/actions.md) · [Events](https://docs.liquidcommerce.cloud/elements-v2/events.md) · [Advanced](https://docs.liquidcommerce.cloud/elements-v2/advanced.md) · [Theming](https://docs.liquidcommerce.cloud/elements-v2/theming.md) · [Configuration](https://docs.liquidcommerce.cloud/elements-v2/configuration.md)
