-
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()
}
###Java - Extend Application
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) {
}
});
In order to provide Bazaarvoice with feedback about user interaction that can help produce 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.BvView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bvView"
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 BvView 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);
BvView bvView = (BvView) convertView.findViewById(R.id.bvView);
bvView.setBvProduct(currentBvProduct);
}
...
}
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.
© 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.