Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Method Objective

The method returns an API response when requesting product recommendations.

Syntax and parameters

Code Block
languagejava
themeFadeToGrey
PersonaClicksdk.recommend(code, params,params) { callback); }


NameTypeRequirementDescription
codestringrequired
Unique code of the recommendation block. See this value in the "data-recommender-code" attribute of the block created in PersonaClick account.
paramsenumrequiredRequest parameters.
callbackfunctionrequiredA callback function, to which the API response will be passed
. Response type: object
.

Request parameters

ITEM in some casesThe text of the search querySearch" algorithm.
NameTypeRequirementDescription
blockIdstringrequiredProduct ID. This parameter is mandatory for the requests of blocks that use the algorithms "Similar" and "Also bought".CATEGORY_IDUnique code of the recommendation block. See this value in the "data-recommender-code" attribute of the block created in PersonaClick account.
currentProductIdstringrequired in some casesCategory ID. This parameter is mandatory for all blocks set on category pages.SEARCH_QUERYstringrequired in some casesProduct ID. This parameter is mandatory for the requests of blocks that use the algorithms "
LIMITstringoptionallyA maximum number of products in the API response.
LOCATIONSstringoptionallyString with location IDs separated by comma. If used, the API response will return products available in the listed locations.
BRANDSstringoptionallyString with brand names separated by comma. If used, only the products of the listed brands will be returned in the API response.

EXCLUDE_BRANDS

stringoptionallyString with brand names separated by comma. If used, the API response will exclude the products of the listed brands.
CATEGORIESstringoptionallyString with category IDs separated by comma. If used, the API response will only return products that are included in the listed categories.
DISCOUNTbooleanoptionallyIf used with "true" value, then only those products, the value of which is less than the "oldprice" value, will be returned in the API response.
EXTENDEDbooleanoptionallyAllows getting extended data in the "recommeds" property of the API response.
Similar" and "Also bought".

API response properties

NameTypeDescription
htmlstringHTML-code of the block with products. The template is customized in the PersonaClick account.
titlestringThe block title. Corresponds to the value of the "Action" element in the block rules.
recommendsarray/ObjectArray with product IDs. If an extended response is requested, this property will have an object array with extended information for each product.
idnumberUnique block identifier. Corresponds to the block ID in the list of blocks in the PersonaClick account.

Examples of use

For blocks with algorithms that require the "Product ID"without any additional parameters:

Code Block
languagejavaapplescript
themeFadeToGrey
Params recommender_params = new Params();
recommender_params.put(Params.Parameter.ITEM, "100500");
PersonaClick.recommend("1fd1b3495137bc3c9299816026acf36f", recommender_params, new Api.OnApiCallbackListener(sdk.recommend(blockId: "1fd1b3495137bc3c9299816026acf36f") {     @Override
    public void onSuccess(JSONObject response) {
        recommendResult in
  // the functionality of rendering a block of product recommendations
    }
});

For blocks with algorithms that require the "

Category

Product ID":

Code Block
languagejavaapplescript
themeFadeToGrey
Params recommender_params = new Params();
recommender_params.put(Params.Parameter.CATEGORY_ID, "146");
PersonaClick.recommend("1fd1b3495137bc3c9299816026acf36f", recommender_params, new Api.OnApiCallbackListener() {
    @Override
    public void onSuccess(JSONObject response) {
        // the functionality of rendering a block of product recommendations
    }
});

For blocks with an algorithm that requires the "Search Query":

Code Block
languagejava
themeFadeToGrey
Params recommender_params = new Params();
recommender_params.put(Params.Parameter.SEARCH_QUERY, "To be or not to be");
PersonaClick.recommend("1fd1b3495137bc3c9299816026acf36f", recommender_params, new Api.OnApiCallbackListener() {
    @Override
    public void onSuccess(JSONObject response) {
        // the functionality of rendering a block of product recommendations
    }
});

Full example:

Code Block
languagejava
themeFadeToGrey
Params recommender_params = new Params();
recommender_params.put(Params.Parameter.ITEM, "100500");
recommender_params.put(Params.Parameter.SEARCH_QUERY, "To be or not to be");
recommender_params.put(Params.Parameter.CATEGORY_ID, "146");
recommender_params.put(Params.Parameter.LIMIT, "15");
recommender_params.put(Params.Parameter.BRANDS, "Alas,poor,Yorick");
recommender_params.put(Params.Parameter.CATEGORIES, "1,146,100500");
PersonaClick.recommend("1fd1b3495137bc3c9299816026acf36f", recommender_params, new Api.OnApiCallbackListener() {
    @Override
    public void onSuccess(JSONObject response) {
        sdk.recommend(blockId: "1fd1b3495137bc3c9299816026acf36f", currentProductId: "100500") { recommendResult in
  // the functionality of rendering a block of product recommendations
   
}
});


Table of Contents
classpersonaclick-fixed-position