You can use track notification click events and session tracking events so you can collect statistical data about your application usage.

The Android event service attempts to send all events every 20 minutes in the background if there is data to send.

Simple notification click events track the user actions, and can be one of the following notifications:

  • URL clicked (urlClicked)
  • App opened from notification (appOpened)
  • Dial action clicked (phoneNumberClicked)

Session tracking events track the user session and send the following events:

  • Session start event (sessionStarted), which is sent when the application is sent to the foreground and there is no current session or the current session timed out.
  • Session end event (sessionEnded), which is sent when the application is sent to the foreground and the current session timed out. A session end event contains an attribute for the session length.

Session events can be enabled or disabled, and the session timeout duration is configurable. A notification click event is sent when a notification action is clicked. The notification click event contains the push type, action name, and attribution attributes.

The default state of a session is enabled. If sessions are enabled, the first time the application is sent to the foreground, a new session is created. If the application has been in the background for more than the defined session length, which is 20 minutes, when the application is sent back to the foreground, the previous session ends and a new session is created. If you want to make the session end (send a session end event) without getting the application to the foreground, the session tracking service needs to be added to AndroidManifest.xml.

<service android:name="com.ibm.mce.sdk.alarm.SessiontrackingIntentService" />

The service checks every 30 seconds if the application is in the background for more than the session duration. If it is, the service ends the session. When the application is sent back to the foreground, a new session is created. Managing session can be done either by using the mce.properties file by using “session.tracking” = true for enabling session or false for disabling sessions and by using “session.duration” = to set the session duration.

Sessions can also be managed in AndroidManifest.xml by using application metadata.

<meta-data
         android:name="mceSessionEnabled"
         android:value="<true for enabled or false for disabled>" />
       <meta-data
         android:name="mceSessionDuration"
         android:value="<session duration in minutes>" />

By using AndroidManifest.xml, you can control which activities participate in the session. If sessions are disabled for an activity, even if that activity is in the foreground, the session manager ignores it and considers the application as being in the background. Disabling sessions for an activity is done by using a metadata in the activity element.

<meta-data
         android:name="mceSessionEnabled"
         android:value="<true for enabled or false for disabled/>" />

Performing events operations is done using the an events client that can be accessed from the MceSdk class. You can use the ‘Queued Client’ for this purpose. Queued Client sends the operation to a queue and it is processed asynchronously with retry logic for when the device is offline or encounters a problem communicating with the APIs.

Here is an example of how to use the queued client.

import java.util.Date;
import com.ibm.mce.sdk.api.events.CustomEvent;
import com.ibm.mce.sdk.api.events.Event;

Event event = new Event(Constants.Notifications. SIMPLE_NOTIFICATION_EVENT_TYPE,  "appOpened",  new Date(), attributes,  "sampleAttribution");
MceSdk.getQueuedEventsClient().sendEvent(getApplicationContext(), event);

Creating events

SDK events are broadcast with the action name "com.ibm.mce.sdk.NOTIFIER". The following events are sent: SDK registration, GCM registration, GCM error, GCM message received, notification action clicked, session started, session ended, and illegal GCM message received.

In order to handle events, you must perform the following tasks.

1. Create a broadcast receiver that handles the events. This can be done in one of the following ways:

a.Implement MceBroadcastReceiver:

import com.ibm.mce.sdk.api.MceBroadcastReceiver;
 
public class MceNotifier extends MceBroadcastReceiver {
 
  ...
     
  ...
 }

b. Implement a broadcast receiver and use EventBroadcastUtil to handle the events.

import com.ibm.mce.sdk.api.broadcast.EventBroadcastUtil;
import com.ibm.mce.sdk.api.broadcast.EventBroadcastHandler;

 

 
 
public class MceNotifier extends BroadcastReceiver implements EventBroadcastHandler {
 
  ...
  
  @Override
  public void onReceive(Context context, Intent intent) {
    RichNotificationManger.processNotifExtras(context, msgExtras);
    EventBroadcastUtil.handleBroadcast(context, intent, this);
    
  }
  
 ...
 
 }

2. In either scenario, you must implement the following methods:

@Override
  public void onSdkRegistered(Context context) {
    // handle sdk registration event here
  }

 

 
@Override
  public void onDeliveryChannelRegistered(Context context) {
    // handle GCM registration event here
  }

 
@Override
  public void onMessage(Context context, NotificationDetails notificationDetails, Bundle msgExtras) {
    // handle GCM message event here
  }

 
@Override
  public void onC2dmError(Context context, String gerrorId) {
    // handle GCM error event here
  }

 
@Override
  public void onSessionStart(Context context, Date sessionStartDate) {
    // handle session start event here
  }

 
@Override
  public void onSessionEnd(Context context, Date sessionEndDate, long sessionDurationInMinutes) {
    // handle session end event here
  }

 
@Override
  public void onAttributesOperation(Context context , AttributesOperation, attributesOperation ) {
    // handle attributes operation event here
  }


@Override
  public void onEventsSend(Context context , List events ) {
    // handle event sending event here


@Override
  public void onNotificationAction(Context context, Date actionTime, String pushType, String actionType, String actionValue) {
    // handle notification action click event here
  }

 
@Override
  public void onIllegalNotification(Context context, Intent intent) {
    // handle illegal GCM message event here
  }

 
@Override
  public void onNonMceBroadcast(Context context, Intent intent) {
    // handle a broadcast that did not come from mce sdk here
  }
  
 

3. Add the following to the application node in your manifest:

<receiver android:name=".MceNotifier">
<intent-filter>
  <action android:name="com.ibm.mce.sdk.NOTIFIER" />
</intent-filter>
</receiver>

Go Back to the Mobile App Messaging home page.

Join The Discussion

Your email address will not be published. Required fields are marked *