-
Notifications
You must be signed in to change notification settings - Fork 8
Recommendations
Product Recommendations is currently in BETA! If you would like to participate in the Beta Pilot Program, please contact Mobile Development at Bazaarvoice
This page describes how you configure the Recommendations in your Android Studio project so you can begin to use the funcionality of the Recommendations SDK module.
NOTE: Make sure you have your Shopper Advertising API Key and Client ID before initializing the BVSDK!
Include Maven Central repository and add Common and Advertising modules to dependencies
dependencies {
compile 'com.bazaarvoice.bvandroidsdk:recommendations:3.2.0'
}
repositories {
mavenCentral()
}
Create a class that extends android.app.Application
and initialize the SDK using its builder. Full list of build options are found in BVSDK.java
public class BVApplication extends Application {
@Override
public void onCreate(){
super.onCreate();
// Builder used to initialize the Bazaarvoice SDKs
BVSDK bvsdk = new BVSDK.Builder(this, YOUR_CLIENT_ID)
.bazaarEnvironment(BazaarEnvironment.PRODUCTION) //Either staging or production. Use corresponding API keys
.apiKeyShopperAdvertising(YOUR_SHOPPER_ADVERTISING_API_KEY) //Required for Recommendations
.logLevel(BVLogLevel.INFO)
.build();
}
}
###AndroidManifest - set the name of the class for the application entry and request internet permission
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".BVApplication">
</application>
Once a Recommendations instance has been created, you can also set an authenticated user for profile matching. Please refer to User Authentication for steps on how to accomplish this.
This step is not required, however, the end-user will receive trending product recommendations over personalized recommendations.
To set authenticated user call setUserWithAuthString on your Recommendations instance:
BVSDK.getInstance().setUserAuthString("USER_AUTH_STRING);
At this point you should be able to fetch a shopper profile with product recommendations.
BVRecommendations recs = new BVRecommendations();
recs.getRecommendedProducts(20, new BVRecommendations.BVRecommendationsCallback() {
@Override
public void onSuccess(List<BVProduct> recommendedProducts) {
Log.d("Demo", recommendedProducts.toString());
}
@Override
public void onFailure(Throwable throwable) {
Log.d("Demo", throwable.getMessage());
}
});
Refer to BVRecommendations.java
methods for getting recommendations based on a categoryId or productId.
Refer to RecommendationsFragment
in the app
module for a demo implementation.
In order to provide Bazaarvoice with feedback about user interaction that can help produce easier Return On Investment reports, and more accurate future recommendations, you should use one of the provided views to wrap either a single recommended product view, or a group of recommended products views.
Suppose you had the following layout to display a single BVProduct
after fetching it as described above,
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
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>
In order to take this and provide Bazaarvoice with feedback you should wrap the LinearLayout
with the provided BvView,
<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>
</com.bazaarvoice.bvandroidsdk.RecommendationView>
Finally, in the code, associate the inflated RecommendationView object with the BVProduct it correlates to. An example of when you would do this is in the getView
method of an Adapter
class MyAdapter extends ArrayAdapter<BVProduct> {
private List<BVProduct> bvProducts;
@Override
public View getView(int position, View convertView, ViewGroup parent) {
...
BVProduct currentBvProduct = getItem(position);
RecommendationView recommendationView = (RecommendationView) convertView.findViewById(R.id.recommendationView);
recommendationView.setBvProduct(currentBvProduct);
...
}
}
Suppose you had the following layout to display a group of BVProduct
s after fetching them as described above,
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recommendationProdRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
In order to take this and provide Bazaarvoice with feedback you should swap the RecyclerView
with the provided RecommendationsRecyclerView
,
<com.bazaarvoice.bvandroidsdk.RecommendationsRecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recommendationProdRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
If you wanted to use other ViewGroups in place of a RecyclerView
the three other options in the SDK are...
RecommendationsListView
<com.bazaarvoice.bvandroidsdk.RecommendationsListView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recommendationProdListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
RecommendationsGridView
<com.bazaarvoice.bvandroidsdk.RecommendationsGridView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recommendationProdGridView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
RecommendationsContainerView - If you wish to use a different ViewGroup than ListView, GridView, or RecyclerView (such as a LinearLayout) to display RecommendationView objects, than you can simply wrap that with a RecommendationsContainerView.
<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>
© 2016 Bazaarvoice, Inc.
Use of this SDK is contingent on your agreement and conformance with Bazaarvoice's API Terms of Use. Additionally, you agree to store all data acquired by this SDK or Bazaarvoice’s API only within the storage of the individual application instance using the SDK or API. You also agree to use the data acquired by the SDK or API only within the context of the same individual application instance and only for purposes consistent with that application’s purpose. Except as otherwise noted, the Bazaarvoice iOS SDK licensed under the Apache License, Version 2.0.