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.
Listen to an Event
Section titled “Listen to an Event”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.
Shared Properties
Section titled “Shared Properties”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 itwidgetId: the widget’s ID, present only when one is setwidgetVersion: thevviinn-widgetsversion 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.
Lifecycle
Section titled “Lifecycle”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-buttonvviinn-vpr-widgetvviinn-vps-buttonvviinn-vps-widget |
Shared |
vviinnWidgetOpen |
The shopper selects the widget’s button, right after the modal opens. | vviinn-vpr-buttonvviinn-vps-buttonvviinn-vps-widget |
Shared |
vviinnWidgetClose |
The shopper closes the widget. | vviinn-vpr-buttonvviinn-vps-buttonvviinn-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"}Search Input
Section titled “Search Input”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 |
queryisTriggeredByVpsWidget |
vviinnImageUploadFinished |
The search ID of an image search arrives. vviinn-results uses it to show the results. |
vviinn-text-search |
searchIdisTriggeredByVpsWidget |
document.addEventListener("vviinnTextSearchStarted", ({ detail }) => { console.log(detail);});
// Output:{ "query": "kitchen", "isTriggeredByVpsWidget": false}Image and Cropper
Section titled “Image and Cropper”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-buttonvviinn-vps-widget |
SharedisTriggeredByVpsWidget |
vviinnImageCrop |
The search area changes: the shopper crops the image, selects a detected object or removes the crop. | vviinn-croppervviinn-vps-buttonvviinn-vps-widget |
SharedisTriggeredByVpsWidget |
vviinnSelectObject |
The shopper selects a detected object. | vviinn-vps-buttonvviinn-vps-widget |
ShareddetectedObjectsearchArea |
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 pixelssearchArea: search area in pixelsnormalizedSearchArea: search area from 0 to 1, as the Visual Search API takes itrequestId: 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}Filters
Section titled “Filters”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-filtersvviinn-extended-filtersvviinn-selected-filtersvviinn-suggestionsvviinn-vpr-widget |
filters: the selected values per column, as a list of values or of ranges with start and endel: the element that sent the changeisTriggeredByVpsWidget |
vviinnFilterTriggered |
The shopper selects, deselects or resets a filter, and tracking is permitted. | vviinn-filtersvviinn-extended-filtersvviinn-selected-filtersvviinn-suggestionsvviinn-text-search |
action: "select", "deselect" or "reset"kind: the filter kindisTriggeredByVpsWidget |
document.addEventListener("vviinnFiltersChanged", ({ detail }) => { console.log(detail.filters);});
// Output:[ { "column": "color", "values": ["beige > #c7b3a8"] }]Products and Results
Section titled “Products and Results”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-cardvviinn-resultsvviinn-vpr-buttonvviinn-vpr-widgetvviinn-vps-button |
SharedproductIdproductNameproductTypeproductRank |
vviinnProductView |
At least 95% of a product card’s image is in the viewport, once for each product in a session. | Same as vviinnProductLoad |
SharedproductIdproductNameproductTypeproductRank |
vviinnProductClick |
The shopper selects a product’s link. | Same as vviinnProductLoad |
SharedproductIdproductNameproductTypeproductRankclickEvent |
vviinnAddToBasket |
The shopper selects Add to Basket. The button shows when add-to-basket-show is true. |
vviinn-product-cardvviinn-vpr-buttonvviinn-vpr-widget |
SharedproductIdproductNameproductTypeproductRank |
vviinnAddToFavorite |
The shopper selects the favorite button. The button shows when favorite-show is true. |
vviinn-product-card |
SharedproductIdproductNameproductTypeproductRank |
vviinnResultLoad |
At least one result has loaded. | vviinn-resultsvviinn-vpr-buttonvviinn-vpr-widgetvviinn-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"}Responses and Redirects
Section titled “Responses and Redirects”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-buttonvviinn-text-searchvviinn-resultsvviinn-cropper |
Sharedresults: the productsdynamicFilters: the filters available for the resultsdetectedObjects: detected objects, Visual Search onlyrequestId: the request’s IDquery: the query, Text Search onlystoreName: "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-searchvviinn-vps-buttonvviinn-vps-widget |
Sharedurl: the redirect URLsource: "text-search", "visual-search" or "auto-suggest"query: the query, for text-search and auto-suggestsearchId: 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-buttonvviinn-vpr-widgetvviinn-vps-buttonvviinn-vps-widgetvviinn-text-searchvviinn-resultsvviinn-cropper |
Shared For image upload errors: reason: the error type, such as "invalid_file_type"errorCode: the error codeerrorMessage: 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"}Related
Section titled “Related”Where the events come into play:
- Redirect Search to a Results Page:
vviinnRedirectand the manual redirect with the Search Input events - Build a Search Page: the components these events connect