Widget Lifecycle
An <ekoo-widget> element manages its own lifecycle: it initializes when it is inserted into the page, reloads the product when data-ekoo-product-id, data-ekoo-locale, data-ekoo-variant or data-ekoo-type changes, and is destroyed when it is removed from the DOM. With a framework (React, Vue, Angular, Svelte, Ionic…), render it in your component and bind its attributes: there is nothing else to call.
The window.ekooLoad(), ekooUnload() and ekooReload() functions are for <div data-ekoo> placeholders and window.ekooOptions, which the script turns into widgets. Signatures and examples: JavaScript API reference.
| Situation | What to do |
|---|---|
| <ekoo-widget> written in the page or rendered by a framework | Nothing: bind data-ekoo-product-id to the route or the page data. |
| The product changes without a page load | Set data-ekoo-product-id on the <ekoo-widget> element (example below). |
| A widget is added after the script has loaded | Insert an <ekoo-widget>: a <div data-ekoo> added at that point stays empty, even with ekooLoad(). |
| You remove <div data-ekoo> placeholders yourself | Call ekooUnload() before removing them. |
| window.ekooOptions changes after the script has loaded | Call ekooReload(). |
1// The product changes without a page load: set the attribute, the widget reloads2document.querySelector('ekoo-widget')3 .setAttribute('data-ekoo-product-id', 'SKU-5678');ekooUnload() and ekooReload() remove <ekoo-widget> elements
<ekoo-widget> element from the page, including the ones your framework manages, and ekooLoad() does not recreate them. Do not call them on a page that uses <ekoo-widget>.Display Conditions
The widget only displays when all of the following conditions are met:
- The Ekoo script is loaded and executed.
- A container with the
data-ekooattribute (or an<ekoo-widget>element) is present in the DOM. - The
websiteIdis valid. - A
productIdis defined and matches an existing product in the backoffice. - At least one published audio is associated with the product.
- The requested locale matches an available locale (if specified).
Configuration Resolution
The widget automatically fetches configuration from the Ekoo backoffice based on the websiteId and productId. Local data-* attributes defined in the HTML take precedence over the remote backoffice configuration.
| Source | Behavior |
|---|---|
Local HTML attributes (data-ekoo-*) | Take precedence. Values defined in HTML are always used first. |
| Remote configuration (backoffice) | Fetched automatically. Used for values not defined locally. |