Installing UserReport SDK to Android Application

This guide will walk you through how to install UserReport survey tool on your native Android app.

Please notice that it is a technical guide and therefore it is targeted to developers.

Before proceeding with this guide, you need to configure as “ Android app” your media in UserReport interface. You can do this by going to the media settings and adding a new media.  When asked on which media you want to run UserReport please select Android app.

Android_app.png

Once this is done, you will find the two SDK initializations parameters that will be needed to configure UserReport in-app code:  the SAK_ID (to identify your account) and the MEDIA_ID (to identify your app).

iOS_App_skd_media_id.png

Adding UserReport SDK to your app

Add dependencies to app/build.gradle.

1. Add dependencies to app/build.gradle

 apply plugin: 'com.android.application'

dependencies {

    compile "com.android.support:appcompat-v7:22.1.1"
    compile "com.audienceproject:userreport:0.+"
    compile "com.google.android.gms:play-services:7.5.0+"

}

 
android {

    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {

        applicationId "com.userreport.example.myapplication"
        minSdkVersion 21
        targetSdkVersion 22

        versionCode 1

        versionName "1.0"

    }
}

 

 
2. Add permissions to app/src/main/AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mixpanel.example.myapplication" > 
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" >
        <activity android:name=".MainActivity" android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

 

 
3. Add UserReport to your main activity app/src/main/java/com/userreport/example/myapplication/MainActivity.java

package com.mixpanel.example.myapplication;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import com.audienceproject.UserReport;

public class MainActivity extends ActionBarActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        String sakId = YOUR_SAK_ID; // eg: "yourcompany" 
        String mediaId = YOUR_MEDIA_ID; // eg: "b2a408cb-719d-4468-a943-1187201d1ccb" 

        new UserReportBuilder(sakId, mediaId)
                .build(this);

    }
}

User identification parameters

If you want to send user identification parameter you can do it in following way:


new UserReportBuilder(ACCOUNT_ID, MEDIA_ID)
    .setUserInfo(UserIdentificationType.EmailSha256, "87924606b4131a8aceeeae8868531fbb9712aaa07a5d3a756b26ce0f5d6ca674")
    .build(this);

 Please notice that you always need to send hashed emails.

Invitation rules

By default, users are eligible for an invitation after spending in application X minutes and total Y screen-views. The screen view is an activity start inside your app, when a user becomes eligible for invitation in Z seconds from application session started we will check if the user can be invited:
- Is the survey enabled for this media?
- Is the current user not in the UserReport quarantine?
 
If answers on both questions and on the invitation frequency selected in UserReport interface, the user will or won't be invited to the survey.
 
When the invitation is shown - we put the user to quarantine so he or she will be not invited again and again. Depending on what action the user will perform in invitation – the quarantine period will last for a different span of time. Here you can find detailed information on quarantine rules applied.

Testing

During development, it is very important to set test mode on. It will guarantee that pop up will appear each time when invite conditions met (X minutes and total Y screen-views). You can do it in the following way 


new UserReportBuilder(ACCOUNT_ID, MEDIA_ID)
    .setSurveyTestMode()
    .build(this);

Automatically measure activity state changes as page views

If you want to automatically measure Activity State Changes as page views, use the UserReportBuilder with the default provided invoker, the StandardInvoker class.

new UserReportBuilder(YOUR_SAK_ID, YOUR_MEDIA_ID)
.setSurveyInvoker(
new StandardInvoker(context, this.getSettingsLoader(context), prefWrapper)
;

Manually measure any kind of event as a screen view

To manually register any kind of event as a screen view, use the UserReportBuilder with the ManualEventSurveyInvoker class. This class allows you to increment the view counter on any kind of custom provided event by simply calling the makeEvent() method. 

new UserReportBuilder(YOUR_SAK_ID, YOUR_MEDIA_ID)
.setSurveyInvoker(new ManualEventSurveyInvoker(5));

Alternatively, you can implement even more complex custom Invokers by implementing the ISurveyInvoker interface.

Change Settings

To update the default rules for the rendering of the survey use the UserReportBuilder with the ActivityChangesSurveyInvoker class. This invoker allows you to specify after how many view counts the survey should be invoked.

new UserReportBuilder(YOUR_SAK_ID, YOUR_MEDIA_ID)
.setSurveyInvoker(new ActivityChangesSurveyInvoker(this, 5, MainActivity.class.getName()))
.skipInAppActivityChangeFor("");

You can use the skipInAppActivityChangeFor(“ActivityClassName”) method to prevent counting switches to specific activities, like for example to the main activity.

Update user information

When changing user data, you should also send the updated data to the UserReport survey instance.

this.survey.setUserInfo(UserIdentificationType.Email, "email@google.com");

Manually trigger the survey based on custom parameters

If you decide to trigger the survey manually based on custom parameters, you can use the following method attached to the survey instance:

this.survey.tryInvite();

Debugging

For debugging purposes, we recommend to implement ISurveyLogger and set it during initialization. Like this 


new UserReportBuilder(ACCOUNT_ID, MEDIA_ID)
    .setSurveyTestMode() 
    .setLogger(new someCustomLoggerImplementation())
    .build(this);

Attachments

Comments

Powered by Zendesk