Magento / Adobe Commerce Integration

Magento 2 module that renders the Ekoo transcript on the server, inside the full page cache

The widget auto-loads its config from the backoffice. Appearance attributes are optional overrides — no need to set them if the backoffice is configured.
Core attributes
data-ekooReq
string
Your Ekoo website UUID: backoffice, Settings → Organization, Organization ID field.
data-ekoo-product-idReq
string
Product reference (must match exactly what is in your Ekoo catalog).
data-ekoo-locale
string·default: auto
Locale code: fr, en, es, it, de, ar, cn, tw, hk, jp, kr, nl, tr, pl, pt, lu, be, ru. "auto" = navigator.language detection.
data-ekoo-variant
string
Stable reference of a widget configuration. The product, its audios, and its reviewers still come from data-ekoo-product-id; only the widget styling changes.
data-ekoo-review-id
string
ID of a specific audio review. If omitted: the product's default audio, otherwise the first published audio.
data-ekoo-on-event
string (fn name)
Name of a global window function called on each widget event (printed, played-0, played-25…).
Appearance — backoffice overrides
data-ekoo-direction
normal | reverse·default: normal
Expansion direction. normal = left-to-right, reverse = right-to-left.
data-ekoo-scale
number·default: 1
Scale factor (e.g. "1.2" for 20% larger).
data-ekoo-animation
string·default: pulse
Animation type for the widget icon at rest.
data-ekoo-animation-duration
string·default: continuous
Animation duration.
data-ekoo-always-open
boolean·default: false
If "true", the widget stays permanently expanded.
data-ekoo-show-image
boolean·default: true
Show or hide the product image in the widget.
data-ekoo-not-fully-clickable
boolean·default: false
If "true", only the play button is clickable.
data-ekoo-autoplay
boolean·default: false
Automatically start audio playback on load.
data-ekoo-audio-preload
metadata | none·default: metadata
Standalone 4.0.0: overrides the backoffice setting. “none” waits until the first click to load the file and disables autoplay.
data-ekoo-show-transcript
boolean·default: false
Show a button to read the audio transcript.
data-ekoo-show-speed-button
boolean·default: false
Show a playback speed control.
data-ekoo-closed-state-main-text
string
Main CTA text shown when the widget is collapsed.
data-ekoo-closed-state-secondary-text
string
Secondary text below the CTA when the widget is collapsed.
SPA & Shadow DOM
data-ekoo-mode
spa | static·default: auto
Forces rendering mode. Auto-detected (Next.js, Nuxt, React, Vue, Angular, Sapper). Only use if auto-detection fails.
data-shadow-mode
open | closed·default: open
"open" (default) enables inspection, external CSS access and analytics tracking. Set to "closed" to fully isolate the widget.
Global JS config
window.EKOO_FORCE_SPA = true
Forces SPA mode globally (alternative to data-ekoo-mode="spa" on each widget).
window.ekooShadowMode = "open"
Global Shadow DOM mode (alternative to data-shadow-mode on each widget).

Magento renders your product pages on the server. This module adds the transcript and its JSON-LD to the initial HTML, readable without JavaScript. Ekoo is only called when the page is generated, which then goes into the full page cache, and its response is kept for 15 minutes in the Magento cache.

Before you start

Requirements

  • Magento Open Source or Adobe Commerce 2.4.4 or later, with PHP 8.1 or later.
  • Access to the store code (app/code) and to bin/magento.
  • Luma or Hyvä theme: the template uses no JavaScript.

Three values to prepare

  1. Website ID: in the backoffice, Settings → Organization, Organization ID field, or in the data-ekoo attribute of the widget already installed.
  2. Product reference: exactly the one in data-ekoo-product-id on your site and in Ekoo (ID or SKU), without changing convention.
  3. Language: an explicit value such as fr or en, the same as data-ekoo-locale. Never auto.

Is an A/B experiment comparing the widget with no widget running on these pages? Read the server rendering limits first.

⚠️

Test on a staging environment first

