Skip to main content
RichRelevance

Purchase Complete

Place this code in your native view initialization logic, such as viewDidLoad.

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.

#import <RichRelevanceSDK/RichRelevanceSDK.h>

RCHRequestPlacement *placement = [[RCHRequestPlacement alloc] initWithListeningPageType:RCHPlacementPageTypePurchaseComplete];
 RCHPlacementRecsBuilder *builder = [RCHSDK builderForRecsWithPlacement:placement];
NSArray *purchasedProducts = @[
                               [[RCHRequestProduct alloc] initWithIdentifier:@"<product ID 1>" quantity:[NSNumber numberWithInt:<product quantity 1>] priceDollars:[NSNumber numberWithFloat:<single item price 1>]],
                               [[RCHRequestProduct alloc] initWithIdentifier:@"<product ID 2>" quantity:[NSNumber numberWithInt:<product quantity 2>] priceDollars:[NSNumber numberWithFloat:<single item price 2>]],
                               [[RCHRequestProduct alloc] initWithIdentifier:@"<product ID 3>" quantity:[NSNumber numberWithInt:<product quantity 3>] priceDollars:[NSNumber numberWithFloat:<single item price 3>]],
];


for (RCHRequestProduct product in purchasedProducts) {
    [builder addPurchasedProduct:product];
}

[builder setOrderID:@"<order ID>"];
__block RCHRecommendedProduct *product;
[[RCHSDK defaultClient] sendRequest:[builder build] success:^(id responseObject) {
    RCHPlacementsResult *result = responseObject;
    RCHPlacement *placement = result.placements[0];
    product = placement.recommendedProducts[0];
} failure:^(id responseObject, NSError *error) {
    // Use this code block to handle any errors that may occur while loading recommendations.
    NSLog(@"Error encountered: %@", error);
}];

Calling multiple placements

If you want to call multiple placements, simply initialize a builder with a nil placement, then define your placements and pass them to builder:addPlacement. You can also create a list such as a NSArray and iterate with a for..in loop.

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

    NSArray *placements = @[
                            [[RCHRequestPlacement alloc] initWithPageType:RCHPlacementPageTypePurchaseComplete name:@"recs_top"],
                            [[RCHRequestPlacement alloc] initWithPageType:RCHPlacementPageTypePurchaseComplete name:@"recs_middle"]
                            ];
    
    RCHPlacementRecsBuilder *builder = [RCHSDK builderForRecsWithPlacement:nil];
    for (RCHRequestPlacement *placement in placements) {
        [builder addPlacement:placement];
    }
    
    for (RCHRequestProduct product in purchasedProducts) {
        [builder addPurchasedProduct:product];
    }
    
    [[RCHSDK defaultClient] sendRequest:builder success:^(id responseObject) {
        // Add your display logic here
    } failure:^(id responseObject, NSError *error) {
        // Add your error handling logic here
    }];

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 RichRelevance 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.

#import <RichRelevanceSDK/RichRelevanceSDK.h>

RCHRequestPlacement *placement = [[RCHRequestPlacement alloc] initWithListeningPageType:RCHPlacementPageTypePurchaseComplete];
RCHPlacementRecsBuilder *builder = [RCHSDK builderForRecsWithPlacement:placement];

NSArray *purchasedProducts = @[
                               [[RCHRequestProduct alloc] initWithIdentifier:@"<product ID 1>" quantity:[NSNumber numberWithInt:<product quantity 1>] priceDollars:[NSNumber numberWithFloat:<single item price 1>]],
                               [[RCHRequestProduct alloc] initWithIdentifier:@"<product ID 2>" quantity:[NSNumber numberWithInt:<product quantity 2>] priceDollars:[NSNumber numberWithFloat:<single item price 2>]],
                               [[RCHRequestProduct alloc] initWithIdentifier:@"<product ID 3>" quantity:[NSNumber numberWithInt:<product quantity 3>] priceDollars:[NSNumber numberWithFloat:<single item price 3>]],
];


for (RCHRequestProduct product in purchasedProducts) {
    [builder addPurchasedProduct:product];
}

[builder setOrderID:@"<order ID>"];
[[RCHSDK defaultClient] sendRequest:[builder build]];

Product Pricing

You can pass product prices in your local currency to RCHRequestProduct initWithIdentifier:quantity:priceDollars:. As an alternative, you can pass prices in cents. Example: one dollar has 100 cents, so the value for USD will be 100. The Yen is the smallest unit in Japan, so the value for JPY will be 1.

/** 
 * In this example we will define a purchased product in Euro (price EUR 29.99).
 * In the first line, we will pass its price using a float.
 * In the second line, we will pass its price using an integer. One Euro has 100 cents, so we need to multiply the original product price by 100.
 *
 * IMPORTANT: Do not use both priceDollars and priceCents in the same request. If you do so, we will only record pricing in local currency.
 */
RCHRequestProduct *productInLocalCurrency =  [[RCHRequestProduct alloc] initWithIdentifier:@"EURPRD192321" quantity:[NSNumber numberWithInt:1] priceDollars:[NSNumber numberWithFloat:29.99]];
RCHRequestProduct *productInCents =  [[RCHRequestProduct alloc] initWithIdentifier:@"EURPRD192321" quantity:[NSNumber numberWithInt:1] priceCents:[NSNumber numberWithInt:2999]];

IMPORTANT Do not use both  initWithIdentifier:quantity:priceDollars: andinitWithIdentifier:quantity:priceCents:in the same request. If you do so, we will only record pricing in local currency.

  • Was this article helpful?