Integrating RR cookies for RecsForPlacements
Overview
The recsForPlacement API returns a field called “rcs” in the json reponse. This “rcs" parameter is the encrypted Algonomy cookie for the user associated with the API request. It contains various RR IDs including the RR USER GUID. Clients take the rcs parameter received from API and store it in a cookie named “rr_rcs” on the browser under their domain. They can then pass this rr_rcs cookie value as a parameter to subsequent recsForPlacements server side calls with the api parameter called “rcs”.
Clients should ensure to preserve the 'rcs' value just as it was served. The 'rcs' parameter is always alphanumeric and case-sensitive, with the token value including a mix of uppercase letters, lowercase letters, and numbers.
This will allow the cookie to pass through via first party cookie when recsForPlacements api is used server side.
Code Sample
IMPORTANT: This sample is strictly for illustration purpose. We have not tried and tested it.
final static String RCS_PARAM = "rcs";
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String RR_RCS_COOKIE_NAME = "rr_rcs";
String rcsValue = null;
// Get the cookies from the merchant site.
javax.servlet.http.Cookie[] cookies = req.getCookies();
for (javax.servlet.http.Cookie cookie : cookies) {
// rcs cookie needs to be passed to recsForPlacements API as a query parameter
if (cookie.getName().equals(RR_RCS_COOKIE_NAME)) {
rcsValue = cookie.getValue();
break;
}
}
// Call the API
WebResource r = Client.create().resource(constructAPIURl(rcsValue));
ClientResponse response = r.get(ClientResponse.class);
// Grab the rcs value from the API response and set it as a cookie
String responseString = response.getEntity(String.class);
JSONObject jsonResponse = new JSONObject(reponseString);
if(jsonResponse.has(RCS_PARAM)){
String updatedRcsValue = jsonResponse.getString(RCS_PARAM);
javax.servlet.http.Cookie httpCookie = new javax.servlet.http.Cookie(RR_RCS_COOKIE_NAME, updatedRcsValue);
httpCookie.setMaxAge(nc.getMaxAge()); // Set domain according to site policy.
resp.addCookie(httpCookie);
}
//process rest of the response
}
private String constructAPIURl(String rcsValue){
//regular API URL construction
String apiUrl = "http://recs.richrelevance.com/rrserver/api/rrPlatform/recsForPlacements?"
if (rcsValue != null){
apiUrl += "&RCS_PARAM=" + rcsValue;
}
return apiUrl;
}