The PHP code of this module is tested with PHP 8.2 and the XML files follow the Magento schemas, but we have not installed the module on a Magento store yet. Install it on staging first.

⚠️

Keep the product reference of your current integration

The reference sent to the API and data-ekoo-product-id must be exactly the one already stored in Ekoo. The module uses the SKU; if your integration uses the Magento ID, replace getSku() with getId() in getProductRef.

1. Create the module

Create the app/code/Ekoo/Widget folder and these two files.

app/code/Ekoo/Widget/registration.php
php
1<?php
2// app/code/Ekoo/Widget/registration.php
3use Magento\Framework\Component\ComponentRegistrar;
4
5ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Ekoo_Widget', __DIR__);
app/code/Ekoo/Widget/etc/module.xml
xml
1<?xml version="1.0"?>
2<!-- app/code/Ekoo/Widget/etc/module.xml -->
3<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
4 <module name="Ekoo_Widget">
5 <sequence>
6 <module name="Magento_Catalog"/>
7 </sequence>
8 </module>
9</config>

2. Add the configuration

These fields show up in Stores → Configuration → Catalog → Catalog → Ekoo. Enter the website ID, then the language for each store view. Without a language, the module shows the widget alone, without calling Ekoo.

app/code/Ekoo/Widget/etc/adminhtml/system.xml
xml
1<?xml version="1.0"?>
2<!-- app/code/Ekoo/Widget/etc/adminhtml/system.xml -->
3<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
4 <system>
5 <section id="catalog">
6 <group id="ekoo" translate="label" sortOrder="900" showInDefault="1" showInWebsite="1" showInStore="1">
7 <label>Ekoo</label>
8 <field id="website_id" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
9 <label>Website ID</label>
10 </field>
11 <field id="locale" translate="label comment" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
12 <label>Locale</label>
13 <comment>Same value as data-ekoo-locale, for example en. Empty: the widget alone, without server rendering.</comment>
14 </field>
15 </group>
16 </section>
17 </system>
18</config>

3. Fetch the data

This view model calls Ekoo, picks the audio the way the widget does and builds the JSON-LD, with the same logic as the other integrations. There is nothing to change in it, except the product reference if needed.

