public class WLAnalytics
extends java.lang.Object
WLAnalytics means of persistently capturing analytics data and provides a method call to send captured data to the IBM MobileFirst Platform server, to be forwarded to the Operational Analytics engine.
Capture is on by default.
When this WLAnalytics class's capture flag is turned on via enable method call, all messages passed through this class's log method will be persisted to file in the following JSON object format:
{ "timestamp" : "17-02-2013 13:54:27:123", // "dd-MM-yyyy hh:mm:ss:S" "level" : "ERROR", // ERROR || WARN || INFO || LOG || DEBUG "package" : "your_tag", // typically a class name, app name, or JavaScript object name "msg" : "the message", // a helpful log message "metadata" : {"hi": "world"}, // (optional) additional JSON metadata, appended via doLog API call "threadid" : long // (optional) id of the current thread }
Log data is accumulated persistently to a log file until the file size is greater than FILE_SIZE_LOG_THRESHOLD. At this point the log file is rolled over. Log data will only be captured once com.worklight.common.WLAnalytics.setContext(Context) is called. Once both files are full, the oldest log data is pushed out to make room for new log data.
Log file data is sent to the IBM MobileFirst Platform server when this class's send() method is called and the accumulated log size is greater than zero. When the log data is successfully uploaded, the persisted local log data is deleted.
Modifier and Type | Class and Description |
---|---|
static class |
WLAnalytics.DeviceEvent
Set of device attribute changes WLAnalytics can register event listeners for.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
SHARED_PREF_KEY |
static java.lang.String |
SHARED_PREF_KEY_USER_ID |
static java.lang.Object |
WAIT_LOCK |
Constructor and Description |
---|
WLAnalytics() |
Modifier and Type | Method and Description |
---|---|
static void |
addDeviceEventListener(WLAnalytics.DeviceEvent deviceEvent)
Enable analytics to capture the specified DeviceEvent
|
static void |
disable()
Disable persistent capture of analytics data.
|
static void |
enable()
Enable persistent capture of analytics data.
|
static void |
init(Application app)
Initialize WLAnalytics API.
|
static void |
log(java.lang.String message,
JSONObject additionalMetadata)
Log data you want to be captured in the context of "analytics".
|
static void |
log(java.lang.String message,
JSONObject additionalMetadata,
java.lang.Throwable t)
Log exceptions you want to be captured in the context of "analytics".
|
static void |
logAppBackground()
Manually record the application successfully exiting from the user (entering the background) - used
to recored app session analytics.
|
static void |
logAppCrash(java.lang.Throwable t)
Manually record the application crashing - used to record app session analytics.
|
static void |
logAppForeground()
Manually record the application entering the foreground - used to record app session analytics.
|
static void |
removeDeviceEventListener(WLAnalytics.DeviceEvent deviceEvent)
Disable analytics from capturing the specified DeviceEvent
|
static void |
send()
Send the accumulated log data when the persistent log buffer exists and is not empty.
|
static void |
send(WLRequestListener listener)
See
send() |
static void |
setContext(Context context)
Deprecated.
use WLAnalytics.init() instead
Context object must be set in order to use the WLAnalytics API. This is called automatically by WL.init.
|
static void |
setUserContext(java.lang.String _user)
Specify current application user.
|
static void |
triggerFeedbackMode()
Method Triggers Inapp Feedback mode
Triggers In app Feedback Mode and enabled the user to send the feedback to Bluemix Analytic console.
|
static void |
unsetUserContext()
Unset any user context previously set.
|
public static final java.lang.String SHARED_PREF_KEY
public static final java.lang.String SHARED_PREF_KEY_USER_ID
public static final java.lang.Object WAIT_LOCK
public static void init(Application app)
app
- Android Application to instrument with WLAnalytics.public static void addDeviceEventListener(WLAnalytics.DeviceEvent deviceEvent)
deviceEvent
- the DeviceEvent to capturepublic static void removeDeviceEventListener(WLAnalytics.DeviceEvent deviceEvent)
deviceEvent
- the DeviceEvent to disablepublic static void triggerFeedbackMode()
public static void setContext(Context context)
context
- Android Context objectpublic static void setUserContext(java.lang.String _user)
_user
- User User id for current app user.public static void unsetUserContext()
public static void enable()
public static void disable()
public static void log(java.lang.String message, JSONObject additionalMetadata)
message
- Message to be logged.additionalMetadata
- Meta-data associated with log message.public static void log(java.lang.String message, JSONObject additionalMetadata, java.lang.Throwable t)
message
- Message to be logged.additionalMetadata
- Meta-data associated with log message.t
- a Throwable whose stack trace is converted to string and loggedpublic static void send()
WLAnalytics
with capture
(see enable()
) turned on.public static void send(WLRequestListener listener)
send()
listener
- WLRequestListener which specifies an onSuccess callback and an onFailure callback (see WLRequestListener
)public static void logAppForeground()
public static void logAppBackground()
public static void logAppCrash(java.lang.Throwable t)