Events and Display Rules
Which event a widget sends and when, and the rules that decide whether it is shown.
This page defines the event protocol of the recommendation widget and the rules that decide whether it is shown at all.
Display Rules
Section titled “Display Rules”The rules are checked in this order. When one fails, the widget draws nothing and sends no event.
| # | Rule | On failure |
|---|---|---|
| 1 | schemaVersion is known |
reportError('UNSUPPORTED_SCHEMA') |
| 2 | If the config has an extensionId, the extension is registered and runs without a fault |
reportError('EXTENSION_NOT_FOUND') or reportError('EXTENSION_FAILED') |
| 3 | If rules.devices exists, the current device is in it |
Nothing |
| 4 | There are at least rules.minProducts[device] products (1 when not set), counted after the extension’s product filter |
Nothing |
| 5 | The extension’s shouldRender, if it has one, answers true |
Nothing |
| 6 | Web: placement.selector matches an element; looked up 50 times, 100 ms apart |
reportError('DIV_SELECTOR_NOT_FOUND') |
Rules 3 to 5 are silent on purpose: a widget that is not meant for this device or page is not an error.
In data only delivery a failing rule from 2 on gives the site an empty delivery; see below.
Events
Section titled “Events”| When | Call | How often |
|---|---|---|
| The placement target is found and the widget is added to the page | impression, with interactionId = actionId |
Once per render; never before the target is found |
| The widget becomes visible | widget-view, with interactionId = interactionId |
Once |
| A product card is tapped | click, with interactionId = the product id |
Every tap, before navigation |
| The previous or next arrow is tapped | slider:arrow:left or slider:arrow:right, with the same value as interactionId |
Every tap that the arrow accepts; an arrow at its edge refuses the tap |
| A pagination dot is tapped | Nothing; by decision | |
| The see all link is tapped | Nothing | |
| The add-to-basket button is tapped | click, then addToBasket with quantity: 1 |
Every tap; the page does not navigate |
Every event carries the campaign’s instanceId.
In Data Only Delivery
Section titled “In Data Only Delivery”The widget draws nothing, so the site reports what the visitor does through the delivered handle.
| When | Call | How often |
|---|---|---|
| There is something to show | impression, then deliverData |
Once |
| A display rule fails, or there are no products | deliverData with an empty product list; no impression |
Once |
The element given to observeView(root) becomes visible |
widget-view |
Once |
The site calls reportClick(productId) |
click |
Every call for a delivered product |
The site calls addToBasket(productId, quantity) |
click, then addToBasket |
Every call for a delivered product |
The impression is sent before the delivery, as in the callback delivery of the web SDK. As there, the site is also told when there is nothing to show, so it can hide the place it kept for the widget; an empty delivery sends no event afterwards either. No placement target is looked for in this mode, because the site decides where it draws.
The Placement Target
Section titled “The Placement Target”A page may add the target after the campaign arrives. The widget looks for it 50 times, 100 ms apart, as the web SDK does. If it never appears, the widget reports DIV_SELECTOR_NOT_FOUND once and sends no impression. The runtime turns that report into the event:alert custom event.
Impression and Widget View Are Different
Section titled “Impression and Widget View Are Different”An impression means the widget was delivered to the page. A widget view means the visitor could actually see it. A widget far down a long page has an impression and may never have a widget view.
Visibility is the runtime’s knowledge, not the widget’s: the widget asks observeVisibility() and sends widget-view the first time it is called back.
Add to Basket
Section titled “Add to Basket”- The button is drawn only when
card.addToBasketistrueandruntime.capabilities.addToBasketistrue. - A tap sends
clickand then callsruntime.addToBasket(). - The button is disabled until the answer arrives, so a second tap cannot add the product twice.
- On
'failed', or when the call throws, the widget reportsBASKET_FAILEDand enables the button again.
The card link and the button are separate elements next to each other. A tap on the button is therefore not a tap on the card, and the page does not navigate.
Adding to the site’s own basket is different on every site. That part lives in a per-account adapter behind the runtime, not in the widget.
Favourites
Section titled “Favourites”- The button is drawn only when
card.addToFavoritesistrueandruntime.capabilities.favoritesistrue. - A tap calls
runtime.toggleFavorite(). The runtime sends the Segmentify favourite event, as it sends the basket event for add to basket:favorite:addwhen the product was added andfavorite:removewhen it was removed, with the product id. These are the web SDK’s existing events. The widget itself sends noclickfor a favourite tap. 'added'shows the product as a favourite,'removed'as not a favourite.- On
'failed', or when the call throws, the widget reportsFAVORITE_FAILEDand keeps the previous state.
Every product starts as not a favourite. The state is not kept: after a page reload the button is not selected again. No source for an initial state is defined.
Next Steps
Section titled “Next Steps”- Conformance Scenarios shows how each rule on this page is tested.
- Runtime Interface lists the calls used here.