Ionic / Capacitor Integration
Use the <ekoo-widget> custom element in your Ionic applications (React, Vue, Angular)
SEO & GEO
Server rendering applies to web pages indexed by search engines, not to a mobile app. For your website, follow the SSR, SEO & GEO guide.
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"Overview
In an Ionic / Capacitor app, use the <ekoo-widget> custom element. The script is loaded once in index.html. The element initializes when the page inserts it, reloads the product when data-ekoo-product-id changes and is destroyed when the page is removed: no Ionic hook is needed.
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" defer></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.
3. Dynamic product reference
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}4. Ionic React
1import React from 'react'2import { IonContent, IonPage } from '@ionic/react'34interface ProductPageProps {5 productId: string6}78const ProductPage: React.FC<ProductPageProps> = ({ productId }) => {9 return (10 <IonPage>11 <IonContent>12 <h1>My product</h1>13 {/* @ts-expect-error — custom element not typed by default */}14 <ekoo-widget15 data-ekoo="YOUR_WEBSITE_ID"16 data-ekoo-product-id={productId}17 data-ekoo-locale="fr"18 data-shadow-mode="open"19 />20 </IonContent>21 </IonPage>22 )23}2425export 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 } from '@ionic/vue'1718defineProps<{19 productId: string20}>()21</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, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'23@Component({4 selector: 'app-product',5 schemas: [CUSTOM_ELEMENTS_SCHEMA],6 template: `7 <ion-content>8 <h1>My product</h1>9 <ekoo-widget10 data-ekoo="YOUR_WEBSITE_ID"11 [attr.data-ekoo-product-id]="productId"12 data-ekoo-locale="fr"13 data-shadow-mode="open"14 ></ekoo-widget>15 </ion-content>16 `,17})18export class ProductPage {19 productId = 'my-product-123'20}CUSTOM_ELEMENTS_SCHEMA
Without CUSTOM_ELEMENTS_SCHEMA, Angular will throw an error because it does not recognize <ekoo-widget> as a native Angular component.