Skip to main content
RichRelevance

Add to Cart Page

The add to cart page is typically any page displayed immediately after a customer adds a product to their shopping cart. It is a distinct page separate from the cart, typically offering other products, options, or information relevant to the product just added to the cart. It may be a modal window or an interstitial page before cart, such as an options page.

How To Make This Code Work For You

Follow the sample integration code below, making these changes:

Function Requirement
R3_COMMON.setApiKey('API Key'); Replace API Key with your site’s API key, a unique identifier for your account.
R3_COMMON.setBaseUrl(window.location.protocol+'//RR Server URL.richrelevance.com/rrserver/'); Set RR Server URL to one of the following values:

For initial development:
integration
For production:
recs
R3_COMMON.setSessionId('User Session ID'); Replace User Session ID with the session ID for the current user and session. The session ID is a crucial variable that allows RichRelevance to track shopper behavior when they visit your site so recommendations can be generated. This parameter should remain the same from start to finish for a user’s shopping session.
R3_COMMON.setUserId('User ID'); Replace User ID with the user ID, a unique string to identify each user. All user behavior will be stored using this key. It is case-sensitive and should be the same UserId sent to RichRelevance in other applications. User IDs are often connected to email addresses, and can be directly linked to the login credentials a consumer uses to log into and buy products from the e-commerce site. To avoid sending personally identifiable information to RichRelevance, you can use a hash of your site’s user ID (if, for example, your site uses email addresses as user IDs, then you should not send that information directly to RichRelevance).

Note: If the User ID is unknown, leave it blank.
R3_ADDTOCART.addItemIdToCart('Item ID','SKU'); Replace Item ID with the item ID, a unique identifier for the item.
Replace SKU with the specific SKU the user has purchased. If there is no SKU ID, this can be left empty.​
R3_COMMON.addPlacementType('brand_page.Placement Name'); Replace Placement Name with the Placement ID. You can find your Placement IDs in the Dashboard under the Placements section. If you do not display personalization on this page, call R3_COMMON.addPlacementType('brand_page');instead.
 R3_COMMON.setClickthruServer(window.location.protocol+'//'+window.location.host)

No changes are required.

This code enables the client to send the domain for click-through URL through the p13n_generated.js call if relative URLs are supplied in the feed. For example, if the domain calling our code is m.retailer.com or UAT.retailer.com, we can automatically redirect to the correct domain.

Sample Integration Code

RichRelevance JavaScript Library

<!-- Primary function library placed before the callback and Primary Code Block. -->
<script src="//media.richrelevance.com/rrserver/js/1.2/p13n.js"></script>

Callback Function

This function will consume the JSON response object. Place anywhere in between your <script> tag that loads p13n.js and the r3() function call.

<script charset="utf-8" type="text/javascript">
  RR.jsonCallback = function(){
    // Place your rendering logic here. Actual code varies depending on your website implementation.
    console.dir(RR.data.JSON.placements);
  };
</script>

Primary Code Block

<!-- Place this code inside the <body> element as close to the top as possible -->
<script charset="utf-8" type="text/javascript">
  var R3_COMMON = new r3_common();
  R3_COMMON.setApiKey('abcd5432e1');
  R3_COMMON.setBaseUrl(window.location.protocol+'//integration.richrelevance.com/rrserver/');
  R3_COMMON.setClickthruServer(window.location.protocol+"//"+window.location.host);
  R3_COMMON.setSessionId('6B4D397B');
  R3_COMMON.setUserId('10987');  // if no user ID is available, please leave this blank
 
  // Use this code if you are not requesting placement(s) for personalization
  R3_COMMON.addPlacementType('add_to_cart_page');

  // Use this code if you are not requesting placement(s) for personalization
  // Replace placement_name with the placement name you set up in Dashboard.
  // Call multiple times to display more than one placement.
  R3_COMMON.addPlacementType('add_to_cart_page.placement_name');

  var R3_ADDTOCART = new r3_addtocart();
  R3_ADDTOCART.addItemIdToCart('ACW239845','0WD37534000');
 
  rr_flush_onload();
 
  r3(); 
</script>

Integration with FindTM

Find requires additional parameters on the add to cart request. If there is already an add to cart integration on product detail page, then store the add to cart parameters returned by the search request, on local storage under a key like 'rr-find-atcparams' on the search results page. 

Add the code similar to following before making r3() call to launch add to cart event.

if(localStorage) {
    var productId = '';
    //example parameter : query=blue&lang=pt&page=1&searchConfigId=1234ABC
    var findA2CParameters = localStorage.getItem('rr-find-atcparams');
    var params = JSON.parse('{"' + decodeURI(findA2CParameters.replace(/&/g, "\",\"").replace(/=/g,"\":\"")) + '"}');
   
    if(params.query && params.lang &&params.page && params.searchConfigId) {
        R3_COMMON.addContext({
          "st": params.query,
          "lang": params.lang,
          "page": params.page,
          "searchConfigId": params.searchConfigId
        });
    }

    localStorage.removeItem('rr-find-atcparams');
}

Please note that, the above is not a working code. It's a pseudo code to exemplify the logic. 

Notes

  • Placements requested via addPlacementType() should always be displayed on the page.