Event Data Enrichment - Android

The modules in the Oracle CX Mobile SDK can help you capture user behavior data in the form of events. Events captured by a module can be enriched by adding additional data points to further refine the context around which the event occurred. The Core module acts like a central module that other modules in the Oracle CX Mobile SDK can subscribe and observe. Whenever the Core module receives an event that is subscribed by the other modules, all the subscribing modules are notified. The modules that subscribed for events from the Core module are called observing modules or Observers.

The Core module includes the ability of acting as an Observable that publishes events as and when they are generated/received. Observers subscribe to Observable and get notified when an event is generated/received. Every event generated by the modules in the SDK has its Group name. This Group name plays vital role while subscribing.

The Core module provides an interface called IORAEventListener that gives an ability to subscribe for events. These Observers override the onEventFound() method where the add or update or deleting of data will be carried out.

Implementing Process Communication Queues

The Core module provides ORABaseDataCollector.addEventListener() method which registers the Observer on the Observable. Before registering, we have to know the Priority and Time Delay parameters. The Priority parameter is a positive integer that ranges from 1 to 16, where 1 is the highest priority and 16 is the lowest priority. Any value passed that is out of range, is considered as least priority. The Time Delay parameter is measured is in milliseconds. This is the waiting time for getting response from the Observer.

Register or Add Observers

  • Add event listeners aka Observers by invoking the 'addEventListener' method. This method is available in the 'ORABaseDataCollector' class.

ORABaseDataCollector dataCollector = ORABaseDataCollector.getInstance();
dataCollector.addEventListener(IORAEventListener listener, String moduleId, String listenerName, ArrayList<String> groups, int priority);
  • In the above snippet, the 'IORAEventListener' is an interface. The interface has a public method 'ORAEventMap onEventFound(ORAEventMap object)' that must be overridden. This method accepts one parameter 'ORAEventMap' which is a generated event and returns updated event object.

The following is a sample implementation:

new IORAEventListener() {
@Override
public ORAEventMap onEventFound(ORAEventMap object) {
object.put("custom", "my_custom_data");
object.put("wt.sdk_v", "2.0");
return object;
}
}

Requirements for adding an event listener.

  • A unique identifier for the module.

  • For every listener we register, we must provide a unique name as an identifier. The identifier is important for registering or de-registering an observer. The name string must be passed in the addEventListener() method.

Note: Listener name must be alpha numeric only.

  • Every event that is captured belongs to some category. This category is called as 'Group'. While subscribing to an observable, we register to listen all the events which are belong to a group. So we need to pass valid group name as parameter in addEventListener() method. The valid group names for the events captured by the Core module are listed in 'ORAEventGroup' class.

An observer can register to listen events from multiple groups, by sending array of group names in the method argument.

Sample code snippet with Group name

Subscribing to a single group

ArrayList<String> groupArray = new ArrayList<>();
groupArray.add(ORAEventGroup.ORA_EG_INTERACTION);

Subscribing to multiple groups

ArrayList<String> groupArray = new ArrayList<>();
groupArray.add(ORAEventGroup.ORA_EG_INTERACTION);
groupArray.add(ORAEventGroup.ORA_EG_SCREEN);
groupArray.add(ORAEventGroup.ORA_EG_CUSTOM);

Subscribing to all events

ArrayList<String> groupArray = new ArrayList<>();
groupArray.add(ORAEventGroup.ORA_EG_TYPE_ALL);

The following code snippet details the implementation:

ORABaseDataCollector dataCollector =
ORABaseDataCollector.getInstance();
ArrayList<String> groupArray = new ArrayList<>();
groupArray.add(ORAEventGroup.ORA_EG_TYPE_ALL);
dataCollector.addEventListener(new IORAEventListener() {
@Override
public ORAEventMap onEventFound(ORAEventMap object) {
object.put("custom", "my_name");
object.put("wt.sdk_v", "2.0");
return object;
}
}, "CoreTestModuleId", "CoreTestListener", groupArray, 3);

Remove or De-register observers

To de-register observers, we need to invoke 'removeEventListener( String moduleId, String listenerName)' method on 'ORABaseDataCollector' object. The following code snippet demonstrates the same:

ORABaseDataCollector dataCollector = ORABaseDataCollector.getInstance();
dataCollector.removeEventListener("CoreTestModuleId", "CoreTestListener");

In above code, we have passed the name of the listener as an argument. Here the listener name represents the identifier which we sent in dataCollector.addEventListener() method above.