Skip to content
Panel(opens in a new tab)

Events

The vviinn widgets and components emit DOM events that you can listen to for analytics, for your own UI, or to connect your code to a search. Each table below lists the events of one area: what triggers each, which elements emit it, and the props in its detail.

The events bubble out of the widgets, so one listener on document receives them from every widget on the page:

document.addEventListener("vviinnProductClick", ({ detail }) => {
console.log(detail.productId, detail.campaignTypeId);
});

The Emitted By column names element tags. The widget catalog maps each tag to its widget or component.

Most events carry these props in detail. In the tables, Shared in the Props column means the event carries all four, plus any props listed after it:

  • campaignTypeId: the campaign type the request used (see the table below)
  • campaignTypeName: the campaign type’s name, as the widgets send it
  • widgetId: the widget’s ID, present only when one is set
  • widgetVersion: the vviinn-widgets version that sent the event
campaignTypeId Feature campaignTypeName
TPS Text Search Text Product Search
VPS Visual Search Visual Search
VPR Similar Products Similar Products
VCS Cross-Selling Cross-Selling

Several events also carry isTriggeredByVpsWidget: true when the event comes from the Search Modal Window (vviinn-vps-widget), false when it comes from the component on your page.

Events for loading, opening and closing a widget.

Event Triggered When Emitted By Props
vviinnWidgetLoad The widget has loaded and initialized. One-Click Discovery sends it in the background when its button renders. The Search Modal sends it only after the shopper opens the modal. vviinn-vpr-button
vviinn-vpr-widget
vviinn-vps-button
vviinn-vps-widget
Shared
vviinnWidgetOpen The shopper selects the widget’s button, right after the modal opens. vviinn-vpr-button
vviinn-vps-button
vviinn-vps-widget
Shared
vviinnWidgetClose The shopper closes the widget. vviinn-vpr-button
vviinn-vps-button
vviinn-vps-widget
Shared
vviinnVprButtonActivated The One-Click Discovery button is activated. vviinn-vpr-button None
vviinnShopTheLookModalClose The shopper closes the Shop-the-Look recommendation modal. vviinn-shop-the-look Shared
document.addEventListener("vviinnWidgetLoad", ({ detail }) => {
console.log(detail);
});
// Output: Search Modal
{
"campaignTypeId": "VPS",
"campaignTypeName": "Visual Search",
"widgetId": "my-search-widget",
"widgetVersion": "2.85.0"
}
// Output: One-Click Discovery
{
"campaignTypeId": "VPR",
"campaignTypeName": "Similar Products",
"widgetVersion": "2.87.0"
}

Events of the Search Bar. They connect vviinn-text-search to vviinn-results on the same page, and you can use them to redirect a search yourself. They carry only the props listed.

Event Triggered When Emitted By Props
vviinnTextSearchStarted The shopper starts a text search. Not sent while results-page-url is set and the shopper is away from the results page, or when a Query-to-URL Mapping matches the query. vviinnRedirect is sent instead in both cases. vviinn-text-search query
isTriggeredByVpsWidget
vviinnImageUploadFinished The search ID of an image search arrives. vviinn-results uses it to show the results. vviinn-text-search searchId
isTriggeredByVpsWidget
document.addEventListener("vviinnTextSearchStarted", ({ detail }) => {
console.log(detail);
});
// Output:
{
"query": "kitchen",
"isTriggeredByVpsWidget": false
}

Events of an image search: the upload, the search area and detected objects, in the Search Modal and in the Cropper.

Event Triggered When Emitted By Props
vviinnImageUploadStarted The shopper selects the image upload button. vviinn-vps-button
vviinn-vps-widget
Shared
isTriggeredByVpsWidget
vviinnImageCrop The search area changes: the shopper crops the image, selects a detected object or removes the crop. vviinn-cropper
vviinn-vps-button
vviinn-vps-widget
Shared
isTriggeredByVpsWidget
vviinnSelectObject The shopper selects a detected object. vviinn-vps-button
vviinn-vps-widget
Shared
detectedObject
searchArea
vviinnCropperLoadImage The image loads in the Cropper. vviinn-cropper imageBounds: image dimensions in pixels
vviinnCropperCropEnd The shopper finishes cropping. Carries the search area ready for the Visual Search API. vviinn-cropper imageBounds: image dimensions in pixels
searchArea: search area in pixels
normalizedSearchArea: search area from 0 to 1, as the Visual Search API takes it
requestId: the search’s request ID, present only during a search session

