Login

Integration Tools

iOS Integration Test

iOS Device Event Log

Android Integration Test

Android Device Event Log

Sandbox Event Log

Android Device Event Log
NOTE Go to pre SDK 2.0.0 instructions
Start Understanding
Your People
Enable
Personalized Push
Enrich Your
People Profiles
  • Requirements - The Kahuna Android SDK currently supports Android 2.2+ (API level 8 and above) devices and requires internet to be added as a permission to your application if you plan on integrating with the SDK.
    First, get the Kahuna SDK into your app.
    2. Add the Kahuna jar to your project:
    • For Eclipse: show me
      Unzip the file and drag Kahuna.jar into the libs directory of your Android project.
      NoteIf your project doesn't have a libs directory, right-click your project and add it as new directory.
      Note Depending on which version of eclipse you are using, adding the jar to the "libs" directory may have already setup your build path dependencies. You can check this by expanding the "AndroidDependencies" icon and seeing if "Kahuna.jar" is populated there, if not you will need to add the Kahuna library to your build path.
      You can do this by right-clicking on your project -> Build Path -> Configure Build Path...
      Then, select the "Libraries" tab in the Java Build Path section. Once there, you can select "Add JARs...", then select your project and select the Kahuna.jar from "libs". Click "OK" twice to close both dialogs.
      Now that you've got all the files you need in place, it's time to start using the Kahuna SDK.
    • For Android Studio: show me
      In Android Studio, open the project for your app, then open the Project Window.
      Open the build.gradle file for your project. It has the name
      build.gradle (Project: your_project_name) (callout 1).
      In the allprojects section of build.gradle, add the following line:
      maven { url "https://kahuna.github.io/kahuna-android/sdk" }.
      Next, open the build.gradle file for the module that contains your app. It has the name
      build.gradle (Module: your_app_module_name) (callout 2). In most cases, your_app_module_name is app.
      In the dependencies section of build.gradle, add the following line:
      compile 'com.kahuna.sdk:kahuna:2.+'
      Finally, re-sync your project to apply these changes
    3. Add the Android Support Library to your project.

    Kahuna requires Android Support Library version 4.

    To add the Android Support Library to your app:

    • a. On the Android Developer website, open the topic Support Library Setup.
    • b. Find the section "Adding libraries without resources".
    • c. For your development environment (Eclipse or Android Studio), follow the instructions for adding the Android Support Library to your project.
    4. Setup Google Play services for your project.

    Kahuna requires the following components of Google Play services:

    • Google Actions, Base Client Library: com.google.android.gms:play-services-base:8.1.0
    • Google Cloud Messaging: com.google.android.gms:play-services-gcm:8.1.0
    • Google Location, Activity Recognition, and Places: com.google.android.gms:play-services-location:8.1.0
    Note: If you do a custom installation of Google Play services in Android Studio, you must include the required components in your build; otherwise, your app may crash.
    (Google does not allow you to customize the installation of Google Play services in Eclipse with ADT.)

    To add Google Play services to your app:

    • a. On the Google Developers website (not the Android site), open the topic Setting Up Google Play Services.
    • b. Find the section "Add Google Play Services to Your Project".
    • c. For your development environment (Eclipse with ADT or Android Studio), follow the instructions for adding Google Play services to your project.
    5. Ensure that your Android app has permission to access the Internet.

    If you haven't done it already, add the permission android.permission.INTERNET to your manifest.

    <uses-permission android:name="android.permission.INTERNET" />
    Now, what data do you have on the people who use your app?
    May have Username/Email
    May have Other Credentials
    Anonymous Only
    • Your app allows some form of user login and/or registration. Some users can continue to use your app anonymously if they want.
      6. In your Main Application class, incorporate the following lines:
      IMPORTANT! Please make sure usernames & emails are UNIQUE across all your users. Why?
      
      public class SampleApplication extends Application {
      
          @Override
          public void onCreate() {
              super.onCreate();
      
              Kahuna.getInstance().onAppCreate(this, "INSERT_APP_KEY", null);
      
              //TODO: Load your app's credentials here (if any)
              IKahunaUserCredentials credentials = Kahuna.getInstance().createUserCredentials();
              credentials.add(KahunaUserCredentials.USERNAME_KEY, USERNAME_HERE);
              credentials.add(KahunaUserCredentials.EMAIL_KEY, EMAIL_HERE);
              try {
                  Kahuna.getInstance().login(credentials);
              } catch (EmptyCredentialsException e) {
                  // The SDK does not accept null or empty UserCredentials.
              }
          }
      }
                          
    • Your app allows some form of user login and/or registration. Some users can continue to use your app anonymously if they want. This page is to allow your app to pass in even more credentials besides just username and email.
      6. In your Main Application class, incorporate the following lines:
      IMPORTANT! Please make sure all user credentials are UNIQUE across all your users. Why?
      
      public class SampleApplication extends Application {
      
          @Override
          public void onCreate() {
              super.onCreate();
      
              Kahuna.getInstance().onAppCreate(this, "INSERT_APP_KEY", null);
              //TODO:Load your user credentials here
              IKahunaUserCredentials credentials = Kahuna.getInstance().createUserCredentials();
              credentials.add(KahunaUserCredentials.USER_ID_KEY, USER_ID_HERE);
              credentials.add(KahunaUserCredentials.USERNAME_KEY, USERNAME_HERE);
              credentials.add(KahunaUserCredentials.EMAIL_KEY, EMAIL_HERE);
              credentials.add(KahunaUserCredentials.FACEBOOK_KEY, FACEBOOK_ID_HERE);
              credentials.add(KahunaUserCredentials.TWITTER_KEY, TWITTER_ID_HERE);
              credentials.add(KahunaUserCredentials.LINKEDIN_KEY, LINKEDIN_ID_HERE);
              credentials.add(KahunaUserCredentials.GOOGLE_PLUS_ID, GOOGLE_PLUS_ID_HERE);
              credentials.add(KahunaUserCredentials.INSTALL_TOKEN_KEY, INSTALL_TOKEN_HERE);
              try {
                  Kahuna.getInstance().login(credentials);
              } catch (EmptyCredentialsException e) {
                  // The SDK does not accept null or empty UserCredentials.
              }
          }
      }
                          
    • Your app does not allow user login or user registration in any form.
      6. In your Main Application class, incorporate the following line:
      
      public class SampleApplication extends Application {
      
          @Override
          public void onCreate() {
              super.onCreate();
      
              Kahuna.getInstance().onAppCreate(this, "INSERT_APP_KEY", null);
              // Your Code Here
          }
      }
                          
  • The Kahuna Android SDK now supports sending targeted push notifications! Follow these steps to get it hooked up in your app after you have done the basic integration.
    Requirements - Push requires Android 2.2+ and requires an end user to have a Google account on their device if they are running a version lower than Android 4.0.4. Push also requires the end user to have the Google Play Store installed on their device.
    1. Get your Google API key and note your project number - You'll need to setup a Google API project in order to support Push in your application. (if you already have a Google API project setup for your app, you may skip this step). show me
    First thing you'll need to do is create a Google API project here: Google API Console
    If you haven't created an API project yet, you can easily create one by clicking Create Project. Just supply a project name and click Create
    After you create a new project or select an existing project from the dashboard, you will see a screen similar to the following:
    Take note of the number following Project Number (926399374613 in the above image). This is your project number and SenderId which you will use later for the integration.
    Next, you'll need to enable the Google Cloud Messaging (GCM) for Android service.
    Finally, you need to generate an API key for your project. We will need your API key in order to perform pushes on your behalf. You can do this by first selecting APIs & auth > Credentials on the left sidebar. Under Public API access click Create a new key and then specify Server key. Do not specify any IP addresses and click Create
    You should then see your newly created key show up under Public API Access. Take note of your API key as you will give this to us so we can push on your behalf:
    2. Add your GCM API Key to your account - show me
    Once you have created a GCM API Key, please visit the settings page and scroll to the 'Push Authorization' section to set the API Key.
    3. Update your manifest for Push - Push requires several receivers, permissions and a service to function properly. The following is an example of a sample manifest file which has push enabled. You will need to pay attention to the "Modification" & "Required" areas as those are the tags you need to update/change in your own manifest. You cannot copy this example manifest and expect it to work as is with your application, it merely serves a guide to show you what areas you need to add to your own manifest. It is important that you double check your manifest because improper permission settings or missing receivers will prevent your application from obtaining a device token that Kahuna can push to.
    <?xml version="1.0" encoding="utf-8"?>
    <!-- MODIFICATION: Change package="com.kahuna.sample" to your app package name -->
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.kahuna.sample"
        android:versionCode="1"
        android:versionName="1.0" >

        <!-- Push currently only supports Android versions 2.2 and above -->
        <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="17" />

        <!-- REQUIRED: Kahuna's push requires the following permissions -->
        <!-- MODIFICATION: Replace "com.kahuna.sample" with your app package name -->
        <permission
            android:name="com.kahuna.sample.permission.C2D_MESSAGE"
            android:protectionLevel="signature" />
        <uses-permission android:name="com.kahuna.sample.permission.C2D_MESSAGE" />

        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

        <!-- App receives GCM messages. -->
        <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
        <!-- GCM requires a Google account. -->
        <uses-permission android:name="android.permission.GET_ACCOUNTS" />
        <!-- Keeps the processor from sleeping when a message is received. -->
        <uses-permission android:name="android.permission.WAKE_LOCK" />

        <!-- END of permissions required for Kahuna Push -->

        <!-- MODIFICATION: Replace "com.kahuna.sample.KASampleApplication" with your app
            package name -->

        <application
            android:name="com.kahuna.sample.KASampleApplication"
            android:allowBackup="true"
            android:label="@string/app_name" 
            android:icon="@drawable/ic_launcher"
            >
            <activity
                android:name="KASampleActivity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>

            <!-- REQUIRED: Kahuna's push requires the receivers and service -->
            <receiver android:name="com.kahuna.sdk.KahunaCoreReceiver" />
            <receiver
                android:name="com.kahuna.sdk.KahunaPushReceiver"
                android:permission="com.google.android.c2dm.permission.SEND" >
                <intent-filter>
                    <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                    <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

                    <!-- MODIFICATION: Replace "com.kahuna.sample" with your package -->
                    <category android:name="com.kahuna.sample" />
                </intent-filter>
            </receiver>

            <service android:name="com.kahuna.sdk.KahunaPushService" />
            <!-- END of Kahuna's push requirements -->

        </application>

    </manifest>
    4. Integrate SDK Calls for Push - To support Push in your application, incorporate the following line into your Main Application class and replace "YOUR_SENDER_ID" with your API project number from step 1 above.
    
    public class SampleApplication extends Application {
    
        @Override
        public void onCreate() {
            super.onCreate();
            Kahuna.getInstance().onAppCreate(this, "INSERT_APP_KEY", "YOUR_SENDER_ID");
            // Your Code Here
        }
    
    }
                
    Push is actually controlled entirely by the application and it is highly recommended that your application expose a setting to the user to enable/disable push depending on their preferences. Push is enabled by default and you can disable it with the following after calling onAppCreate().
    
    Kahuna.getInstance().disablePush();
                
    Optional Push Features
    1. Receive Broadcast when Receiving a Kahuna Push Notification - Just in case you were wondering, the Kahuna SDK can notify you if your application receives a Push notification sent from Kahuna. With Kahuna you can even pass in some extra parameters to your own application and receive them from a Broadcast. You just need to implement a Broadcast Receiver and set that class in the SDK as shown below:
    
    public class SampleReceiver extends BroadcastReceiver {
    
        private static final String LOG_TAG = "PushSample";
    
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if(Kahuna.ACTION_PUSH_CLICKED.equals(action)){
                /* Push notification was clicked. */
                Bundle extras = intent.getBundleExtra(Kahuna.EXTRA_LANDING_DICTIONARY_ID);
                if(extras != null) {
                    // Make sure to check all values in case you receive pushes
                    // without any parameters.
                    String value = extras.getString("YOUR_PARAM_KEY");
                    if(value != null) {
                        Log.i(LOG_TAG, "Received Kahuna push with your value:" + value);
                    }
                }
            }
        }
    
    }
                
    Note: You should decide what custom params (if any) your app will support and add any error handling logic in case a push you receive does not contain any extra parameters. Once you create your custom Broadcast Receiver class, you'll need to add your receiver to your manifest. Just be sure you put your own package and receiver name instead of the Kahuna sample one.
    <receiver android:name="com.kahuna.sample.SampleReceiver" />
    Finally, register your receiver in your Main Application class right after you call onAppCreate().
    
    Kahuna.getInstance().onAppCreate(this, "INSERT_APP_KEY", "YOUR_SENDER_ID");
    Kahuna.getInstance().setPushReceiver(SampleReceiver.class);
                
    2. Set custom Push Notification Icons - By default, Android Push messages will use your app's icon as both the small and large icons when showing notifications. However, you can change the notification icons with the Kahuna SDK as shown below:
    
    Kahuna.getInstance().onAppCreate(this, "INSERT_APP_KEY", "YOUR_SENDER_ID");
    Kahuna.getInstance().setPushNotificationLargeIconResourceId(R.drawable.PUSH_ICON_LARGE);
    Kahuna.getInstance().setPushNotificationSmallIconResourceId(R.drawable.PUSH_ICON_SMALL);
                
    Once these steps are completed, your team will have a robust push notification delivery system capable of targeting key groups of users.
  • Want to run campaigns based on what your users do and who they are? Set up Custom Events and Custom Attributes to make this happen!
    1. Put in some custom events with the following line:
    
    Kahuna.getInstance().trackEvent("EVENT_NAME_HERE");
                
    Then, go head and launch your app and trigger some of your custom events. We'll wait.
    Waiting for an event...
    2. Kahuna allows you to further characterize your users by specifying additional user attributes:
    
    Map<String, String> dummyAttributes = new HashMap<String, String>();
    dummyAttributes.put(KahunaUserAttributesKeys.FIRST_NAME_KEY, "John");
    dummyAttributes.put(KahunaUserAttributesKeys.LAST_NAME_KEY, "Doe");
    dummyAttributes.put(KahunaUserAttributesKeys.GENDER_KEY, "m");
    dummyAttributes.put(KahunaUserAttributesKeys.BIRTH_DAY_KEY, String.valueOf(2));
    dummyAttributes.put(KahunaUserAttributesKeys.BIRTH_MONTH_KEY, String.valueOf(1));
    dummyAttributes.put(KahunaUserAttributesKeys.BIRTH_YEAR_KEY, String.valueOf(1989));
    
    Kahuna.getInstance().setUserAttributes(dummyAttributes);
                
    Optional Features
    1. Associate a count and value to your Event - Kahuna allows you to specify additional count and value information to an Event you track, the most obvious of which is to track user purchases. For instance, if you wanted to track a user purchase of 2 items for $5.00 total, you would pass 2 for count and 500 for value. :
    
    Kahuna.getInstance().trackEvent("EVENT_NAME_HERE", 2, 500);
                
    Setting count and value to an Event is optional, but allows deeper tracking of your user behavior. For example if you wanted to track purchase information and LTV per user.