- Created by Andrey Veprikov, last modified on Sept 12, 2023
You are viewing an old version of this page. View the current version.
Compare with Current View Page History
« Previous Version 11 Next »
Method Objective
The method returns an API response when requesting product recommendations.
Syntax and parameters
PersonaClick.recommend(code, params, callback);
Name | Type | Requirement | Description |
---|---|---|---|
code | string | required | Unique code of the recommendation block. See this value in the "data-recommender-code" attribute of the block created in PersonaClick account. |
params | enum | required | Request parameters. |
callback | function | required | A callback function, to which the API response will be passed. Response type: object. |
Request parameters
Name | Type | Requirement | Description |
---|---|---|---|
ITEM | string | required in some cases | Product ID. This parameter is mandatory for the requests of blocks with algorithms that depend on the current product. Algorithms: "Similar", "Products usually purchased with this product", "Store recommendations", etc. |
CATEGORY_ID | string | required in some cases | Category ID. This parameter is mandatory for all blocks set on category pages. |
SEARCH_QUERY | string | required in some cases | The text of the search query. This parameter is mandatory for the requests of blocks that use the "Search" algorithm. |
LIMIT | string | optionally | A maximum number of products in the API response. |
LOCATIONS | string | optionally | String with location IDs separated by comma. If used, the API response will return products available in the listed locations. |
BRANDS | string | optionally | String with brand names separated by comma. If used, only the products of the listed brands will be returned in the API response. |
EXCLUDE_BRANDS | string | optionally | String with brand names separated by comma. If used, the API response will exclude the products of the listed brands. |
CATEGORIES | string | optionally | String with category IDs separated by comma. If used, the API response will only return products that are included in the listed categories. |
DISCOUNT | boolean | optionally | If 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. |
EXTENDED | boolean | optionally | Allows getting extended information about products for self-rendering of the recommended products widget. See the "recommends" property of the API response. Default: false |
API response properties
Name | Type | Description |
---|---|---|
html | string | HTML-code of the block with products. The template is customized in the PersonaClick account. |
title | string | The block title. Corresponds to the value of the "Action" element in the block rules. |
recommends | array/Object Array | Depending on the value of the "EXTENDED" parameter in the API request, it returns either an Array or an Object Array. The Array contains only product IDs. The Object Array contains objects with the following properties:
|
id | number | Unique 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":
Params recommender_params = new Params(); recommender_params.put(Params.Parameter.ITEM, "100500"); 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 algorithms that require the "Category ID":
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":
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:
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"); recommender_params.put(Params.Parameter.EXTENDED, true); PersonaClick.recommend("1fd1b3495137bc3c9299816026acf36f", recommender_params, new Api.OnApiCallbackListener() { @Override public void onSuccess(JSONObject response) { // the functionality of rendering a block of product recommendations } });
Page Navigation
Related Pages
-
Page:
-
Page:
-
Page:
-
Page:
-
Page:
-
Page:
- No labels