Skip to main content
RichRelevance

Android: Purchase Complete Page

Overview

The Purchase Complete page is the experience available to customers immediately after they successfully purchased their items.

This is a required integration type. You must include the tracking logic even if you do not serve personalization in this section.

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.
  • For each purchased product, replace:
    • <product ID>with the Product ID of the purchased item
    • <product quantity>with the purchased quantity for this product
    • <product single price> with the price for a single unit of this product. For example, if a customer purchased 3 products P12389, and its price was 9.99 per item, the value for this argument will be 9.99.
    • <order ID> with an identifier for this order, such as a Confirmation ID.

Make sure to add all the products in the order. In order to successfully log a purchase you must pass at least one valid product.

In addition to the variadic signature, addPurchasedProducts() can also accept a Collection<Product>.

Placement placement = new Placement(Placement.PlacementType.PURCHASE_COMPLETE, "<placement name>");

RichRelevance.buildRecommendationsForPlacements(placement)
  .addPurchasedProducts(
      new Product("<product ID 1>", <product quantity 1>, <product single price 1>),
      new Product("<product ID 2>", <product quantity 2>, <product single price 2>),
      new Product("<product ID 3>", <product quantity 3>, <product single price 3>)
  ).setOrderId("<order ID>")
  .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.PURCHASE_COMPLETE, "recs_top");
Placement middlePlacement = new Placement(Placement.PlacementType.PURCHASE_COMPLETE, "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.PURCHASE_COMPLETE, "recs_top"),
        new Placement(Placement.PlacementType.PURCHASE_COMPLETE, "recs_middle"))
    );

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

Listening Mode

When you do not render personalization in your Purchase Complete 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.

RichRelevance.buildLogPurchase(
    "<order id>",
    new Product("<product ID 1>", <product quantity 1>, <product single price 1>),
    new Product("<product ID 2>", <product quantity 2>, <product single price 2>),
    new Product("<product ID 3>", <product quantity 3>, <product single price 3>)
).execute();

In addition to the variadic signature, buildLogPurchase() can also accept a Collection<Product>.

  • Was this article helpful?