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

typescript
1window.ekooLoad(): void

Usage

Adding a widget after the script has loaded
javascript
1// Adding a widget after the script has loaded: insert <ekoo-widget> directly
2const 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);
7
8// 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

typescript
1window.ekooUnload(): void

Usage

Cleanup
javascript
1// Before removing <div data-ekoo> placeholders yourself
2window.ekooUnload();
3
4// 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

typescript
1window.ekooReload(): void

Usage

Reload after a window.ekooOptions change
javascript
1// window.ekooOptions changed after the script loaded
2window.ekooOptions.widgets[0].productId = 'SKU-5678';
3window.ekooReload();
4
5// 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

PropertyTypeDescription
websiteIdstringYour Ekoo website UUID
widgetsArrayArray of widget configurations (see structure below)
widgets[].nodeIdstring | () => HTMLElementTarget element ID or function returning the element
widgets[].productIdstring | () => stringProduct ID or function returning the ID
widgets[].localestring | () => stringOptional locale (ISO 639-1 code)
Complete ekooOptions example
javascript
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.
4
5<ekoo-widget
6 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>
19
20// --- Method 2: JavaScript configuration (for dynamic insertion) ---
21
22window.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

window.ekooOptions interface
typescript
1// window.ekooOptions structure
2interface EkooOptions {
3 websiteId: string; // Your Ekoo website UUID
4 widgets: Array<{
5 nodeId: string | (() => HTMLElement); // Target element ID or function returning element
6 productId: string | (() => string); // Product ID or function returning it
7 locale?: string | (() => string); // Optional locale ("fr", "en", "auto")
8 audioPreload?: "metadata" | "none"; // Standalone 4.0.0 only; "none" disables autoplay
9 }>;
10}
11
12// HTML data attributes (on each widget container):
13// Core
14// data-ekoo="WEBSITE_ID" — required, your website UUID
15// data-ekoo-product-id="PRODUCT_ID" — required, product identifier
16// 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 backoffice
18// data-ekoo-review-id="REVIEW_ID" — optional, target a specific review
19// data-ekoo-on-event="callbackFnName" — optional, window function name for event callback
20//
21// Appearance
22// data-ekoo-direction="normal" — "normal" (default) or "reverse"
23// data-ekoo-scale="1.2" — numeric scale factor
24// data-ekoo-animation="pulse" — animation type (default: "pulse")
25// data-ekoo-animation-duration="continuous" — animation duration
26// data-ekoo-always-open="true" — keep player always expanded
27// data-ekoo-show-image="true" — show product image (default: true)
28// data-ekoo-not-fully-clickable="true" — restrict click zone to play button
29// data-ekoo-autoplay="true" — auto-play audio on load
30// data-ekoo-audio-preload="none" — standalone 4.0.0 only; load on first play (disables autoplay)
31// data-ekoo-show-transcript="true" — show transcript button
32// data-ekoo-show-speed-button="true" — show playback speed button
33// data-ekoo-closed-state-main-text="..." — main CTA text when closed
34// data-ekoo-closed-state-secondary-text="..." — secondary text when closed
35//
36// SPA & Shadow DOM
37// 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 config
41// window.EKOO_FORCE_SPA = true — force SPA mode for all widgets
42// window.ekooShadowMode = "open" — global shadow DOM mode
⚠️

Define Before Script Load

Define 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

FunctionParametersReturnsDescription
ekooLoadnonevoidMounts the <div data-ekoo> and window.ekooOptions; no effect after the first initialization
ekooUnloadnonevoidDestroys the widgets and removes the <ekoo-widget> elements from the page
ekooReloadnonevoidekooUnload() then ekooLoad(); <ekoo-widget> elements are not recreated

Related Resources