Magento / Adobe Commerce Integration
Magento 2 module that renders the Ekoo transcript on the server, inside the full page cache
data-ekooReqdata-ekoo-product-idReqdata-ekoo-localeautodata-ekoo-variantdata-ekoo-review-iddata-ekoo-on-eventdata-ekoo-directionnormaldata-ekoo-scale1data-ekoo-animationpulsedata-ekoo-animation-durationcontinuousdata-ekoo-always-openfalsedata-ekoo-show-imagetruedata-ekoo-not-fully-clickablefalsedata-ekoo-autoplayfalsedata-ekoo-audio-preloadmetadatadata-ekoo-show-transcriptfalsedata-ekoo-show-speed-buttonfalsedata-ekoo-closed-state-main-textdata-ekoo-closed-state-secondary-textdata-ekoo-modeautodata-shadow-modeopenwindow.EKOO_FORCE_SPA = truewindow.ekooShadowMode = "open"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 tobin/magento. - Luma or Hyvä theme: the template uses no JavaScript.
Three values to prepare
- Website ID: in the backoffice, Settings → Organization, Organization ID field, or in the
data-ekooattribute of the widget already installed. - Product reference: exactly the one in
data-ekoo-product-idon your site and in Ekoo (ID or SKU), without changing convention. - Language: an explicit value such as
froren, the same asdata-ekoo-locale. Neverauto.
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.
1<?php2// app/code/Ekoo/Widget/registration.php3use Magento\Framework\Component\ComponentRegistrar;45ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Ekoo_Widget', __DIR__);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.
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.
1<?php2// app/code/Ekoo/Widget/ViewModel/Ekoo.php3declare(strict_types=1);45namespace Ekoo\Widget\ViewModel;67use 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;1415class Ekoo implements ArgumentInterface16{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'];1920 public function __construct(21 private readonly ScopeConfigInterface $scopeConfig,22 private readonly CurlFactory $curlFactory,23 private readonly CacheInterface $cache,24 private readonly Json $json25 ) {26 }2728 // Values entered in Stores > Configuration > Catalog > Catalog > Ekoo, per store view.29 public function getWebsiteId(): string30 {31 return trim((string) $this->scopeConfig->getValue('catalog/ekoo/website_id', ScopeInterface::SCOPE_STORE));32 }3334 // Same value as data-ekoo-locale. Never 'auto': the server does not know the browser language.35 public function getLocale(): string36 {37 return trim((string) $this->scopeConfig->getValue('catalog/ekoo/locale', ScopeInterface::SCOPE_STORE));38 }3940 // 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): string42 {43 return (string) $product->getSku();44 }4546 /**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}|null50 */51 public function getServerBlock(string $productRef): ?array52 {53 $websiteId = $this->getWebsiteId();54 $locale = $this->getLocale();55 if ($websiteId === '' || $productRef === '' || $locale === '' || $locale === 'auto') {56 return null;57 }5859 $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 }6768 // 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): ?array70 {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 }7677 $url = self::ORIGIN . '/ws/websites/' . rawurlencode($websiteId)78 . '/products/' . rawurlencode($productRef)79 . '?' . http_build_query(['locale' => $locale]);8081 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 }9495 // 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 }99100 // 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 }104105 // 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 = ''): ?array107 {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 }118119 // created_at is a PostgreSQL timestamp ("2026-09-04 15:56:31.998283+00"), not ISO 8601.120 private function uploadDate(?string $value): ?string121 {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 }128129 // AudioObject JSON-LD: data-ekoo-audio-id tells the widget not to add a second one.130 private function buildJsonLd(array $product, array $review): string131 {132 $extension = strtolower(pathinfo((string) parse_url($review['audio_url'], PHP_URL_PATH), PATHINFO_EXTENSION));133 $author = trim(($review['user']['firstname'] ?? '') . ' ' . ($review['user']['lastname'] ?? ''));134135 $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 ];147148 // 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_UNICODE152 );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.
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>1<?php2// app/code/Ekoo/Widget/view/frontend/templates/product/ekoo.phtml3/** @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.
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>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>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.
1bin/magento module:enable Ekoo_Widget2bin/magento setup:upgrade3bin/magento cache:flushFull 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
- Transcript in the source code: view the page source (Ctrl+U), look for
data-ekoo-audio-idand a sentence of the transcript. - Playback: the player shows up and the audio starts on click.
- 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:
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>1<?php2/** @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>