These docs are for v1.0. Click to read the latest docs for v2.0.

Product Recommendations

This integration step is about getting personalized product recommendations. This personalization is provided out of the box using machine intelligence and AI/ML capabilities of Raman, the AI engine of Smartech,

With this integration step, you can get the following product recommendations:

  • Default recommendations
  • Best Seller recommendations
  • New products recommendations
  • Recently viewed recommendations

📘

Note:

This feature is available from SDK v2.5.5.

Getting Product Recommendations

Smartech has introduced the below methods to get different types of product recommendations.

// To get default(boxx) product recommendations.
Smartech.getInstance(new WeakReference<Context>(context)).getBoxxReco(context, boxxRequest, boxxResponseListener);

// To get best_seller product recommendations.
Smartech.getInstance(new WeakReference<Context>(context)).getBoxxBestSellerReco(context, boxxRequest, boxxResponseListener);

// To get recently_viewed product recommendations.
Smartech.getInstance(new WeakReference<Context>(context)).getBoxxRecentlyViewedReco(context, boxxRequest, boxxResponseListener);

// To get new_products recommendations.
Smartech.getInstance(new WeakReference<Context>(context)).getBoxxNewProductsReco(context, boxxRequest, boxxResponseListener);
// To get default(boxx) product recommendations.
Smartech.getInstance(WeakReference(context)).getBoxxReco(context, boxxRequest, boxxResponseListener);

// To get best_seller product recommendations.
Smartech.getInstance(WeakReference(context)).getBoxxBestSellerReco(context, boxxRequest, boxxResponseListener);

// To get recently_viewed product recommendations.
Smartech.getInstance(WeakReference(context)).getBoxxRecentlyViewedReco(context, boxxRequest, boxxResponseListener);

// To get new_products recommendations.
Smartech.getInstance(WeakReference(context)).getBoxxNewProductsReco(context, boxxRequest, boxxResponseListener);

// To get trending product recommendations.
Smartech.getInstance(WeakReference(context)).getBoxxTrendingReco(context, boxxRequest, boxxResponseListener);

Step 1. Create SMTBoxxRequestQuery object.

SMTBoxxRequestQuery object will contain the detailed inputs like item filters, related products, excluded products, and related action types. These inputs will be used to create the response for the product recommendation request.

SMTBoxxRequestQuery.Builder queryBuilder = new SMTBoxxRequestQuery.Builder();
SMTBoxxRequestQuery smtBoxxRequestQuery;

// Setting the item filters.
JSONObject itemFilters = new JSONObject();
itemFilters.put("boost_factor", 1);
queryBuilder.setItemFilters(itemFilters);

// Setting the related products.
String[] relatedProducts = {"PRODUCT_ID1", "PRODUCT_ID2", "PRODUCT_ID3"};
queryBuilder.setRelatedProducts(relatedProducts);

// Setting the context.
JSONObject context = new JSONObject();
context.put("boxx_location_code", 56);
queryBuilder.setContext(context);

// Setting products to exclude.
String[] exclude = {"PRODUCT_ID4", "PRODUCT_ID5"};
queryBuilder.setExclude(exclude);

// Setting transaction types not to repeat.
String[] dontRepeatTransactionTypes = {"ACTION_TYPE1", "ACTION_TYPE2"};
queryBuilder.setDontRepeatTransactionTypes(dontRepeatTransactionTypes);

// Setting whether you want to get the product properties.
queryBuilder.setGetProductProperties(true);

// Setting the num.
queryBuilder.setNum(45);

// Setting the offset.
queryBuilder.setOffset(30);

// Setting the related action type.
queryBuilder.setRelatedActionType("view");

// Setting whether you want to get the product liked disliked status.
queryBuilder.setGetProductLikedDislikedStatus(true);

// Setting whether you want to get the product aliases.
queryBuilder.setGetProductAliases(true);

// Setting extra inputs.
HashMap<String, Object> extras = new HashMap<>();
extras.put("Key1", "Value1");
extras.put("Key2", 2);
extras.put("Key3", true);
queryBuilder.setExtras(extras);

smtBoxxRequestQuery = queryBuilder.build();
val queryBuilder = SMTBoxxRequestQuery.Builder()
val smtBoxxRequestQuery: SMTBoxxRequestQuery

