- Add the required permissions to your AndroidManifest.xml file
- Implement an extended Application class with the needed RSClient
- Point the AndroidManifest to the Application class you created
Add the required permissions to your AndroidManifest.xml file.
The following permissions need to be added to the `AndroidManifest.xml` file:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
Your `AndroidManifest.xml` looks something like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.package.name" >
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application ......
Now, the RSClient class is accessible within your project. To completely implement the RSClient, we need to make sure the init methods are called prior to any event calls.
You may have other preferred implementations for library initializers being called prior to complete application initialization, but the following is the suggested implementation.
Implement an extended Application class with the needed RSClient
Java:
public class MainActivity extends ActionBarActivity {
private static final String TAG = "MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
// Set the environment to staging. Calling this method will transmit
// all the events to Retention Science staging server.
// NOTE: THIS METHOD SHOULD NOT BE CALLED IN PRODUCTION ENVIRONMENT OR DURING INTEGRATION TESTING
RSClient.setStagingEnvironment();
// initializeWithSiteId should be called once before making any tracking/event call
// Application.onCreate is the recommended place to put this
RSClient.initializeWithSiteId("1000", this.getApplication());
// Used to set userId depending on app implementation. Potentially after the user is logged in. This
// userId will be part of each tracking event. Appropriate place to call -
// after user login is complete or if the app maintains user session then retrieve this id
// from the session object and pass it to this method on app create
RSClient.setUserId("user12345");
// Used for tracking marketing / other source providers. (Optional method call)
RSClient.setDeviceIdSource("deviceId12345678");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
The core initialization only requires the following:
RSClient.initializeWithSiteId("XXX", this.getApplication());
The above initialization makes sure that each event transmitted from the current project has the unique Id provided by Retention Science. “XXX” is the Site Id provided to you by Retention Science.
The other calls in the above code snippet are not required and depend on your implementation. Here is the explanation of other methods shown in the above code snippet:
RSClient.setStagingEnvironment();
The above method should be called as part of initialization only while you are testing the project. The main role of this method is to set the staging environment under RSClient. This transmits all
events to the Retention Science staging server. This method also enables all RSClient logs.
Important: The above method shouldn't be called in the production environment. |
In the production environment, RSClient transmits events to the server - `https://waves.retentionscience.com/wave`. Add this to the list of domain exceptions if your project requires one. The staging endpoint is `https://waves.retentionsandbox.com/wave`.
RSClient.setUserId("user12345");
The above method sets the `userId` to be tracked in each event call. You can call this method based on your project implementation, typically after user login is complete or if the app maintains the user session where the Id is retrieved from the session object and passed into this method.
RSClient.setDeviceIdSource("deviceId12345678");
Used for tracking marketing / other source providers. (Optional method call)
Point the AndroidManifest to the Application class you created
<application
android:name="com.package.name.MainActivity" ....
The AndroidManifest.xml looks something like:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.package.name" >
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.package.name.MainActivity"
android:label="@string/app_name" > ......
Now your application always calls the RSClient's initialize function when the application is Initialized.
Comments
0 comments
Please sign in to leave a comment.