Skip to main content

Android: Purchase Complete Page


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.


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>");

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

// Add callback logic

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.

    "<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>)

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

  • Was this article helpful?