NAV Navbar
java
  • Introduction
  • Getting started
  • Installation
  • Initialization
  • User data recording
  • Push notifications
  • Conversion data
  • Introduction

    Welcome on the Omnisense Android SDK Documentation. You can use these to retrieve and add informations on your Omnisense instance.

    Current SDK Version : 1.2.0

    Omnisense is an omnicanal CRM.

    With Omnisense, you can manage the entire lifecycle of your users : Acquisition, Segmentation, Reengagement.

    Acquisition : Omnisense is connected to the main advertising companies of the market and will allow you to manage your acquisition easily.

    Segmentation : Retrieve all your user data within a clear and intuitive interface and segment them in a few clicks.

    Reengagement : Push, mails, sms ... You can reengage your users with all possible and unimaginable means...

    Getting started

    Before installing Omnisense, you should follow one of these links which explain how to integrate FCM or GCM inside your app : Firebase Cloud Messaging or Google Cloud Messaging

    Adding Omnisense to your project

    Installation

    settings.gradle

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

    Project level build.gradle

      // (top-level) build.gradle
      dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'
        classpath 'com.google.gms:google-services:3.0.0'
      }
    

    App level build.gradle

      // (app-level) 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_instance values according to your credentials.

    The omnisense_instance is the beginning of your Omnisense instance URL. Example: If instance's URL is "myinstance.app.omnisense.io" then omnisense_instance = myinstance.

      <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="omnisense_instance" android:value="YOUR_INSTANCE" />
         <meta-data android:name="gcm_sender_id" android:value="@string/gcm_defaultSenderId" />
    
         <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>
    

    Updating your project to include Omnisense is easy but requires you to put some modifications in your settings.gradle, build.gradle at the project level and your build gradle at the app level. You'll find more informations to follow in the right part of your screen.

    Initialization

    Application

    Minimal initialization

    public class App extends Application {
      ...
    
      public void onCreate() {
        super.onCreate();
    
        //Must be called before anything else
    
        Omnisense.createInstance(this);
        Omnisense.getInstance().initialize();
      }
    
      ...
    
    }
    

    The Omnisense SDK is now successfully included in your project.

    Now you must create an App class extending Application at the root of your app.

    Activities

    BaseActivity

    public class BaseActivity extends AppCompatActivity {
    
      @Override
      public void onStart()
      {
        super.onStart();
        Omnisense.getInstance().onStart(this);
      }
    
      @Override
      public void onStop()
      {
        super.onStop();
        Omnisense.getInstance().onStop(this);
      }
    
    }
    

    Then in every Activities you just need to extends BaseActivity and everything will be set using the hierarchy

    public class AnyActivity extends BaseActivity {
    
      ...
    
    }
    

    The next point is to add the Omnisense SDK in every activities you need or want. This part is very easy and requires a bit of code.

    We recommand you to create a BaseActivity class extending AppCompatActivity. That will make you win a lot of time with a very little amount of code.

    User data recording

    User profile management

      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 the user on Omnisense (after login or sign up), simply update the fields on the OmnisenseUser provided by the instance.

    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.

    Available fields

    Field Value Description
    email String
    fb_id String
    firstName String
    lastName String
    birthday Date
    phone String
    address String
    city String
    postal_code String
    country String must be the iso code for country (ISO 3166)
    lang String must be the iso code for lang (ISO 639)
    sex String One of "male", "female"
    optin Boolean Set to true if the user is optin to receive email

    You can add custom fields with the setMetadata method, if needed.

    Event recording

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

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

    Method Informations

    Function name: recordEvent(identifier: String, segments: Hash)

    Method Parameters

    Parameter Value Description
    identifier String The action name
    segments Hash Set of key/values describing the event ()

    Push notifications

    public class App extends Application {
      ...
    
      public void onCreate() {
        super.onCreate();
    
        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.notification_icon);
            Omnisense.getInstance().getNotificationConfig().setClickActivityClass(MainActivity.class);
    
            String url =  extras.getString("u"); //or extras.getString("open_url") or whatever param sent with an url
    
            /*
              NB : If the param containing the URL scheme is not "u", you must add it, otherwise it won't work.
            */
            extras.put("u", url);
    
    
            /*
            You can also download a picture to display inside the notification.
            To do so, you have to provide a key called "i" and set the URL of the picture.
            */
    
            String image = "https://my.website.com/res/somepicture.jpg";
            extras.put("i", image);
    
            /*
            You can also display actions.
            Actions must be added on the "extras" json with "a1" and "a2" keys,
            each containing "l" and "u" param.
            l = Label of the button
            u = URL which will be passed to the intent
            */
            JSONObject action1 = new JSONObject();
            JSONObject action2 = new JSONObject();
    
            //
            action1.put("l", getResources().getString(R.string.notification_action_1_label));
            action1.put("u", url+"&action=do_something");
    
            action2.put("l", getResources().getString(R.string.notification_action_2_label));
            action2.put("u", url+"&action=do_something_different");
    
            extras.put("a1", action1);
            extras.put("a2", action2);
    
            //Set the action icons
            Omnisense.getInstance().getNotificationConfig().setAction1Icon(R.drawable.action1_icon);
            Omnisense.getInstance().getNotificationConfig().setAction2Icon(R.drawable.action2_icon);
          }
    
          @Override
          public void onNotificationDisplayed() {
    
          }
        });
    
        Omnisense.getInstance().initialize(); //Must be called before anything else
      }
    
      ...
    
    }
    

    You can customize received push notifications by setting an icon or the activity which should be opened on click.

    The customization has to be done when receiving the push.

    You can add a picture, change icon, or add action(s) to your notification.

    The implementation of your URL scheme is up to you. You have to handle it on the receiving activity (set with setClickActivityClass).

    You can refer on the right part to a

    Conversion data

    public class App extends Application {
      ...
    
      public void onCreate() {
        super.onCreate();
    
        Omnisense.createInstance(this);
    
        Omnisense.getInstance().setTrackingListener(new OnOmnisenseFingerprintListener() {
          @Override
          public void onOmnisenseFingerprintCompleted(Map<String, String> map) {
            // do whatever you want with the returned info
          }
        };
    
        Omnisense.getInstance().initialize();
      }
    
      ...
    
    }
    

    In case you want to use Omnisense conversion data at first launch in your app, you can use the following method before initialize() method in your App.java file.