Introduction
Welcome on the Omnisense Android SDK Documentation. You can use these to retrieve and add informations on your Omnisense instance.
Current SDK Version : 2.0.6
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
Installation
Project level build.gradle
// (top-level) build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:7.0.0'
classpath 'com.google.gms:google-services:4.3.9'
}
App level build.gradle
// (app-level) build.gradle
dependencies {
...
implementation 'io.omnisense:omnisense:2.0.6'
...
}
// 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.
<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="com.google.firebase.messaging.default_notification_channel_id"
android:value="default" />
<service android:name="io.omnisense.services.OmnisenseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</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
class App : Application() {
...
override fun 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
class BaseActivity : Activity() {
override fun onStart() {
super.onStart()
Omnisense.getInstance().onStart(this)
}
override fun 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
class AnyActivity : 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
val 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 |
---|---|---|
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
val segment = 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
class App : Application() {
...
override fun onCreate() {
super.onCreate()
Omnisense.createInstance(this)
Omnisense.getInstance().getNotificationConfig().setAutoCancel(true)
Omnisense.getInstance().notificationConfig.pushListener = object : PushReceptionListener {
override fun onPushReceived(extras: JSONObject) {
/*
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);
val 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.
*/
val 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
*/
val action1 = JSONObject()
val action2 = JSONObject()
//
action1.put("l", resources.getString(R.string.notification_action_1_label))
action1.put("u", url+"&action=do_something")
action2.put("l", resources.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().notificationConfig.action1Icon = R.drawable.action1_icon
Omnisense.getInstance().notificationConfig.action1Icon = R.drawable.action2_icon
}
override fun 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
class App : Application() {
...
override fun 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().setTrackingListener(object : OnOmnisenseFingerprintListener {
override fun onOmnisenseFingerprintCompleted(map: Map<String, String>) {
// 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.