Step 3: Registering Recommendation

Prev Next

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 define the widget element and the product-specific data you want to send.

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

Loaded events are triggered automatically as soon as elements matching the selector appear in the DOM. This also works for lazy-loaded content and SPA environments, as no separate event is required. 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/element reference for the recommendation widget

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 (total for quantity)

data.currency

No

ISO currency code, e.g., EUR

data.placement

Yes

Widget placement (e.g., PDP, homepage)

data.algorithm

Yes

Algorithm (e.g., similar items, trending)

data.occasion

Yes (for outfits)

Product occasion (e.g., casual)

data.position

Yes

Product position in widget (e.g., 3)

Note

The extension listens for click events on all clickable elements inside the widget (a, area, button, input[type="submit"]).

Warning

You must call add() for each widget you want to track.

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:

  1. Open the page with a recommendation widget and start the Debugger.

  2. Trigger the events (widget load, product in view, click, and later a purchase).

  3. 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 loaded-reco, or display-reco on Smart Pixel versions before 6.12.1, and the configured product fields (id, cost, placement, algorithm, position). The widget context parameters 765 (placement), 766 (product position) and 767 (algorithm) appear in the request.

Widget product viewable

Scroll the product fully into view and leave it on screen for more than a second.

A product with status viewable-reco, or view-reco on Smart Pixel versions before 6.12.1, plus the same product fields and the widget context parameters 765 / 766 / 767. Scrolling the same product out of view and back does not produce a second event.

Widget product clicked

Click a product inside the recommendation widget.

A product with status click-reco plus the same product fields and the widget context parameters 765 / 766 / 767. This confirms that recommendation click tracking works.

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., conf), not a recommendation-specific status, together with the widget context parameters 765 / 766 / 767. These parameters show that the purchase is linked to a prior recommendation click and enables attribution.