Skip to main content
RichRelevance

Android: Category Page

 

Overview

 A Category screen displays either a subset of related products or a group of sub-categories that help the customer navigate deeper into your inventory. It may be a department section, vertical etc., depending on your nomenclature.

Details

Place your code in your fragment's initialization logic, such as onCreate.

Return Personalization

Use this code when you are requesting and serving personalized product recommendations.

Replace the following placeholders in the code:

  • <placement name> with your Placement name. You can find a list of placements in your Dashboard.
  • <category ID>with the ID of the category currently being viewed.
Placement placement = new Placement(Placement.PlacementType.CATEGORY, "<placement name>");

RichRelevance.buildRecommendationsForPlacements(placement)
  .setCategoryId("<category ID 1>")
  .setCallback(new Callback<PlacementResponseInfo>() {
      @Override
      public void onResult(PlacementResponseInfo result) {          
          int index = 0;
          for(PlacementResponse placement : result.getPlacements()) {
              for(final RecommendedProduct recommendedProduct : placement.getRecommendedProducts()) {
                  // Add your view init logic. The actual implementation will depend on your code.
                  // In this example we will assume items are rendered as TableRows in a TableView.
                  TableRow row = new TableRow(context);
                  row.setId(index);
                  row.addView(detailView);
                  index++;
                  tableView.addLayout(row);
              }
          }
      }
      @Override
      public void onError(Error error) {
          // Use this code block to handle errors
          Log.e(getClass().getSimpleName(), "Error: " + error.getMessage());
      }
  }).execute();

Calling multiple placements

If you want to call multiple placements, simply define your placements and pass them to RichRelevance.buildRecommendationsForPlacements() either as individual arguments or as a Collection<Placement>.

IMPORTANT Placements must always be of the same type per request.

// This example defines placements as individual arguments.
Placement topPlacement = new Placement(Placement.PlacementType.CATEGORY, "recs_top");
Placement middlePlacement = new Placement(Placement.PlacementType.CATEGORY, "recs_middle");

RichRelevance.buildRecommendationsForPlacements(topPlacement, middlePlacement)
// Add callback logic
.execute();
// This example defines placements as an ArrayList. It is equivalent to the example above.
ArrayList<Placement> placements = new ArrayList<>(
    Arrays.asList(
        new Placement(Placement.PlacementType.CATEGORY, "recs_top"),
        new Placement(Placement.PlacementType.CATEGORY, "recs_middle"))
    );

RichRelevance.buildRecommendationsForPlacements(placements)
// Add callback logic
.execute();

Listening Mode

When you do not render personalization in your Category UX, you must still send a tracking request using the SDK. This is required so that Personalization Cloud can gather usage data in order to train your personalization models. In this specific case, you can use a convenience builder that sets all the configuration parameters (including a listening placement) automatically.

Replace <category ID>with the ID of the category currently being viewed.

RequestBuilder builder = RichRelevance.buildLogCategoryView("<category ID>");
builder.execute();
  • Was this article helpful?