JavaScript API
Ekoo exposes global JavaScript functions for programmatic widget control. Use these when you need more than data attributes alone.
ekooLoad()
Initializes all <ekoo-widget> elements on the page. This function is called automatically when the Ekoo script loads, but you can invoke it manually when widgets are added to the DOM dynamically.
Signature
1window.ekooLoad(): voidUsage
1// Initialize all widgets on the page2window.ekooLoad();34// Typically called:5// - After dynamically adding widget containers to the DOM6// - On SPA route change (after DOM update)7// - After script lazy-loadingWhen to use: After dynamically adding <ekoo-widget> elements to the DOM — for example, in a single-page application after a route change or after injecting widget markup via JavaScript.
ekooUnload()
Destroys all active widget instances. Removes event listeners and cleans up resources associated with every Ekoo widget on the page.
Signature
1window.ekooUnload(): voidUsage
1// Remove all widgets — always call on unmount in a SPA2window.ekooUnload();When to use: During SPA page transitions, component unmounting, or any scenario where you need to tear down widgets and free their resources before navigating away.
ekooReload()
Convenience method that calls ekooUnload() followed by ekooLoad(). Reinitializes all widgets on the page with their current attributes.
Signature
1window.ekooReload(): voidUsage
1// Update the displayed product2const container = document.querySelector('[data-ekoo-product-id]');3container.setAttribute('data-ekoo-product-id', 'new-product');45// Unload + reload in one call6window.ekooReload();When to use: After changing a product ID, switching locale, or any context change that requires widgets to refresh with new data.
ekooOptions
A global configuration object that sets default values for all Ekoo widgets on the page. Must be defined before the Ekoo script loads.
Properties
| Property | Type | Description |
|---|---|---|
websiteId | string | Your Ekoo website UUID |
widgets | Array | Array of widget configurations (see structure below) |
widgets[].nodeId | string | () => HTMLElement | Target element ID or function returning the element |
widgets[].productId | string | () => string | Product ID or function returning the ID |
widgets[].locale | string | () => string | Optional locale (ISO 639-1 code) |
1// --- Method 1: HTML data attributes (recommended) ---2// Configuration is set directly on the container element.3// The websiteId is the value of data-ekoo.45<ekoo-widget6 data-ekoo="YOUR_WEBSITE_ID"7 data-ekoo-product-id="YOUR_PRODUCT_ID"8 data-ekoo-locale="fr"9 data-ekoo-variant="WIDGET_CONFIG_REF"10 data-ekoo-on-event="onEkooEvent"11 data-ekoo-always-open="true"12 data-ekoo-direction="reverse"13 data-ekoo-scale="1.2"14 data-ekoo-animation="pulse"15 data-ekoo-show-transcript="true"16 data-ekoo-show-speed-button="true"17 data-shadow-mode="open"18></ekoo-widget>1920// --- Method 2: JavaScript configuration (for dynamic insertion) ---2122window.ekooOptions = {23 websiteId: "YOUR_WEBSITE_ID",24 widgets: [25 {26 nodeId: "container-id", // or: () => document.querySelector('.my-class')27 productId: "YOUR_PRODUCT_ID", // or: () => getProductId()28 locale: "fr" // or: () => getUserLocale()29 }30 ]31};EkooOptions Structure
1// window.ekooOptions structure2interface EkooOptions {3 websiteId: string; // Your Ekoo website UUID4 widgets: Array<{5 nodeId: string | (() => HTMLElement); // Target element ID or function returning element6 productId: string | (() => string); // Product ID or function returning it7 locale?: string | (() => string); // Optional locale ("fr", "en", "auto")8 }>;9}1011// HTML data attributes (on each widget container):12// Core13// data-ekoo="WEBSITE_ID" — required, your website UUID14// data-ekoo-product-id="PRODUCT_ID" — required, product identifier15// data-ekoo-locale="fr" — optional, "fr", "en", "auto", etc.16// data-ekoo-variant="WIDGET_CONFIG_REF" — optional, reference of a widget configuration saved in the backoffice17// data-ekoo-review-id="REVIEW_ID" — optional, target a specific review18// data-ekoo-on-event="callbackFnName" — optional, window function name for event callback19//20// Appearance21// data-ekoo-direction="normal" — "normal" (default) or "reverse"22// data-ekoo-scale="1.2" — numeric scale factor23// data-ekoo-animation="pulse" — animation type (default: "pulse")24// data-ekoo-animation-duration="continuous" — animation duration25// data-ekoo-always-open="true" — keep player always expanded26// data-ekoo-show-image="true" — show product image (default: true)27// data-ekoo-not-fully-clickable="true" — restrict click zone to play button28// data-ekoo-autoplay="true" — auto-play audio on load29// data-ekoo-show-transcript="true" — show transcript button30// data-ekoo-show-speed-button="true" — show playback speed button31// data-ekoo-closed-state-main-text="..." — main CTA text when closed32// data-ekoo-closed-state-secondary-text="..." — secondary text when closed33//34// SPA & Shadow DOM35// data-ekoo-mode="spa" — "spa" or "static" (auto-detected by default)36// data-shadow-mode="closed" — "open" or "closed" (default: "open")37//38// Global JS config39// window.EKOO_FORCE_SPA = true — force SPA mode for all widgets40// window.ekooShadowMode = "open" — global shadow DOM modeDefine Before Script Load
window.ekooOptions before the Ekoo script tag in your HTML. The script reads this configuration on initialization — setting it afterward has no effect. Only the websiteId and widgets properties are supported. Other options (direction, animation, etc.) are configured via HTML data attributes.API Reference
| Function | Parameters | Returns | Description |
|---|---|---|---|
ekooLoad | none | void | Initialize all widgets on the page |
ekooUnload | none | void | Destroy all widget instances |
ekooReload | none | void | Reinitialize all widgets (unload + load) |
Related Resources
- Attributes Reference — All data attributes for the widget element
- Events Reference — All events emitted by Ekoo widgets