After activating the Recommendation Tracking extension, you must register the elements on your website that you want to track as recommendations. This is required for all integration methods.
When a recommended product is loaded into a widget, becomes viewable on screen, or is clicked, the extension sends product details along with widget context (placement, algorithm, product position). The three product statuses and what triggers them are described in Recommendation Tracking.
If the clicked product is purchased within seven days, the stored widget context is included in the purchase request. Attribution follows a last-click approach.
Register recommendation
Use add() to register a recommended product element and the data you want to send for it. Call add() once for every product element.
wtSmart.extension.recommendation_tracking.add({
selector: "li.item:nth-of-type(2)",
shadowRoot: "#product-collection",
exclude: ["li.item:nth-of-type(2) a:last-child"],
data: {
id: "MP12",
cost: 19.95,
currency: "EUR",
placement: "pdp",
algorithm: "similar items",
occasion: "casual",
position: 3
}
});Note
The extension evaluates the selector once, about one second after
add()is called. The product elements must already exist in the DOM at that time. Calladd()after your widget has rendered, and call it again whenever new product elements are added later, for example after a carousel loads more items, after a route change in a single-page application, or after the widget re-renders. Elements that are already registered are skipped, so a repeated call does not change their data. The loaded event is sent when an element is registered. Viewable and clicked events follow from the visitor scrolling the product into view and clicking it, and need no further registration.
Fields
Field | Required | Description |
|---|---|---|
selector | Yes | CSS selector or DOM element of the recommended product. If the selector matches several elements, all of them receive the same |
shadowRoot | No | Selector for a Shadow DOM root if applicable |
exclude | No | Elements to exclude from click tracking |
data.id | Yes | Product identifier (same value as used for product tracking) |
data.cost | Yes | Product price. The extension always sends a quantity of 1. |
data.currency | No | ISO currency code, e.g., |
data.placement | Yes | Widget placement (e.g., |
data.algorithm | Yes | Algorithm (e.g., |
data.occasion | No | Occasion of an outfit recommendation (for example |
data.position | Yes | Product position in widget (e.g., |
data.productId | No | ID of the parent product (same value as used for fashionProductId in product tracking) |
Note
The extension listens for click events on all clickable elements inside the widget (
a,area,button,input[type="submit"]).
Warning
Call
add()for every product element you want to track. A selector that matches several elements gives all of them the sameidandposition, so use one call per product.
Example
// register multiple products inside the same widget
document.querySelectorAll(".recos li.item").forEach((el, index) => {
wtSmart.extension.recommendation_tracking.add({
selector: el,
data: {
id: el.dataset.sku,
cost: el.dataset.price,
currency: "EUR",
placement: "homepage",
algorithm: "similar items",
occasion: "casual",
position: index + 1
}
});
});Testing your implementation
To verify that recommendation events are firing correctly, use your browser's developer tools or the Mapp Cloud debugger:
Open the page with a recommendation widget and start the Debugger.
Trigger the events (widget load, product in view, click, and later a purchase).
Check the outgoing requests and verify that the following values are sent:
Event | How to trigger | What you should see in the Mapp Cloud Debugger |
|---|---|---|
Widget product loaded | Load the page with the recommendation widget. The widget does not have to be scrolled into view. | A product with status |
Widget product viewable | Scroll the product fully into view and leave it on screen for more than a second. | A product with status |
Widget product clicked | Click a product inside the recommendation widget. | A product with status |
Purchase after a recommendation click | Complete a test purchase for a product that was previously clicked in a recommendation widget (within seven days). | A normal purchase status (e.g., |