Reference Source
import WLAnalytics from 'react-native-ibm-mobilefirst'
public class | source

WLAnalytics

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 }

Method Summary

Public Methods
public

Enable analytics to capture the specified DeviceEvent

public

Disable persistent capture of analytics data.

public

enable()

Enable persistent capture of analytics data.

public

log(message: string, metadata: Object)

Log data you want to be captured in the context of "analytics".

public

Disable analytics from capturing the specified DeviceEvent

public

send()

Send the accumulated log data when the persistent log buffer exists and is not empty.

public

Send the accumulated log data when the persistent log buffer exists and is not empty.

public

Specify current application user.

public

Unset any user context previously set.

Public Methods

public addDeviceEventListener(deviceEvent: string) source

Enable analytics to capture the specified DeviceEvent

Params:

NameTypeAttributeDescription
deviceEvent string

A string representation of the device event to capture. Valid values are "LIFECYCLE" and "NETWORK"

public disable() source

Disable persistent capture of analytics data.

public enable() source

Enable persistent capture of analytics data. Enable, and thus capture, is the default.

public log(message: string, metadata: Object) source

Log data you want to be captured in the context of "analytics". Some data is already captured by the framework. To avoid collisions, the following keys will be excluded if logged: appStoreID appStoreLabel appStoreVersion appStoreVersionDisplay mfpAppName mfpAppVersion deviceBrand deviceOSversion deviceOS deviceModel deviceID timezone timestamp

Params:

NameTypeAttributeDescription
message string

The message to be logged

metadata Object

Any additional metadata to be added to the log message.

public removeDeviceEventListener(deviceEvent: string) source

Disable analytics from capturing the specified DeviceEvent

Params:

NameTypeAttributeDescription
deviceEvent string

A string representation of the device event to capture. Valid values are "LIFECYCLE" and "NETWORK"

public send() source

Send the accumulated log data when the persistent log buffer exists and is not empty.

public async sendWithCallback(): Promise source

Send the accumulated log data when the persistent log buffer exists and is not empty.

Return:

Promise

public setUserContext(user: string) source

Specify current application user. If you want user-based analytics, you must use this method call. For example, use it when the user logs in, and call the unsetUserContext method when the user logs out. Or if your application supports user profiles, call this method when the user profile changes.

Params:

NameTypeAttributeDescription
user string

User ID for the current app user.

public unsetUserContext() source

Unset any user context previously set.