app/code/Ekoo/Widget/ViewModel/Ekoo.php
php
1<?php
2// app/code/Ekoo/Widget/ViewModel/Ekoo.php
3declare(strict_types=1);
4
5namespace Ekoo\Widget\ViewModel;
6
7use Magento\Catalog\Api\Data\ProductInterface;
8use Magento\Framework\App\CacheInterface;
9use Magento\Framework\App\Config\ScopeConfigInterface;
10use Magento\Framework\HTTP\Client\CurlFactory;
11use Magento\Framework\Serialize\Serializer\Json;
12use Magento\Framework\View\Element\Block\ArgumentInterface;
13use Magento\Store\Model\ScopeInterface;
14
15class Ekoo implements ArgumentInterface
16{
17 private const ORIGIN = 'https://app.ekoo.co';
18 private const AUDIO_FORMATS = ['mp3' => 'audio/mpeg', 'm4a' => 'audio/mp4', 'ogg' => 'audio/ogg', 'wav' => 'audio/wav'];
19
20 public function __construct(
21 private readonly ScopeConfigInterface $scopeConfig,
22 private readonly CurlFactory $curlFactory,
23 private readonly CacheInterface $cache,
24 private readonly Json $json
25 ) {
26 }
27
28 // Values entered in Stores > Configuration > Catalog > Catalog > Ekoo, per store view.
29 public function getWebsiteId(): string
30 {
31 return trim((string) $this->scopeConfig->getValue('catalog/ekoo/website_id', ScopeInterface::SCOPE_STORE));
32 }
33
34 // Same value as data-ekoo-locale. Never 'auto': the server does not know the browser language.
35 public function getLocale(): string
36 {
37 return trim((string) $this->scopeConfig->getValue('catalog/ekoo/locale', ScopeInterface::SCOPE_STORE));
38 }
39
40 // Same reference as data-ekoo-product-id on the rest of the site: the SKU here, replace it with getId() if your integration uses the ID.
41 public function getProductRef(ProductInterface $product): string
42 {
43 return (string) $product->getSku();
44 }
45
46 /**
47 * Audio and JSON-LD to render, or null: empty or "auto" locale, unknown product, Ekoo unavailable.
48 *
49 * @return array{review: array, jsonLd: string}|null
50 */
51 public function getServerBlock(string $productRef): ?array
52 {
53 $websiteId = $this->getWebsiteId();
54 $locale = $this->getLocale();
55 if ($websiteId === '' || $productRef === '' || $locale === '' || $locale === 'auto') {
56 return null;
57 }
58
59 $product = $this->fetchProduct($websiteId, $productRef, $locale);
60 $review = $product ? $this->selectReview($product) : null;
61 // An empty or whitespace-only transcript adds nothing.
62 if (!$review || preg_match('/[^\s\p{Z}]/u', (string) ($review['transcript'] ?? '')) !== 1) {
63 return null;
64 }
65 return ['review' => $review, 'jsonLd' => $this->buildJsonLd($product, $review)];
66 }
67
68 // Returns the product, or null when Ekoo has nothing to render (unknown product, error, timeout).
69 private function fetchProduct(string $websiteId, string $productRef, string $locale): ?array
70 {
71 $cacheKey = 'ekoo_product_' . md5($websiteId . '|' . $locale . '|' . $productRef);
72 $cached = $this->cache->load($cacheKey);
73 if (is_string($cached) && $cached !== '') {
74 return $this->json->unserialize($cached);
75 }
76
77 $url = self::ORIGIN . '/ws/websites/' . rawurlencode($websiteId)
78 . '/products/' . rawurlencode($productRef)
79 . '?' . http_build_query(['locale' => $locale]);
80
81 try {
82 $curl = $this->curlFactory->create();
83 $curl->setTimeout(2);
84 $curl->addHeader('Accept', 'application/json');
85 $curl->get($url);
86 if ($curl->getStatus() !== 200) {
87 return null;
88 }
89 $body = json_decode($curl->getBody(), true);
90 } catch (\Throwable $e) {
91 // Timeout or network error: the page renders without the Ekoo block.
92 return null;
93 }
94
95 // An unknown product answers 200 with { type, message }: test the body, not the status.
96 if (!is_array($body) || isset($body['type']) || !is_array($body['reviews'] ?? null)) {
97 return null;
98 }
99
100 // Only a valid product is kept, for 15 minutes, in the Magento cache (ekoo tag).
101 $this->cache->save($this->json->serialize($body), $cacheKey, ['ekoo'], 900);
102 return $body;
103 }
104
105 // Same choice as the widget: unknown explicit ID → first playable audio; no ID → default audio, then first playable.
106 private function selectReview(array $product, string $reviewId = ''): ?array
107 {
108 $playable = array_values(
109 array_filter($product['reviews'], fn ($review) => !empty($review['audio_url']) && !empty($review['is_active']))
110 );
111 foreach ($playable as $review) {
112 if ($reviewId !== '' ? $review['id'] === $reviewId : !empty($review['is_default'])) {
113 return $review;
114 }
115 }
116 return $playable[0] ?? null;
117 }
118
119 // created_at is a PostgreSQL timestamp ("2026-09-04 15:56:31.998283+00"), not ISO 8601.
120 private function uploadDate(?string $value): ?string
121 {
122 try {
123 return $value ? (new \DateTimeImmutable($value))->setTimezone(new \DateTimeZone('UTC'))->format('Y-m-d\TH:i:s.v\Z') : null;
124 } catch (\Exception $e) {
125 return null;
126 }
127 }
128
129 // AudioObject JSON-LD: data-ekoo-audio-id tells the widget not to add a second one.
130 private function buildJsonLd(array $product, array $review): string
131 {
132 $extension = strtolower(pathinfo((string) parse_url($review['audio_url'], PHP_URL_PATH), PATHINFO_EXTENSION));
133 $author = trim(($review['user']['firstname'] ?? '') . ' ' . ($review['user']['lastname'] ?? ''));
134
135 $data = [
136 '@context' => 'https://schema.org',
137 '@type' => 'AudioObject',
138 'name' => ($product['seo_name'] ?? '') ?: ($product['name'] ?? null),
139 'description' => $product['seo_description'] ?? null,
140 'contentUrl' => $review['audio_url'],
141 'encodingFormat' => self::AUDIO_FORMATS[$extension] ?? null,
142 'inLanguage' => $review['locale'] ?? null,
143 'transcript' => str_replace(["\r\n", "\r"], "\n", $review['transcript']),
144 'uploadDate' => $this->uploadDate($review['created_at'] ?? null),
145 'author' => $author !== '' ? ['@type' => 'Person', 'name' => $author] : null,
146 ];
147
148 // JSON.stringify does not escape "<": a transcript containing "</script>" would close the tag.
149 return (string) json_encode(
150 array_filter($data, fn ($value) => $value !== null && $value !== ''),
151 JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
152 );
153 }
154}

