Omnisense Android SDK

Import SDK in your project

Before installing Omnisense, you should follow this link which explain how to integrate GCM inside your app : https://developers.google.com/cloud-messaging/android/client?configured=true

Note : You must provide a google-services.json config file.

Open your project. Click on File > New > New Module. Select "Import .JAR/.AAR package". Select the provided omnisense.aar package.

Add the following: In settings.gradle

include ':app', ':omnisense' //Append :omnisense to the list of included modules

In the main (top-level) build.gradle

dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'
        classpath 'com.google.gms:google-services:3.0.0'
    }

In app's build.gradle


dependencies {
...
compile project(':omnisense')
...
}


//Add at the bottom of the file
apply plugin: 'com.google.gms.google-services'

In AndroidManifest.xml (Replace "yourpackage" by your app's package) Replace omnisense_api_key and omnisense_app_identifier values according to your credentials. The omnisense_app_identifier is the beginning of your Omnisense instance URL. Example: If instance's URL is "myinstance.app.omnisense.io" then myinstance is your identifier.

<permission
        android:name="yourpackage.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
<uses-permission android:name="yourpackage.permission.C2D_MESSAGE" />

<application ...>
   <meta-data android:name="omnisense_api_key" android:value="your_api_key" />
   <meta-data android:name="gcm_sender_id" android:value="@string/gcm_defaultSenderId" />
   <meta-data android:name="omnisense_app_identifier" android:value="your_app_identifier" />

   <receiver
    android:name="com.google.android.gms.gcm.GcmReceiver"
    android:exported="true"
    android:permission="com.google.android.c2dm.permission.SEND">
    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />

        <category android:name="yourpackage" />
    </intent-filter>
   </receiver>

   <service
    android:name="io.omnisense.OmnisenseIntentService"
    android:exported="false">
    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
    </intent-filter>
   </service>
</application>

In the onCreate function of your class extending "Application"

   Omnisense.createInstance(this);
   Omnisense.getInstance().getNotificationConfig().setAutoCancel(true);
   Omnisense.getInstance().getNotificationConfig().setPushListener(new PushReceptionListener() {
      @Override
      public void onPushReceived(JSONObject extras) {
         /*
         This is a basic config. The extras object contains the params sent by Omnisense.
         If the extras already contains "u" param, then a deep linking is already present in the extras. Otherwise, you can create your own deep linking according to the provided param then add it to the "u" param. */
         Omnisense.getInstance().getNotificationConfig().setIcon(R.drawable.bike_white);
         Omnisense.getInstance().getNotificationConfig().setClickActivityClass(MainActivity.class);
      }

      @Override
      public void onNotificationDisplayed() {

      }
   });

   Omnisense.getInstance().initialize(); //Must be called before anything else

In each activity, you have to add this :

@Override
public void onStart()
{
   super.onStart();
   Omnisense.getInstance().onStart(this);
}

@Override
public void onStop()
{
   super.onStop();
   Omnisense.getInstance().onStop(this);
}

User data recording

User profile management

To identify the user on Omnisense (after login or sign up), simply update the fields on the OmnisenseUser provided by the instance :

OmnisenseUser user = Omnisense.getInstance().getCurrentUser();
user.email = "john.doe@gmail.com";
user.fb_id = "12143534535646";
user.firstName = "John";
user.lastName = "Doe";
Omnisense.getInstance().saveUser();

To identify a user on Omnisense, an email OR the Facebook ID must at least be set. If not, other attributes won't be sync with Omnisense.

If you want to add or update some of the user attributes, you can get the current user with the method getCurrentUser and change the values. You will have to call the saveUser after settings the values in order to save them to Omnisense.

After a "log out", simply call the resetCurrentUser to remove the current user.

User custom events recording

To record an event made by the user in the app, call the record event method with segmentation.

Segment segment = new Segment();
segment.put("product_name", "The best product ever");
segment.put("category", "New stuff");
Omnisense.getInstance().recordEvent("product_view", segment);

The segmentation is a hash of event parameters that only contains string values.

Conversion data

In case you want to use Omnisense conversion data at first launch in your app, you can use the following method before "initialize" method.

    Omnisense.getInstance().setTrackingListener(new OnOmnisenseFingerprintListener() {
        @Override
        public void onOmnisenseFingerprintCompleted(Map<String, String> map) {
        }
    };

Facebook app installs

To track Facebook app install, set a specific Omnisense link into the deferred app link parameter of your Facebook campaign. Use method handleFacebookDeferredAppLink to handle the Facebook deferred app link with Omnisense.

AppLinkData.fetchDeferredAppLinkData(this,
    new AppLinkData.CompletionHandler() {
        @Override
        public void onDeferredAppLinkDataFetched(AppLinkData appLinkData) {
            if(appLinkData!=null) {
                Omnisense.getInstance().handleFacebookDeferredAppLink(appLinkData.getTargetUri());
            }
        }
    }
);

License

Copyright (c) 2016 I See U. All rights reserved.