Skip to main content
RichRelevance

Integration: Multiple Requests

In some situations you may wish to request for recommendations more than once, or subsequent to the context of the initial request at a time after page load. A common example of this use case is to display recommendations on an interstitial “add to cart” overlay when items are added to the cart from an item page or quick view.

The Relevance Cloud supports the display of additional recommendations triggered by user action, however additional steps not described in the standard integration guide are required. Please note that some functionality, such as product de-duping (insuring that the same product does not appear within different recommendation placements), will not necessarily be supported with this type of request.

Clearing the Old Context

On initial page load, the personalization context is set. This includes things such as your site API key, session ID, and page type. While the API key and session ID will be consistent between requests, other values, such as the page type, may not be consistent.

In our example, stated above, of an item page displaying additional recommendations when a user adds an item to the cart, we would need to update the page type from "ITEM" to "ADDTOCART", for example. Then we would need to populate the new objects with the appropriate values, and finally we would send the new request.

The first step is to clear all existing data that we do not want re-sent. Many clients find it easiest to clear all data so that the new request may be composed on a blank slate. How you do it is up to you. In the example below, we clear the R3_ITEM object so that it does not get sent a second time, then we delete the placement calls we made previously, and since this was an item page, we delete the category hint ID that is no longer applicable to our new call, which is for the add to cart page type.

if(typeof R3_ITEM !=='undefined') R3_ITEM = undefined;
R3_COMMON.placementTypes='';
//if used on the item page previously
R3_COMMON.categoryHintIds='';

Setting the New Context

The new context will need to be set for the second request for personalized content. This will include the placement type, the page context, and the item added to cart.

R3_COMMON.addPlacementType("add_to_cart_page.placement name");
var R3_ADDTOCART = new r3_addtocart();
R3_ADDTOCART.addItemIdToCart('item id');

Send Request

Finally, you need to trigger the request. This will send the request for personalized content that you have instantiated and populated.

r3();
  • Was this article helpful?