The Cropper events connect vviinn-cropper to vviinn-results. By default, the Cropper starts a new Visual Search when the shopper finishes cropping. To call the API yourself, set auto-search="false" on vviinn-cropper. vviinnCropperCropEnd still fires, and its normalizedSearchArea goes into the request as it is.

document.addEventListener("vviinnCropperCropEnd", ({ detail }) => {
console.log(detail);
// Visual Search API request: query: { searchArea: detail.normalizedSearchArea }
});
// Output:
{
"searchArea": { "left": 100, "top": 50, "width": 200, "height": 150 },
"normalizedSearchArea": { "left": 0.125, "top": 0.083, "width": 0.25, "height": 0.25 },
"imageBounds": { "left": 0, "top": 0, "width": 800, "height": 600 },
"requestId": "abc-123-def" // only during a search session
}
document.addEventListener("vviinnImageUploadStarted", ({ detail }) => {
console.log(detail);
});
// Output: Search Modal
{
"campaignTypeId": "VPS",
"campaignTypeName": "Visual Search",
"widgetId": "my-search-widget",
"widgetVersion": "2.87.0",
"isTriggeredByVpsWidget": true
}

Events of the filters components. The components use them to keep each other and the results in sync, and you can listen to them too. They carry only the props listed.

Event Triggered When Emitted By Props
vviinnFiltersChanged The selected filters change. vviinn-filters
vviinn-extended-filters
vviinn-selected-filters
vviinn-suggestions
vviinn-vpr-widget
filters: the selected values per column, as a list of values or of ranges with start and end
el: the element that sent the change
isTriggeredByVpsWidget
vviinnFilterTriggered The shopper selects, deselects or resets a filter, and tracking is permitted. vviinn-filters
vviinn-extended-filters
vviinn-selected-filters
vviinn-suggestions
vviinn-text-search
action: "select", "deselect" or "reset"
kind: the filter kind
isTriggeredByVpsWidget
document.addEventListener("vviinnFiltersChanged", ({ detail }) => {
console.log(detail.filters);
});
// Output:
[
{
"column": "color",
"values": ["beige > #c7b3a8"]
}
]

Events for the products a widget shows and what shoppers do with them.

Event Triggered When Emitted By Props
vviinnProductLoad A product’s card renders after a successful request, once for each product. vviinn-product-card
vviinn-results
vviinn-vpr-button
vviinn-vpr-widget
vviinn-vps-button
Shared
productId
productName
productType
productRank
vviinnProductView At least 95% of a product card’s image is in the viewport, once for each product in a session. Same as vviinnProductLoad Shared
productId
productName
productType
productRank
vviinnProductClick The shopper selects a product’s link. Same as vviinnProductLoad Shared
productId
productName
productType
productRank
clickEvent
vviinnAddToBasket The shopper selects Add to Basket. The button shows when add-to-basket-show is true. vviinn-product-card
vviinn-vpr-button
vviinn-vpr-widget
Shared
productId
productName
productType
productRank
vviinnAddToFavorite The shopper selects the favorite button. The button shows when favorite-show is true. vviinn-product-card Shared
productId
productName
productType
productRank
vviinnResultLoad At least one result has loaded. vviinn-results
vviinn-vpr-button
vviinn-vpr-widget
vviinn-vps-button
Shared
vviinnResultView The results appear in the viewport, once for each request. In Visual Search it fires again when the shopper changes a filter, changes the search area or selects a detected object. Same as vviinnResultLoad Shared
vviinnShopTheLookDetectedObjectClick The shopper selects a hotspot (detected object) in Shop-the-Look. Carries the object’s ID and the first recommended product. vviinn-shop-the-look See the description
vviinnShopTheLookProductClick The shopper selects a product in the Shop-the-Look recommendation modal. Carries the product and the detected object’s ID. vviinn-shop-the-look See the description
document.addEventListener("vviinnProductLoad", ({ detail }) => {
console.log(detail);
});
// Output: one event for each loaded product
{
"productId": "123456",
"productRank": 0,
"productName": "Sessel Loft",
"productType": "Chair",
"campaignTypeId": "VPR",
"campaignTypeName": "Similar Products",
"widgetId": "my-recommendation-widget",
"widgetVersion": "2.1.0"
}

