Make sure your AndroidManifest.xml requests permissions to connect to the Internet.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yourcompany.yourappname">
<!-- Basic internet access permission. You should already have this in your app. -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Add this to enable offline click tracking and event throttling. -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
Place this code in your main onCreate
method. The SDK configuration must take place once per app load, and there is no need to duplicate this code in other controllers.
Replace the following placeholders:
- <api key> with your API Key.
- <api client key> with your API Client Key.
- <user ID> with a valid User ID, or use an empty string if you do not have a user ID (for example if the user hasn't logged in yet).
- <session ID> with a valid Session ID
public class SampleApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// First create a configuration and use it to configure the default client.
ClientConfiguration config = new ClientConfiguration("<api key>", "<api client key>");
// Required for logged in users. Leave empty for guest users and temporary users.
config.setUserId("<user ID>");
// Always required.
config.setSessionId("<session ID>");
RichRelevance.init(this, config);
// Optional: Set the log level to debug so you can observe the API traffic
RichRelevance.setLoggingLevel(RRLog.VERBOSE);
}
}
User and Session IDs
RichRelevance leverages user and session identifiers to provide product and content personalization. You must always provide a Session ID for the current user. A Session ID can have any format and duration. For example, you can refresh a Session ID by app load, or after 1 hour of idling, depending on how you define sessions.
You must provide a User ID when a user logs into your app (or when you can identify a returning user with a consistent, unique identifier). RichRelevance relies on User IDs to drive personalization and to build personalized user models based on behavioral data. User ID must be unique and consistent for each user, in other words, they must not change upon subsequent sessions and logins.