Skip to content

Event API

The Koral widget communicates through browser custom events dispatched on document.body. You can both fire events to trigger widget functionality and listen for events to react to user activity.

Use these events to control the widget programmatically.

Opens the image search modal.

document.body.dispatchEvent(new CustomEvent('koral_open'));

Triggers a similar product search and opens the widget.

document.body.dispatchEvent(new CustomEvent('koral_similar', {
detail: {
productId: 'SKU-12345', // Required
imageUrl: 'https://...', // Required
filters: [{ key: 'brand', value: 'Nike' }], // Optional
type: 'similar', // Optional
context: {} // Optional
}
}));

Triggers a similar product search with automatic size filtering.

document.body.dispatchEvent(new CustomEvent('koral_similar_by_size', {
detail: {
productId: 'SKU-12345', // Required
size: 'M', // Required
imageUrl: 'https://...' // Optional
}
}));

In addition to custom events, the widget exposes a JavaScript API on the window object.

window.KoralModal.open() // Opens the modal
window.KoralModal.close() // Closes the modal
window.KoralModal.isOpen() // Returns boolean
window.koralSimilarSearch({
productId: 'SKU-12345',
imageUrl: 'https://...',
filters: [], // Optional
type: '', // Optional
context: {} // Optional
});

Listen for these events on document.body to react to widget activity.

document.body.addEventListener('koral_product_click', (event) => {
console.log('Product clicked:', event.detail.productId);
});
EventFired when
koral_closeModal is closed
koral_product_clickUser clicks a product (detail.productId)
koral_product_impressionProduct becomes visible in viewport (detail.productId)
koral_similar_searchSimilar search is performed
koral_image_uploadUser uploads an image
koral_image_upload_searchSearch is executed with uploaded image
koral_image_inspirationUser views inspiration gallery
koral_image_inspiration_categoryUser selects an inspiration category
koral_carousel_slideRelated products carousel is navigated

All events are dispatched on document.body.