-
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 may receive trending product recommendations over personalized recommendations.
To set authenticated user call setUserWithAuthString on you Recommendations instance
BVSDK.getInstance().setUserAuthString("USER_AUTH_STRING);
At this point you should be able to fetch a shopper profile with product recommendations.
Recommendations recs = new BVRecommendations();
recs.getRecommendedProducts(20, new Recommendations.BVRecommendationsCallback() {
@Override
public void onSuccess(List<BVProduct> recommendedProducts) {
}
@Override
public void onFailure(Throwable throwable) {
}
});
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.BvView>
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 BVProducts after fetching them as described above,
<ListView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recommendationProdListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
In order to take this and provide Bazaarvoice with feedback you should swap the ListView with the provided BvListView,
<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"/>
If you wanted to use other ViewGroups in place of a ListView the three other options in the SDK are RecommendationsGridView, RecommendationsRecyclerView, and 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.
© 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.