Ionic / Capacitor Integration
Use the <ekoo-widget> custom element in your Ionic applications (React, Vue, Angular)
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-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"Overview
In an Ionic / Capacitor context, the Ekoo widget is used via the <ekoo-widget> custom element. The script is loaded once in index.html and the lifecycle is managed through the Ionic hooks of each framework.
ekooLoad()— call when the view containing the widget appears.ekooUnload()— call when the view disappears.ekooReload()— to force a complete widget refresh.
1. Load the Script in index.html
Add the Ekoo script to the <head> of your index.html. It will be loaded once when the application starts.
1<head>2 <meta charset="UTF-8" />3 <title>My App</title>4 <script src="https://app.ekoo.co/widgets/widget-4.0.0-standalone.js"</script>5</head>2. Use the Custom Element
Place the <ekoo-widget> custom element in your template with the following attributes:
1<ekoo-widget2 data-ekoo="YOUR_WEBSITE_ID"3 data-ekoo-product-id="MY_PRODUCT_ID"4 data-ekoo-locale="fr"5 data-shadow-mode="open"6></ekoo-widget>Note
As of widget 4.0.0, "open" is the default Shadow DOM mode, which ensures the widget works correctly as a Web Component in the Ionic context. The data-shadow-mode attribute can therefore be omitted.
Key Attributes
| Attribute | Status | Description |
|---|---|---|
data-ekoo | Required | Your unique Ekoo website identifier. |
data-product-id | Required | The product ID matching your Ekoo catalog. |
data-ekoo-variant | Optional | Reference of a widget configuration saved in the backoffice (e.g. "homepage"). Picks the styling to apply; product, audios and reviewers still come from data-ekoo-product-id. |
data-shadow-mode | Optional | "open" is now the default (widget 4.0.0). Only set to "closed" if you need full style isolation. |
3. Dynamic Product ID
The <ekoo-widget> custom element observes attribute changes. To update the product ID dynamically, use setAttribute:
1const widget = document.querySelector('ekoo-widget')2if (widget) {3 widget.setAttribute('data-ekoo-product-id', newProductId)4}ekooReload() after multiple changes
If you notice visual inconsistencies after several product changes, call window.ekooReload() to force a complete widget re-initialization.
4. Ionic React
1import React from 'react'2import {3 IonContent,4 IonPage,5 useIonViewDidEnter,6 useIonViewWillLeave,7} from '@ionic/react'89interface ProductPageProps {10 productId: string11}1213const ProductPage: React.FC<ProductPageProps> = ({ productId }) => {14 useIonViewDidEnter(() => {15 window.ekooLoad?.()16 })1718 useIonViewWillLeave(() => {19 window.ekooUnload?.()20 })2122 return (23 <IonPage>24 <IonContent>25 <h1>My product</h1>26 {/* @ts-expect-error — custom element not typed by default */}27 <ekoo-widget28 data-ekoo="YOUR_WEBSITE_ID"29 data-ekoo-product-id={productId}30 data-ekoo-locale="fr"31 data-shadow-mode="open"32 />33 </IonContent>34 </IonPage>35 )36}3738export default ProductPage5. Ionic Vue
1<template>2 <ion-page>3 <ion-content>4 <h1>My product</h1>5 <ekoo-widget6 data-ekoo="YOUR_WEBSITE_ID"7 :data-ekoo-product-id="productId"8 data-ekoo-locale="fr"9 data-shadow-mode="open"10 />11 </ion-content>12 </ion-page>13</template>1415<script setup lang="ts">16import { IonPage, IonContent, onIonViewDidEnter, onIonViewWillLeave } from '@ionic/vue'1718defineProps<{19 productId: string20}>()2122onIonViewDidEnter(() => {23 window.ekooLoad?.()24})2526onIonViewWillLeave(() => {27 window.ekooUnload?.()28})29</script>Vue: declare the custom element
To avoid Vue warnings about the custom element, add ekoo-widget to the compilerOptions.isCustomElement configuration in your vite.config.ts.
6. Ionic Angular
For Angular, you must add CUSTOM_ELEMENTS_SCHEMA to the module or component that uses the custom element:
1import { Component } from '@angular/core'2import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'3import { ViewDidEnter, ViewWillLeave } from '@ionic/angular'45@Component({6 selector: 'app-product',7 schemas: [CUSTOM_ELEMENTS_SCHEMA],8 template: `9 <ion-content>10 <h1>My product</h1>11 <ekoo-widget12 data-ekoo="YOUR_WEBSITE_ID"13 [attr.data-ekoo-product-id]="productId"14 data-ekoo-locale="fr"15 data-shadow-mode="open"16 ></ekoo-widget>17 </ion-content>18 `,19})20export class ProductPage implements ViewDidEnter, ViewWillLeave {21 productId = 'my-product-123'2223 ionViewDidEnter() {24 (window as any).ekooLoad?.()25 }2627 ionViewWillLeave() {28 (window as any).ekooUnload?.()29 }30}CUSTOM_ELEMENTS_SCHEMA
Without CUSTOM_ELEMENTS_SCHEMA, Angular will throw an error because it does not recognize <ekoo-widget> as a native Angular component.
Lifecycle Summary
- View enters (visible) →
ekooLoad() - View leaves (hidden) →
ekooUnload() - Product ID changes → update the attribute with
setAttribute - Visual inconsistency →
ekooReload()