4. Show the block on the product page

The block goes into product.info.main, after the short description. Move it if your theme uses other containers.

app/code/Ekoo/Widget/view/frontend/layout/catalog_product_view.xml
xml
1<?xml version="1.0"?>
2<!-- app/code/Ekoo/Widget/view/frontend/layout/catalog_product_view.xml -->
3<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
4 <body>
5 <referenceContainer name="product.info.main">
6 <!-- Never cacheable="false": every product page would leave the full page cache. -->
7 <block class="Magento\Catalog\Block\Product\View" name="ekoo.widget" template="Ekoo_Widget::product/ekoo.phtml" after="product.info.overview">
8 <arguments>
9 <argument name="ekoo" xsi:type="object">Ekoo\Widget\ViewModel\Ekoo</argument>
10 </arguments>
11 </block>
12 </referenceContainer>
13 </body>
14</page>
app/code/Ekoo/Widget/view/frontend/templates/product/ekoo.phtml
php
1<?php
2// app/code/Ekoo/Widget/view/frontend/templates/product/ekoo.phtml
3/** @var \Magento\Catalog\Block\Product\View $block */
4/** @var \Magento\Framework\Escaper $escaper */
5/** @var \Ekoo\Widget\ViewModel\Ekoo $ekoo */
6$ekoo = $block->getData('ekoo');
7$websiteId = $ekoo->getWebsiteId();
8$locale = $ekoo->getLocale();
9$productRef = $ekoo->getProductRef($block->getProduct());
10$server = $ekoo->getServerBlock($productRef);
11?>
12<?php if ($server): ?>
13<script type="application/ld+json" data-ekoo-seo="server" data-ekoo-audio-id="<?= $escaper->escapeHtmlAttr($server['review']['id']) ?>"><?= /* @noEscape */ $server['jsonLd'] ?></script>
14<?php /* Transcript: text escaped by the framework, next to the widget and never inside it. */ ?>
15<section class="ekoo-transcript">
16 <details>
17 <summary><?= $escaper->escapeHtml(__('Read the transcript')) ?></summary>
18 <p style="white-space: pre-line"><?= $escaper->escapeHtml($server['review']['transcript']) ?></p>
19 </details>
20</section>
21<?php endif; ?>
22<?php if ($websiteId !== ''): ?>
23<?php /* The widget stays client-side: it becomes interactive once its script loads. */ ?>
24<div data-ekoo="<?= $escaper->escapeHtmlAttr($websiteId) ?>" data-ekoo-product-id="<?= $escaper->escapeHtmlAttr($productRef) ?>"<?php if ($locale !== ''): ?> data-ekoo-locale="<?= $escaper->escapeHtmlAttr($locale) ?>"<?php endif; ?>></div>
25<?php endif; ?>

5. Load the script and allow the widget

The widget script is added once for the whole store. The next two files allow the widget in the Magento content security policy (CSP): by default it only blocks on payment pages, but a store that hardens it would mute the player without them.