// Setting the item filters.
val itemFilters = JSONObject()
itemFilters.put("boost_factor", 1)
queryBuilder.itemFilters = itemFilters

// Setting the related products.
val relatedProducts = arrayOf("PRODUCT_ID1", "PRODUCT_ID2", "PRODUCT_ID3")
queryBuilder.relatedProducts = relatedProducts

// Setting the context.
val context = JSONObject()
context.put("boxx_location_code", 56)
queryBuilder.context = context

// Setting products to exclude.
val exclude = arrayOf("PRODUCT_ID4", "PRODUCT_ID5")
queryBuilder.exclude = exclude

// Setting transaction types not to repeat.
val dontRepeatTransactionTypes = arrayOf("ACTION_TYPE1", "ACTION_TYPE2")
queryBuilder.dontRepeatTransactionTypes = dontRepeatTransactionTypes

// Setting whether you want to get the product properties.
queryBuilder.getProductProperties = true

// Setting the num.
queryBuilder.num = 45

// Setting the offset.
queryBuilder.offset = 30

// Setting the related action type.
queryBuilder.relatedActionType = "view"

// Setting whether you want to get the product liked disliked status.
queryBuilder.getProductLikedDislikedStatus = true

// Setting whether you want to get the product aliases.
queryBuilder.getProductAliases = true

// Setting extra inputs.
val extras = HashMap<String, Any>()
extras["Key1"] = "Value1"
extras["Key2"] = 2
extras["Key3"] = true
queryBuilder.extras = extras
smtBoxxRequestQuery = queryBuilder.build()

Step 2. Create SMTBoxxRequest object.

After creating a SMTBoxxRequestQuery object you need to create SMTBoxxRequest object and then pass the SMTBoxxRequestQuery object in an object inside SMTBoxxRequest.

SMTBoxxRequest smtBoxxRequest = new SMTBoxxRequest();

// Setting the locale.
smtBoxxRequest.setLocale("EN");                                  

// Setting the SMTBoxxRequestQuery object to input product recommendation API.
smtBoxxRequest.setQuery(smtBoxxRequestQuery);
val smtBoxxRequest = SMTBoxxRequest()

// Setting the locale.
smtBoxxRequest.locale = "EN"

// Setting the SMTBoxxRequestQuery object to input product recommendation API.
smtBoxxRequest.query = smtBoxxRequestQuery

Step 3. Invoke method to get product recommendations.

Once you create SMTBoxxRequest object call the product recommendations method of desired recommendation type and set a listener to listen to the API response.

Smartech.getInstance(new WeakReference<Context>(context)).getBoxxReco(this, smtBoxxRequest, new SMTBoxxResponseListener() {
  @Override
    public void onResponse(@Nullable SMTBoxxResponse smtBoxxResponse) {
    try {
      if (smtBoxxResponse != null) {
        int responseCode = smtBoxxResponse.getResponseCode();
        String responseMessage = smtBoxxResponse.getResponseMessage();
        String responseData = smtBoxxResponse.getResponseData();

        JSONObject productRecommendations = new JSONObject(responseData);
      }
    } catch (JSONException e) {
      e.printStackTrace();
    }
  }
});
Smartech.getInstance(WeakReference(context)).getBoxxReco(this, smtBoxxRequest, object : SMTBoxxResponseListener {
  override fun onResponse(smtBoxxResponse: SMTBoxxResponse?) {
    try {
      if (smtBoxxResponse != null) {
        val responseCode: Int = smtBoxxResponse.responseCode
        val responseMessage: String = smtBoxxResponse.responseMessage
        val responseData: String = smtBoxxResponse.responseData
        
        val productRecommendations = JSONObject(responseData)
        }
    } catch (e: JSONException) {
      e.printStackTrace()
      }
  }
})

The SMTBoxxResponseListener will callback onResponse() with SMTBoxxResponse object. SMTBoxxResponse will contain the below methods to get the API response details.

VariableReturn TypeDescription
getResponseCode()intResponse code of the product recommedation API request.
getResponseMessage()StringResponse message of the product recommedation API request.
getResponseData()StringResponse sent by the product recommedation API.