General Purpose Events - RumbleInc/Rumble-Android-SDK-Getting-Started GitHub Wiki

In this section you can find a small and simple set of API's for logging any form of analytic events into the various analytics providers supported by the Rumble platform.

###Open Session

AnalyticsService.sendOpenSession();

Invokes session opening in the different analytics providers that supports explicit sessions. (Some providers have their own rules of defining sessions and don't support external invocations for it)

Note: RumbleAnalytics provider generates a GUID on each openSession invocation and attache it to every event sent to the server from now on, until close session is called.

###Close Session - Optional

AnalyticsService.sendCloseSession();

The reason this method is optional is due to the fact that there is a default interval of inactivity where the SDK conclude that the session was expired. This interval can be changed on AnalyticsService.Integrate() invocation. However user can still call this method explicitly in order to define own rules of session expiry.

###Send Event

AnalyticsService.sendEvent(AnalyticTrackingEvent event)

You can use on of 2 optional methods for creating an AnalyticTrackingEvent object. Please note that AnalyticTrackingEvent is a mandatory parameter when using addEvent() method

Manual
        HashMap<String, String> attributesMap = new HashMap<>();
        attributesMap.put("Attr1", "Value1"); //put any name:value pair
        attributesMap.put("Attr2", "Value2");
        AnalyticTrackingEvent event = new AnalyticTrackingEvent("MyEventName", attributesMap);
        AnalyticsService.sendEvent(event); 
Manual using Builder pattern (Fluent object creation)
        AnalyticTrackingEvent event = new AnalyticTrackingEvent.Builder().
                name("MyEvent").
                attribute("Attr1", "Value1").
                attribute("Attr2", "Value2").
                build();
        AnalyticsService.sendEvent(event);
Json deserialization - (Snippet is using the 'Jackson' library)
        ObjectMapper mapper = new ObjectMapper();

        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        AnalyticTrackingEvent event = null;
        try {
            event = mapper.readValue("<REPLACE WITH JSON FORMATTED REPRESENTATION OF AnalyticTrackingEvent >", AnalyticTrackingEvent.class);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (event == null || StringUtils.isBlank(event.Name)) {
           throw new Exception("json format is invalid")
        }
        AnalyticsService.sendEvent(event);

Example of valid Json format representation of AnalyticTrackingEvent class

{
  "Attributes" : {
    "Attr1" : "Value1",
    "Attr2" : "Value2"
  },
  "Name" : "MyEventName"
}  

###Opt-Out

AnalyticsService.setOptOut(boolean optout)

Setting opt-out flag to true will stop instantly any analytics event reporting for the current device. Default opt-in behaviour for the whole title, can be defined via Rumble dashboard.