Skip to main content

Android: Add to Cart Page


The Add To Cart screen is typically any experience (such as a popover or a confirmation view) displayed immediately after a customer adds a product to their shopping cart. It is a distinct experience separate from the cart, typically offering other products, options, or information relevant to the product just added to the cart. It is a distinct experience separate from the user's Cart, which is typically the last screen visited before checkout.


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.
  • <product ID> with the Product ID being added to the cart.
Placement placement = new Placement(Placement.PlacementType.ADD_TO_CART, "<placement name>");

  .setAddedToCartProductId("<product ID>")
  .setCallback(new Callback<PlacementResponseInfo>() {
      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);
      public void onError(Error error) {
          // Use this code block to handle errors
          Log.e(getClass().getSimpleName(), "Error: " + error.getMessage());

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.ADD_TO_CART, "recs_top");
Placement middlePlacement = new Placement(Placement.PlacementType.ADD_TO_CART, "recs_middle");

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

// Add callback logic

Listening Mode

When you do not render personalization in your Home UX, you must still send a Home 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 will create a listening placement. Listening placements are a special type of placement that can only log usage data without returning personalization data.

Replace <product ID> with the Product ID being added to the cart.

Placement placement = new Placement(Placement.PlacementType.ADD_TO_CART);
RichRelevance.buildRecommendationsForPlacements(placement).setAddedToCartProductId("<product ID>").execute();
  • Was this article helpful?