Skip to main content
RichRelevance

Cart

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.
  • <product ID 1>, <product ID 2>, <product ID 3>with Product IDs currently in the cart.

You do not need to pass Product IDs if the cart is empty. Add IDs for all the products in the cart.

You only need to specify one ID per product. For example, if 3 quantities of Product ID P12389 are present in the cart, you only need to pass "P12389" once.

#import <RichRelevanceSDK/RichRelevanceSDK.h>

RCHRequestPlacement *placement = [[RCHRequestPlacement alloc] initWithPageType:RCHPlacementPageTypeCart name:@"<placement name>"];
    
NSArray *products = @[@"<product ID 1>", @"<product ID 2>", @"<product ID 3>"];
RCHPlacementRecsBuilder *builder = [RCHSDK builderForRecsWithPlacement:placement];
[builder setProductIDs:products];    
__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:RCHPlacementPageTypeCart name:@"recs_top"],
                            [[RCHRequestPlacement alloc] initWithPageType:RCHPlacementPageTypeCart name:@"recs_middle"]
                            ];
    
    RCHPlacementRecsBuilder *builder = [RCHSDK builderForRecsWithPlacement:nil];
    for (RCHRequestPlacement *placement in placements) {
        [builder addPlacement:placement];
    }
    
    [[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 Cart 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.

Replace <product ID 1>, <product ID 2>, <product ID 3>with Product IDs currently in the cart.

You do not need to pass Product IDs if the cart is empty. Add IDs for all the products in the cart.

You only need to specify one ID per product. For example, if 3 quantities of Product ID P12389 are present in the cart, you only need to pass "P12389" once.

#import <RichRelevanceSDK/RichRelevanceSDK.h>

NSArray *products = @[@"<product ID 1>", @"<product ID 2>", @"<product ID 3>"];

RCHRequestPlacement *placement = [[RCHRequestPlacement alloc] initWithListeningPageType:RCHPlacementPageTypeCart];    
RCHPlacementRecsBuilder *builder = [RCHSDK builderForRecsWithPlacement:placement];
[builder setProductIDs:products]; 
[[RCHSDK defaultClient] sendRequest:[builder build]];
  • Was this article helpful?