Product Recommendations

This documentation explains how to retrieve and display Product Recommendations.

Introduction

📘

The Product Recommendations module is currently in limited beta release. If you'd like to participate, please contact Bazaarvoice.

Use the following guide to fetch and display product recommendations in your app with Bazaarvoice Mobile SDKs.

🚧

You will need your Shopper Advertising API Key and Client ID to implement and use product recommendations.

Installation instructions

Click here to see how to install and configure the BVSDK.

Installation with Gradle

Include the Maven Central repository and add the appropriate Bazaarvoice Mobile SDK modules to your dependencies:

dependencies {  
    implementation 'com.bazaarvoice.bvandroidsdk:recommendations:{BV_SDK_VERSION}.+'  
    implementation 'com.google.android.gms:play-services-ads:9.{YOUR_PLAY_SERVICES_VERSION}'  
    implementation 'com.android.support:recyclerview-v7:25.{YOUR_SUPPORT_LIBRARY_VERSION}'  
}  
repositories {  
    mavenCentral()  
}

Replace the {tokens}, including brackets, with the appropriate values. Refer to the Installation guide for {BV_SDK_VERSION}.

Extending the application

Create a class that extends android.app.Application, and initialize the Mobile SDK using its builder.

You can find a full list of build options in BVSDK.java.

in the following example, YOUR_CLIENT_ID represents your client name, such as "bazaarvoice". If you are unsure about your client ID or API key values, contact Bazaarvoice Support or your implementation team.

public class MyApplication extends Application {
 
    @Override
    public void onCreate(){
        super.onCreate();
        BVSDK.builder(application, BazaarEnvironment.PRODUCTION)
          .logLevel(BVLogLevel.VERBOSE) // Optional: Set the log level. Default level is ERROR.
          .dryRunAnalytics(false)       // Optional: Set analytics to log only, not make a network request. Default is false.
          .okHttpClient(okHttpClient)   // Optional: Use you own okHttpClient instance
          .build();
    }
}

App manifest file

Add the following to your AndroidManifest.xml file.

<!-- set the name of the class for the application entry -->

<application
    android:name=".MyApplication">  
</application>

Set user information

After a user is authenticated inside your user login workflow, set an authenticated user to enable profile matching. Refer to User Authentication Token for instructions.

📘

You must give the userAuthString created with your existing Bazaarvoice implementation logic to the BVSDK.getInstance() object. However, the steps to encrypt your userAuthString are applicable even if you are not a Conversations client.

Example authentication string for testing

If you haven't yet set up an authorization token, use the User Authentication Token example.

Getting recommendations

After you successfully install and configure the SDK and set user information, you can fetch product recommendations with the following steps:

Step 1: Setup the request

RecommendationsRequest.Builder builder = new RecommendationsRequest.Builder(NUM_RECS);

Request Builder Options:

NameTypeDefaultDescriptionPriority
categoryIdStringnullPrefers producs in this category. This is the category external ID as provided in the catalog feed. Can only set categoryId or ProductId. You cannot set both.Recommended
productIdStringnullPrefers products similar to this product. Can only set categoryId or ProductId. You cannot set both.Recommended
PageTypePageTypenullMetadata for the type of page the recommendations are presented. Accepted values are 'home', 'category', 'product', 'cart', 'thankyou' and 'search'.Recommended

Step 2: Provide the request and callback

We recommend that you use the provided view container methods:

BVRecommendations recs = new BVRecommendations();

Or you can use:

recommendationsContainerView.loadRecommendations(request, callback)

Alternatively, if you would prefer to avoid using containers:

BVRecommendations recs = new BVRecommendations();
recs.getRecommendedProducts(20, new BVRecommendations.BVRecommendationsCallback() {
  @Override
  public void onSuccess(BVRecommendationsResponse response) {
    Log.d("Demo", response.getRecommendedProducts().toString());
  }
  @Override
  public void onFailure(Throwable throwable) {
    Log.d("Demo", throwable.getMessage());
  }
});

Displaying recommendations

Wrapping a single recommended product view

In this example, you would use the following layout to display a single BVProduct after fetching it with the methods explained in the "Getting Recommendations" section of this page:

To provide Bazaarvoice with feedback in this layout, wrap the LinearLayout with the provided RecommendationContainerView and RecommendationVIew, as shown in the following example:

<com.bazaarvoice.bvandroidsdk.RecommendationsContainer
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/recommendationView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
 
<com.bazaarvoice.bvandroidsdk.RecommendationView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/recommendationView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="90dp">
            <ImageView
                android:id="@+id/image"
                android:layout_width="90dp"
                android:layout_height="90dp"/>
            <TextView
                android:id="@+id/text"
                android:layout_width="match_parent"
                android:layout_height="90dp" />
    </LinearLayout>

Other options for wrapping a group of recommended product views

If you want to use other ViewGroups in place of a RecyclerView, the Mobile SDK offers the following options:

RecommendationsContainerView — If you want to use a different ViewGroup than ListView, GridView, or RecyclerView—such as a LinearLayout—to display RecommendationView objects, wrap the ViewGroup with a RecommendationsContainerView. The following example shows how you can use a LinearLayout ViewGroup:

<com.bazaarvoice.bvandroidsdk.RecommendationsContainerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recommendationProdContainerView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
 
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
 
    <com.bazaarvoice.bvandroidsdk.RecommendationView
        android:id="@+id/recommendationView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="90dp">
                <ImageView
                    android:id="@+id/image"
                    android:layout_width="90dp"
                    android:layout_height="90dp"/>
                <TextView
                    android:id="@+id/text"
                    android:layout_width="match_parent"
                    android:layout_height="90dp" />
        </LinearLayout>
    </com.bazaarvoice.bvandroidsdk.RecommendationView>
 
    <com.bazaarvoice.bvandroidsdk.RecommendationView
        android:id="@+id/recommendationView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="90dp">
                <ImageView
                    android:id="@+id/image"
                    android:layout_width="90dp"
                    android:layout_height="90dp"/>
                <TextView
                    android:id="@+id/text"
                    android:layout_width="match_parent"
                    android:layout_height="90dp" />
        </LinearLayout>
    </com.bazaarvoice.bvandroidsdk.RecommendationView>
 
</LinearLayout>
 
</com.bazaarvoice.bvandroidsdk.RecommendationsContainerView>