Skip to main content
RichRelevance

User Attributes

Providing additional context about the user, session, or request allows for the use of additional strategies and merchandising rules.

JavaScript Integration

How To Make This Code Work For You

  1. Create the integration code on each of the pages on your site, following the HTML integration and JSON integration guides.
  2. Add this function to your integration code:
Function Requirement
R3_COMMON.addContext(CONTEXT) Replace CONTEXT with a JSON object that defines custom key/value pairs that describe the user context. See the examples below.

Sample Code

Call addContext() in the Primary Code Block.

HTML

<!-- Place code inside the <body> element as close to the top as possible -->
<script src="//media.richrelevance.com/rrserver/js/1.2/p13n.js"></script>
<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('1');  // if exists, set it; if not, set it as session ID
  
  // here's an example requesting recommendations for 1 page area
  R3_COMMON.addPlacementType('home_page.rr1');
    
  var R3_HOME = new r3_home();
 
  // Adding User Attribute data via .addContext()
  
  // Ex1: single object
  R3_COMMON.addContext({
    "userAttribute":{
       "fav_color": ["red", "green"],
       "hair_color": "brown"
    }
  });
  
  // Ex2: multiple calls
  R3_COMMON.addContext({
    "userAttribute": {"fav_color": ["red", "green"]}
  });
  R3_COMMON.addContext({
    "userAttribute": {"hair_color": "brown"}
  });
   
  r3();
  
</script>

JSON

<!-- Place 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 exists, set it; if not, set it as session ID
  
  // here's an example requesting recommendations for 1 page area
  R3_COMMON.addPlacementType('home_page.rr1');
 
  var R3_HOME = new r3_home();
 
  // Adding User Attribute data via .addContext()
  
  // Ex1: single object
  R3_COMMON.addContext({
    "userAttribute":{
       "fav_color": ["red", "green"],
       "hair_color": "brown"
    }
  });
  
  // Ex2: multiple calls
  R3_COMMON.addContext({
    "userAttribute": {"fav_color": ["red", "green"]}
  });
  R3_COMMON.addContext({
    "userAttribute": {"hair_color": "brown"}
  });
 
  rr_flush_onload();
  
  r3();
 
</script>

APIs

Set the registry type with the userAttribute parameter in recsForPlacements.

Example: userAttribute=fav_color:red;green|hair_color:brown