JavaScript API
Ekoo exposes global JavaScript functions for programmatic widget control. Use these when you need more than data attributes alone.
ekooLoad()
Turns the <div data-ekoo> placeholders and the window.ekooOptions entries present in the page into widgets. The script calls it when it loads. After that, a new call has no effect until ekooUnload() has been called: a <div data-ekoo> added later stays empty. An <ekoo-widget> element does not need it: it starts as soon as it is inserted into the page.
Signature
1window.ekooLoad(): voidUsage
1// Adding a widget after the script has loaded: insert <ekoo-widget> directly2const widget = document.createElement('ekoo-widget');3widget.setAttribute('data-ekoo', 'YOUR_WEBSITE_ID');4widget.setAttribute('data-ekoo-product-id', 'SKU-1234');5widget.setAttribute('data-ekoo-locale', 'fr');6document.querySelector('.product-detail').appendChild(widget);78// ekooLoad() would not help here: after the first initialization,9// it no longer scans the page until ekooUnload() is called.When to use: normally never. To add a widget after the script has loaded, for example from a tag manager, insert an <ekoo-widget> element directly, as above.
ekooUnload()
Destroys the widgets created from placeholders or window.ekooOptions and puts the placeholders back. Also removes the <ekoo-widget> elements from the page, which ekooLoad() does not recreate.
Signature
1window.ekooUnload(): voidUsage
1// Before removing <div data-ekoo> placeholders yourself2window.ekooUnload();34// Also removes every <ekoo-widget> element from the page.When to use: before removing <div data-ekoo> placeholders yourself. If your framework renders <ekoo-widget>, do not call it: removing the element is enough, it cleans up after itself.
ekooReload()
Calls ekooUnload() then ekooLoad(): widgets built from placeholders and window.ekooOptions are recreated, <ekoo-widget> elements are removed.
Signature
1window.ekooReload(): voidUsage
1// window.ekooOptions changed after the script loaded2window.ekooOptions.widgets[0].productId = 'SKU-5678';3window.ekooReload();45// To change the product of an <ekoo-widget>, set its attribute instead:6document.querySelector('ekoo-widget')?.setAttribute('data-ekoo-product-id', 'SKU-5678');When to use: after changing window.ekooOptions. To change the product of an <ekoo-widget>, set only its data-ekoo-product-id attribute: the widget reloads. Do not call ekooReload() afterwards, it would remove the element.
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 audioPreload?: "metadata" | "none"; // Standalone 4.0.0 only; "none" disables autoplay9 }>;10}1112// HTML data attributes (on each widget container):13// Core14// data-ekoo="WEBSITE_ID" — required, your website UUID15// data-ekoo-product-id="PRODUCT_ID" — required, product identifier16// data-ekoo-locale="fr" — optional, "fr", "en", "auto", etc.17// data-ekoo-variant="WIDGET_CONFIG_REF" — optional, reference of a widget configuration saved in the backoffice18// data-ekoo-review-id="REVIEW_ID" — optional, target a specific review19// data-ekoo-on-event="callbackFnName" — optional, window function name for event callback20//21// Appearance22// data-ekoo-direction="normal" — "normal" (default) or "reverse"23// data-ekoo-scale="1.2" — numeric scale factor24// data-ekoo-animation="pulse" — animation type (default: "pulse")25// data-ekoo-animation-duration="continuous" — animation duration26// data-ekoo-always-open="true" — keep player always expanded27// data-ekoo-show-image="true" — show product image (default: true)28// data-ekoo-not-fully-clickable="true" — restrict click zone to play button29// data-ekoo-autoplay="true" — auto-play audio on load30// data-ekoo-audio-preload="none" — standalone 4.0.0 only; load on first play (disables autoplay)31// data-ekoo-show-transcript="true" — show transcript button32// data-ekoo-show-speed-button="true" — show playback speed button33// data-ekoo-closed-state-main-text="..." — main CTA text when closed34// data-ekoo-closed-state-secondary-text="..." — secondary text when closed35//36// SPA & Shadow DOM37// data-ekoo-mode="spa" — "spa" or "static" (auto-detected by default)38// data-shadow-mode="closed" — "open" or "closed" (default: "open")39//40// Global JS config41// window.EKOO_FORCE_SPA = true — force SPA mode for all widgets42// 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 or changing it afterward has no automatic effect. To apply it, call ekooReload(), which also removes the <ekoo-widget> elements from the page (see above). 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 | Mounts the <div data-ekoo> and window.ekooOptions; no effect after the first initialization |
ekooUnload | none | void | Destroys the widgets and removes the <ekoo-widget> elements from the page |
ekooReload | none | void | ekooUnload() then ekooLoad(); <ekoo-widget> elements are not recreated |
Related Resources
- Attributes Reference — All data attributes for the widget element
- Events Reference — All events emitted by Ekoo widgets