-
Notifications
You must be signed in to change notification settings - Fork 19
Home
- 1. First steps
- 2. Push
- 3. InApp
- 4. Predict
- 5. DeepLink
- 6. ApplicationCode and merchantId change
- 7. Inbox
- 8. Geofence
A Sample Application using the Emarsys SDK is available here. The Sample Application provides examples of how you can use the various features of the Emarsys SDK in a real application and what steps are needed e.g. to be able to receive push messages.
To configure the SDK, you should do the following in the onCreate
method in the application class:
Note
mobileEngageApplicationCode: is needed if you want to use Mobile Engage features
predictMerchantId: is needed if you want to use Predict features
inAppEventHandler: is needed if you want to handle user actions on the inApp messages
notificationEventHandler: is needed if you want to handle user actions on the push messages
public class SampleApplication extends Application {
private static final String TAG = "SampleApplication";
@Override
public void onCreate() {
super.onCreate();
EmarsysConfig config = new EmarsysConfig.Builder()
.application(this)
.mobileEngageApplicationCode(<applicationCode:String?>)
.contactFieldId(<contactFieldId: Integer>)
.predictMerchantId(<predictMerchantId:String?>)
.inAppEventHandler(getInAppEventHandler())
.notificationEventHandler(getNotificationEventHandler())
.build();
Emarsys.setup(config);
}
}
class SampleApplication: Application() {
override fun onCreate() {
super.onCreate()
val config = EmarsysConfig.Builder()
.application(this)
.mobileEngageApplicationCode(<applicationCode: String?>)
.contactFieldId(<contactFieldId: Integer>)
.predictMerchantId(<predictMerchantId:String?>)
.inAppEventHandler(getInAppEventHandler())
.notificationEventHandler(getNotificationEventHandler())
.build()
Emarsys.setup(config)
}
}
Most calls can receive a completionListener
as parameter, that you can use to track our calls. The CompletionListener
defines one
method:
@Override
public void onCompleted(@Nullable Throwable errorCause) {
if(errorCause != null){
Log.e(TAG, error.getMessage(), error);
}
}
After the application setup is finished, you can use setContact
method to identify the user with a contactFieldValue
. Without setContact
all events will be tracked as anonymous usage using anonymous contacts for Mobile Engage and will rely on visitor cookies in case of Predict. Please note that contactFieldValue
parameter is required, but the CompletionListener is optional.
Emarsys.setContact(String contactFieldValue, CompletionListener completionListener);
Emarsys.setContact(contactFieldValue: String, completionListener: CompletionListener? = null)
When the user signs out, we should use the clearContact
method with the CompletionListener which is optional. The method is going to automatically log in an anonymous user instead of the one leaving.
Note
No need to call
clearContact
every time, even if the user isn't logged in. Just make sure it is called when the user logs out of the application.
Emarsys.clearContact(CompletionListener completionListener);
Emarsys.clearContact(completionListener: CompletionListener? = null)
If you want to track custom events, the trackCustomEvent
method should be used, where the eventName
parameter is required, but the attributes
and the CompletionListener are optional.
Emarsys.trackCustomEvent(String eventName, Map<String,String> attributes, CompletionListener completionListener);
Emarsys.trackCustomEvent(eventName: String, attributes: Map<String, String>?, completionListener: CompletionListener? = null)
Note
The SDK sends an AppEvent action on every interaction with the push notification. (buttons click or click on the push itself)
Event name is:
push:click
, and the payload is the whole rootParameters.If the push also contains an AppEvent, then the callback will be called twice, where the first one will be the
push:clicked
.
The Emarsys SDK automatically handles setPushToken
for the device and it is recommended to leave this to the SDK. However if you have your custom implementation of MessagingService, please use the setPushToken()
method, where CompletionListener parameter is optional, to set the pushToken
.
Emarsys.getPush().setPushToken(String pushToken,CompletionListener completionListener);
Emarsys.push.setPushToken(pushToken: String, completionListener: CompletionListener? = null)
If you want to remove pushToken
for the Contact, please use clearPushToken()
method where CompletionListener parameter is optional.
Note
To use
clearPushToken
you have to disable the automatic setPushTokenHandling, usingdisableAutomaticPushTokenSending
during the setup or the SDK is going to eventually set a new push token automatically. Please consider that in this case, you have to set the push token manually, like in the MyMessagingService example.
Emarsys.getPush().removePushToken(CompletionListener completionListener);
Emarsys.push.removePushToken(completionListener: CompletionListener? = null)
The Emarsys SDK automatically handles whether the push messages have been opened, however, if you want to track it manually the trackMessageOpen
method should be used, where the intent
parameter is required but the CompletionListener is optional.
Emarsys.getPush().trackMessageOpen(Intent intent, CompletionListener completionListener);
Emarsys.push.trackMessageOpen(intent: Intent, completionListener: CompletionListener? = null)
In order to react to an event, triggered by a push notification message, you can register for it using the setNotificationEventHandler method.
Emarsys.getPush().setNotificationEventHandler(EventHandler notificationEventHandler);
Emarsys.push.notificationEventHandler(notificationEventHandler: EventHandler)
In order to react to an event triggered by the silent message, you can register for it using the setSilentMessageEventHandler
method.
The eventHandler is a callback for a silent message event.
Emarsys.getPush().setSilentMessageEventHandler(EventHandler silentMessageEventHandler);
Emarsys.push.silentMessageHandler(silentMessageEventHandler: EventHandler)
In case you need information about the received message, you can set your NotificationInformationListener
implementation as a callback to our Emarsys.push and we will call the method of the listener with a NotificationInformation object.
Emarsys.getPush().setNotificationInformationListener(NotificationInformationListener notificationInformationListener);
Emarsys.push.notificationInformationListener(notificationInformationListener: NotificationInformationListener)
In case you need information about the received message, you can set your NotificationInformationListener
implementation as a callback to our Emarsys.push and we will call the method of the listener with a NotificationInformation object.
Emarsys.getPush().setSilentNotificationInformationListener(NotificationInformationListener silentNotificationInformationListener);
Emarsys.push.silentNotificationInformationListener(silentNotificationInformationListener: NotificationInformationListener)
When a critical activity starts and should not be interrupted by InApp, use pause
to pause InApp messages.
Emarsys.getInApp().pause();
Emarsys.inApp.pause()
In order to show inApp messages after being paused, use the resume
method.
Emarsys.getInApp().resume();
Emarsys.inApp.resume()
In order to react to an event, triggered by the InApp message, you can register for it using the setEventHandler
method.
Emarsys.getInApp().setEventHandler(EventHandler() {
@Override
public void handleEvent(String eventName, @Nullable JSONObject payload) {
...
}
});
Emarsys.inApp.setEventHandler { eventName, payload -> ...}
In-App message, that takes place in the application's view hierarchy. Multiple inline In-App components are allowed in one screen.
Note
The Inline In-App feature is still in pilot phase, please only use it if you have a pilot service order in place! If you need help with piloting, please contact your Client Success Manager @ Emarsys.
There are three ways to implement the inline In-App.
- First way is from XML, this way onAppEventListener, onCompletionListener and onCloseListener cannot be set.
- Secondly is completely from code, this way it could be set up by its constructor.
- The last one is the mixed setup, for this the view could be created in XML, then the listeners should be set by code.
In order to load the inline In-App, the loadInApp
must be called with the corresponding viewId. When the view is created from XML and this value has been set, this call is unnecessary.
InlineInAppView inlineInAppView = new InlineInappView(Context context);
inlineInAppView.loadInApp(String viewId);
val inlineInAppView = InlineInAppView(context: Context)
inlineInAppView.loadInApp(viewId: String)
In order to react to an event triggered from the In-App message, register an onAppEventListener
.
The onAppEventListener
is a callback for an In-App message event.
inlineInAppView.setOnAppEventListener((<String property>, <JSONObject jsonObject>) -> {
...
});
inlineInApp.onAppEventListener = { property: String?, json: jsonObject ->
...
}
The onCompletionListener
is triggered when the inline In-App message is loaded.
inlineInAppView.setOnCompletionListener(<Throwable errorCause> -> {
...
});
inlineInApp.onCompletionListener = CompletionListener { throwable: Throwable? ->
...
}
The onCloseListener
is triggered when the close button has been clicked on the inline In-App message.
inlineInAppView.setOnCloseListener(() -> {
...
});
inlineInApp.onCloseListener = {
...
}
We won't go into the details to introduce how Predict works, and what its capabilities are, rather we aim to explain the mapping between the Predict commands and our interface. Please visit Predict's documentation for more information.
To use the Predict functionality you have to set up your merchantId
during the initialization of the SDK.
In order to track Predict events, you can use the methods available on our Predict interface.
Note
In case you don't use our Mobile Engage solution, please make sure that Firebase is set up because it is needed for device identification.
Find help for Firebase integration here.
When you want to track the cart items in the basket, you can call the trackCart
method with a list of CartItems. CartItem
is an interface
that can be used in your application for your own CartItems and then simply use the same items with the SDK.
Emarsys.getPredict().trackCart(List<CartItem> items);
Emarsys.predict.trackCart(items: List<CartItem>)
To report a purchase event, you should call trackPurchase
with the items purchased and with an orderId
.
Emarsys.getPredict().trackPurchase(String orderId, List<CartItem> items);
Emarsys.predict.trackPurchase(orderId: String, items: List<CartItem>)
If an item was viewed, use the trackItemView
method with an itemId
as a required parameter.
Emarsys.getPredict().trackItemView(String itemId);
Emarsys.predict.trackItemView(itemId: String)
When the user navigates between the categories, you should call trackCategoryView
in every navigation. Be aware to send categoryPath
in the required format. Please visit Predict's documentation for more information .
Emarsys.getPredict().trackCategoryView(String categoryPath)
Emarsys.predict.trackCategoryView(categoryPath: String)
To report search terms entered by the contact, use trackSearchTerm
method.
Emarsys.getPredict().trackSearchTerm(String searchTerm)
Emarsys.predict.trackSearchTerm(searchTerm: String)
To track custom tags, use the trackTag
method, where, the eventName
parameter is required, but the attributes
is optional.
Emarsys.getPredict().trackTag(String eventName, Map<String,String> attributes);
Emarsys.predict.trackTag(eventName: String, attributes: Map<String,String>?)
With the Emarsys SDK you can ask for product recommendations
based on different recommendation logics
.
Note
recommendProducts
is also going to track thevalue
attached to thelogic
on the backend, so no additional tracking needed when using recommendations!
This is a required parameter of the recommendProducts
method.
The currently supported logics are:
-
SEARCH
- based onsearchTerm
-
CART
- based oncartItems
-
RELATED
- based onitemViewId
-
CATEGORY
- based oncategoryPath
-
ALSO_BOUGHT
- based onitemViewId
-
POPULAR
- based oncategoryPath
-
PERSONAL
- based on current browsing and activity -
HOME
- based on most recent browsing behaviour
Note
For more information of the recommender logics, please visit [the official documentation].(https://help.emarsys.com/hc/en-us/articles/115004662189-Web-Recommender-logics "The Official Documentation")
You can pass the values to the chosen recommendation logic, but if you leave it empty, the SDK handles it and uses the last tracked values.
This is an optional parameter of the recommendProducts
method.
You can filter product recommendations
with the SDK by building RecommendationFilters
.
There are two types of filters: Exclude
or Include
.
In every case there are four types of comparators you can use to compare your chosen field to expectationValue:
-
isValue
- checking if thefield
is matching thevalue
-
inValues
- any of thevalues
has a match with thefield
-
hasValue
- One of thefield
values is equal toexpectation value
(applicable only to fields containing multiple values) -
overlapsValues
- One or more of thefield
values are found inexpectation values
(applicable only to fields containing multiple values)
For further information please check the predict documentation.
This is an optional parameter of the recommendProducts
method.
You can limit the number of recommended products
received by defining a limit.
This is an optional parameter, by default its value is 5
.
This is a required parameter of the recommendProducts
method.
The SDK is going to retrieve recommended products
via it's resultListener
RecommendationFilter filter = RecommendationFilter.exclude("category").isValue("SHIRT");
List<RecommendationFilter> filters = new ArrayList();
filters.add(filter);
Emarsys.getPredict().recommendProducts(RecommendationLogic.category(), filters, new ResultListener<Try<List<Product>>>() {
@Override
public void onResult(@NonNull Try<List<Product>> result) {
if (result.getResult() != null) {
List<Product> recommendedProducts = result.getResult();
}
if (result.getErrorCause() != null) {
Throwable cause = result.getErrorCause();
Log.e(TAG, "Error happened: " + cause.getMessage());
}
}
});
val filter = RecommendationFilter.exclude("category").isValue("SHIRT")
Emarsys.predict.recommendProducts(RecommendationLogic.category(), listOf(filter)){
it.result?.let { result ->
val recommendedProducts = result.result
}
it.errorCause?.let { cause ->
Log.e(TAG, "Error happened: ${cause.message}")
}
}
The Emarsys SDK doesn't track automatically recommendationClicks, so you have to call manually trackRecommendationClick
when an interaction happens with any of the recommended products
.
Emarsys.getPredict().trackRecommendationClick(Product clickedProduct);
Emarsys.predict.trackRecommendationClick(clickedProduct: Product)
Variants are used by the HOME
and PERSONAL
logic types. By adding a list of Strings used as suffixes to logic names, recommendations are grouped by the variants provided.
Note
Please check our DeepLink page for more information.
The Emarsys SDK automatically tracks email link clicks that open the application directly in most use cases, with only one exception: manual tracking is needed when your Activity has onNewIntent overridden. In that case, you can track the deep link using the trackDeepLink
method like below:
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Emarsys.trackDeepLink(this, intent, new CompletionListener(){
@Override
public void onCompleted(@Nullable Throwable errorCause) {
...
}
);
}
}
override fun onNewIntent(intent:Intent) {
super.onNewIntent(intent)
Emarsys.trackDeepLink(this, intent) {throwable -> ...}
}
Emarsys SDK provides a solution for applicationCode and merchantId change in a convenient way without restarting the SDK. Please check our Config page for more information.
Under Development
Please be aware that the Inbox feature is under development and therefore should not be included in any SDK integration at present. We estimate that we will be able to accept pilot clients for this feature by Q3 2020.
In order to receive the inbox content, you can use the fetchNotifications
method.
Emarsys.getInbox().fetchNotifications(new ResultListener<Try<NotificationInboxStatus>>() {
@Override
public void onResult(@NonNull
Try<NotificationInboxStatus> result) {
if (result.getResult() != null) {
NotificationInboxStatus inboxStatus = result.getResult();
Log.i(TAG, "Badge count: " + inboxStatus.badgeCount);
}
if (result.getErrorCause() != null) {
Throwable cause = result.getErrorCause();
Log.e(TAG, "Error happened: " + cause.getMessage());
}
}
});
Emarsys.inbox.fetchNotifications { result ->
result.result?.let { inboxStatus ->
Log.i(TAG, "Badge count: ${inboxStatus.badgeCount}")
}
result.errorCause?.let {
Log.e(TAG, "Error happened: ${it.message}")
}
}
When your user opened the application inbox, you might want to reset the unread count (badge). To do so, you can use the resetBadgeCount
method with an optional CompletionListener.
Emarsys.getInbox().resetBadgeCount(CompletionListener completionListener);
Emarsys.inbox.resetBadgeCount(completionListener: CompletionListener? = null)
To track the notification opens in inbox, use the following trackNotificationOpen
method, where the notification
that is being viewed is required, but the CompletionListener is optional.
Emarsys.getInbox().trackNotificationOpen(Notification notification, CompletionListener completionListener);
Emarsys.inbox.trackNotificationOpen(notification: Notification, completionListener: CompletionListener? = null)
User centric inbox solution.
In order to receive the messageInbox content, you can use the fetchMessages
method.
Emarsys.getMessageInbox().fetchMessages(result -> {
if (result.getResult() != null) {
InboxResult inboxResult = result.getResult();
Log.i(TAG, "Inbox result: " + inboxResult.toString());
}
if (result.getErrorCause() != null) {
Throwable cause = result.getErrorCause();
Log.e(TAG, "Error happened: " + cause.getMessage());
}
});
Emarsys.messageInbox.fetchMessages {
it.result?.let { notificationStatus ->
notificationStatus.messages.forEach { notification ->
Log.i(TAG, "Messages: ${notification.title}")
}
}
it.errorCause?.let { cause ->
Log.e("Error fetching messages: ${cause.message}")
}
}
To label a message with a tag, you can use addTag
method. (for example: "READ", "SEEN" etc)
Emarsys.getMessageInbox().addTag(String tag, String messageId, CompletionListener completionListener);
Emarsys.messageInbox.addTag(tag: String, message: String, completionListener: CompletionListener? = null);
To remove a label from a message, you can use removeTag
method.
Emarsys.getMessageInbox().removeTag(String tag, String messageId, CompletionListener completionListener? = null);
Emarsys.messageInbox.removeTag(tag: String, message: String, completionListener: CompletionListener);
Note
The Geofence feature is still in pilot phase, please only use it if you have a pilot service order in place! If you need help with piloting, please contact István Szabó, PM of SDK @ Emarsys.
Geofence makes it available to trigger certain actions based on the users location. When the user enters a predefined region (represented by latitude, longitude and radius) EmarsysSDK fires a customEvent which can trigger an action, for example a push notification. This requires permission for background locations from the user.
Note
Based on our experiences so far, the accuracy of geofencing is inconsistent and can be different based on device types and the environment of usage. We recommend to use at least 100m of radius, to ensure that the triggers happen. Based on the Android documentation only 100 geofences/app can be used, so please be aware that our current geofencing solution only works well when there are no other geofencing solution used by the application.
For the location permissions the applications AndroidManifest.xml must be extended with the following permissions:
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Make sure that your app is requesting the required permissions from the user.
The enable
method is responsible for the activation of this feature
Emarsys.getGeofence().enable(CompletionListener completionListener);
Emarsys.geofence.enable(completionListener: CompletionListener? = null)
The disable
method is responsible for disabling this feature
Emarsys.getGeofence().disable();
Emarsys.geofence.disable()
The isEnabled
method returns if the geofencing is currently enabled or not
Emarsys.getGeofence().isEnabled();
Emarsys.geofence.isEnabled()
In order to react to an event triggered by a geofence, you can register for it using the setEventHandler
method.
The eventHandler is a callback for a Geofence event.
Emarsys.getGeofence().setGeofenceEventHandler(EventHandler geofenceEventHandler);
Emarsys.geofence.geofenceEventHandler(geofenceEventHandler: EventHandler)