Events sent when a request to vviinn returns: results, a redirect, or an error.

Event Triggered When Emitted By Props
vviinnSearchSuccess A Visual Search, Text Search or product listing page request returns results. Use it to build your own results UI. vviinn-vps-button
vviinn-text-search
vviinn-results
vviinn-cropper
Shared
results: the products
dynamicFilters: the filters available for the results
detectedObjects: detected objects, Visual Search only
requestId: the request’s ID
query: the query, Text Search only
storeName: "widget" or "components"
vviinnRedirect A redirect is about to happen: results-page-url is set and the shopper searches away from the results page, or the API returns a URL for the search (a Query-to-URL Mapping for a query, or a suggested URL for an image). The widget redirects unless you call event.preventDefault(). vviinn-text-search
vviinn-vps-button
vviinn-vps-widget
Shared
url: the redirect URL
source: "text-search", "visual-search" or "auto-suggest"
query: the query, for text-search and auto-suggest
searchId: the image search’s ID, for visual-search
vviinnNoResult A request fails: a Similar Products or Cross-Selling request, a Visual Search request (upload, crop, rotation, object selection), a Text Search request or a product listing page request. Also sent when an uploaded image has a format the browser can’t read. vviinn-vpr-button
vviinn-vpr-widget
vviinn-vps-button
vviinn-vps-widget
vviinn-text-search
vviinn-results
vviinn-cropper
Shared
For image upload errors:
reason: the error type, such as "invalid_file_type"
errorCode: the error code
errorMessage: a readable message, validation errors only

An auto-suggest redirect points wherever the Query-to-URL Mapping was set up, so let the widget follow it. Route Redirects in a Single-Page App shows how to intercept only the results-page redirects.

document.addEventListener("vviinnRedirect", ({ detail }) => {
console.log(detail);
});
// Output: auto-suggest
{
"url": "https://www.my-site.de/sansibar",
"source": "auto-suggest",
"query": "sansibar",
"campaignTypeId": "TPS",
"campaignTypeName": "Text Product Search",
"widgetId": "my-search-widget",
"widgetVersion": "2.205.0"
}
// Output: text search with results-page-url
{
"url": "https://www.my-site.de/results?query=shoes",
"source": "text-search",
"query": "shoes",
"campaignTypeId": "TPS",
"campaignTypeName": "Text Product Search",
"widgetVersion": "2.205.0"
}
// Output: image search with results-page-url
{
"url": "https://www.my-site.de/results?searchId=abc-123",
"source": "visual-search",
"searchId": "abc-123",
"campaignTypeId": "VPS",
"campaignTypeName": "Visual Search",
"widgetVersion": "2.205.0"
}
document.addEventListener("vviinnSearchSuccess", ({ detail }) => {
console.log(detail);
});
// Output: Visual Search
{
"results": [
{
"productId": "12345",
"title": "Product Name",
"price": { "actual": { "amount": 29.99 } },
"image": { "url": "https://..." }
// … more product fields
}
// … more products
],
"dynamicFilters": [
{
"kind": "color",
"values": [
{ "value": "red", "count": 15 },
{ "value": "blue", "count": 8 }
]
}
],
"detectedObjects": [
{ "left": 0.1, "top": 0.2, "width": 0.3, "height": 0.4 }
],
"requestId": "abc123-def456",
"storeName": "widget",
"campaignTypeId": "VPS",
"campaignTypeName": "Visual Search",
"widgetVersion": "2.208.0"
}
document.addEventListener("vviinnNoResult", ({ detail }) => {
console.log(detail);
// Show a message to the shopper, retry, and so on
});
// Output:
{
"campaignTypeId": "TPS",
"campaignTypeName": "Text Product Search",
"widgetId": "my-search-widget",
"widgetVersion": "2.208.0"
}

Where the events come into play: