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

# Instalación y configuración

> Instala la biblioteca cliente de Komerza e inicializa tu tienda

## Instalación

Incluye la biblioteca cliente de Komerza via CDN. Agrega esta etiqueta de script a tu HTML:

```html theme={null}
<script src="https://cdn.komerza.com/komerza.min.js"></script>
```

La biblioteca está disponible globalmente como `globalThis.komerza` después de que se cargue el script.

### Beneficios del CDN

* **No requiere paso de compilación** - Funciona con HTML/CSS/JS simple
* **Siempre actualizado** - Última versión entregada automáticamente
* **Carga rápida** - Almacenado en caché globalmente via CDN
* **Ligero** - Impacto mínimo en el tiempo de carga de la página

## Inicialización

Inicializa la biblioteca con el ID de tu tienda antes de usar otras funciones:

```javascript theme={null}
komerza.init("tu-id-de-tienda");
```

<Warning>
  **Debes** llamar a `init()` antes de usar cualquier otra función de `komerza`.
  Todas las demás funciones fallarán si la biblioteca no ha sido inicializada.
</Warning>

### Encontrar tu ID de tienda

El ID de tu tienda está disponible en tu panel de Komerza. Es un identificador único para tu tienda, generalmente en formato UUID.

### Ejemplo

```html theme={null}
<!DOCTYPE html>
<html>
  <head>
    <title>Mi Tienda</title>
    <script src="https://cdn.komerza.com/komerza.min.js"></script>
  </head>
  <body>
    <div id="store-name"></div>

    <script>
      // Inicializar con tu ID de tienda
      komerza.init("550e8400-e29b-41d4-a716-446655440000");

      // Ahora puedes usar otras funciones de komerza
      komerza.getStore().then((response) => {
        if (response.success) {
          document.getElementById("store-name").textContent =
            response.data.name;
        }
      });
    </script>
  </body>
</html>
```

## Cuándo inicializar

Llama a `init()` una vez cuando se carga tu página, antes de usar otros métodos de `komerza`:

**✅ Bien - Inicializar al cargar la página:**

```javascript theme={null}
<script>
  // Inicializar inmediatamente komerza.init('tu-id-de-tienda'); // Luego usar
  otras funciones mostrarProductos();
</script>
```

**❌ Mal - Usar métodos antes de init:**

```javascript theme={null}
<script>
  // Esto fallará - init no se ha llamado aún komerza.getStore(); // ¡Error!
  komerza.init('tu-id-de-tienda');
</script>
```

## Integración con frameworks

### JavaScript Vanilla

```html theme={null}
<!DOCTYPE html>
<html>
  <head>
    <script src="https://cdn.komerza.com/komerza.min.js"></script>
  </head>
  <body>
    <script>
      komerza.init("tu-id-de-tienda");
    </script>
  </body>
</html>
```

### React

```jsx theme={null}
import { useEffect } from "react";

function App() {
  useEffect(() => {
    // Inicializar cuando el componente se monta
    if (globalThis.komerza) {
      globalThis.komerza.init("tu-id-de-tienda");
    }
  }, []);

  return <div>Mi Tienda</div>;
}
```

### Vue

```vue theme={null}
<script>
export default {
  mounted() {
    // Inicializar cuando el componente se monta
    if (globalThis.komerza) {
      globalThis.komerza.init("tu-id-de-tienda");
    }
  },
};
</script>
```

### Svelte

```svelte theme={null}
<script>
  import { onMount } from 'svelte';

  onMount(() => {
    // Inicializar cuando el componente se monta
    if (globalThis.komerza) {
      globalThis.komerza.init('tu-id-de-tienda');
    }
  });
</script>
```
