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.

SituationWhat to do
<ekoo-widget> written in the page or rendered by a frameworkNothing: bind data-ekoo-product-id to the route or the page data.
The product changes without a page loadSet data-ekoo-product-id on the <ekoo-widget> element (example below).
A widget is added after the script has loadedInsert an <ekoo-widget>: a <div data-ekoo> added at that point stays empty, even with ekooLoad().
You remove <div data-ekoo> placeholders yourselfCall ekooUnload() before removing them.
window.ekooOptions changes after the script has loadedCall ekooReload().
Product change
javascript
1// The product changes without a page load: set the attribute, the widget reloads
2document.querySelector('ekoo-widget')
3 .setAttribute('data-ekoo-product-id', 'SKU-5678');
⚠️

ekooUnload() and ekooReload() remove <ekoo-widget> elements

Both functions remove every <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-ekoo attribute (or an <ekoo-widget> element) is present in the DOM.
  • The websiteId is valid.
  • A productId is 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.

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