app/code/Ekoo/Widget/view/frontend/layout/default_head_blocks.xml
xml
1<?xml version="1.0"?>
2<!-- app/code/Ekoo/Widget/view/frontend/layout/default_head_blocks.xml -->
3<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
4 <head>
5 <!-- Widget script, loaded once for the whole site. -->
6 <script src="https://app.ekoo.co/widgets/widget-4.0.0-standalone.js" src_type="url" defer="defer"/>
7 </head>
8</page>
app/code/Ekoo/Widget/etc/csp_whitelist.xml
xml
1<?xml version="1.0"?>
2<!-- app/code/Ekoo/Widget/etc/csp_whitelist.xml -->
3<!-- Widget script, API, audio files and images. -->
4<csp_whitelist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Csp:etc/csp_whitelist.xsd">
5 <policies>
6 <policy id="script-src">
7 <values>
8 <value id="ekoo" type="host">app.ekoo.co</value>
9 </values>
10 </policy>
11 <policy id="connect-src">
12 <values>
13 <value id="ekoo" type="host">app.ekoo.co</value>
14 <value id="ekoo-media" type="host">qafalzqaomwrrfdmvlno.supabase.co</value>
15 </values>
16 </policy>
17 <policy id="media-src">
18 <values>
19 <value id="ekoo-media" type="host">qafalzqaomwrrfdmvlno.supabase.co</value>
20 </values>
21 </policy>
22 <policy id="img-src">
23 <values>
24 <value id="ekoo-media" type="host">qafalzqaomwrrfdmvlno.supabase.co</value>
25 </values>
26 </policy>
27 </policies>
28</csp_whitelist>
app/code/Ekoo/Widget/etc/config.xml
xml
1<?xml version="1.0"?>
2<!-- app/code/Ekoo/Widget/etc/config.xml -->
3<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
4 <default>
5 <csp>
6 <policies>
7 <storefront>
8 <!-- The widget plays the preloaded audio from a blob: URL. -->
9 <media>
10 <schemes>
11 <blob>blob</blob>
12 </schemes>
13 </media>
14 </storefront>
15 </policies>
16 </csp>
17 </default>
18</config>

6. Enable the module

In production mode, also run bin/magento setup:di:compile and bin/magento setup:static-content:deploy.

Terminal
bash
1bin/magento module:enable Ekoo_Widget
2bin/magento setup:upgrade
3bin/magento cache:flush
ℹ️

Full page cache

The whole product page goes into the full page cache (or Varnish). A page generated while Ekoo is unavailable stays without a transcript until it expires or is invalidated; the widget itself works normally. Only a valid product is kept in the Magento cache: a page unknown to Ekoo asks again each time the page is generated.

Check

  1. Transcript in the source code: view the page source (Ctrl+U), look for data-ekoo-audio-id and a sentence of the transcript.
  2. Playback: the player shows up and the audio starts on click.
  3. Product change: open another product page; the transcript and the audio must match that product.

Detailed checks, including no duplicate JSON-LD: SSR, SEO & GEO guide.

To show the widget alone, without a transcript in the initial HTML, install the module from the previous tab and leave the language empty. Or, in an existing theme, add the script, then the widget slot in the product template:

view/frontend/layout/default_head_blocks.xml
xml
1<?xml version="1.0"?>
2<!-- app/code/Ekoo/Widget/view/frontend/layout/default_head_blocks.xml -->
3<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
4 <head>
5 <!-- Widget script, loaded once for the whole site. -->
6 <script src="https://app.ekoo.co/widgets/widget-4.0.0-standalone.js" src_type="url" defer="defer"/>
7 </head>
8</page>
Product page template
php
1<?php
2/** @var \Magento\Catalog\Block\Product\View $block */
3/** @var \Magento\Framework\Escaper $escaper */
4?>
5<div data-ekoo="YOUR_WEBSITE_ID" data-ekoo-product-id="<?= $escaper->escapeHtmlAttr($block->getProduct()->getSku()) ?>" data-ekoo-locale="fr"></div>

Going further