Analytics
public class Analytics
Records analytics data and sends it to the Mobile Analytics service.
To subscribe to automated analytics recording, pass the DeviceEvent options that you want recorded in initialize(appName:apiKey:hasUserContext:deviceEvents:).
Custom events can be recorded with log(metadata:). You can also define the current application user with userIdentity using, for example, the user’s login information.
When you are ready to send all of the recorded data to the Mobile Analytics service, use send(completionHandler:).
-
Determines whether analytics data will be recorded.
Declaration
Swift
public static var isEnabled: Bool -
Identifies the current application user. To reset the
userIdentity, set the value to nil.Declaration
Swift
public static var userIdentity: String? { get set }
-
Record analytics data.
Analytics logs are added to the log file until the file size is greater than
Logger.maxLogStoreSize. At this point, the first half of the stored logs will be deleted to make room for new log data.When ready, use
send(completionHandler:)to send the recorded data to the Mobile Analytics service.Note
Do not supply values for the
file,function, orlineparameters. These parameters take default values to automatically record the file, function, and line in which this method was called.Declaration
Swift
public static func log(metadata: [String : Any], file: String = #file, function: String = #function, line: Int = #line)Parameters
metadataThe analytics data
-
The required initializer for the
Analyticsclass when communicating with a Mobile Analytics service.Here you can choose what data you want to have monitored by
Analytics, including user identities, user location, app lifecycle events, and network requests.Note
This method must be called after initializing
BMSClientwithBMSClient.sharedInstance.initialize(bluemixRegion:)from theBMSCoreframework, and before callingsend(completionHandler:)orLogger.send(completionHandler:).Declaration
Swift
public static func initialize(appName: String?, apiKey: String?, hasUserContext: Bool = false, collectLocation: Bool = false, deviceEvents: DeviceEvent...)Parameters
appNameThe application name. Should be consistent across platforms (i.e. Android and iOS).
apiKeyA unique ID used to authenticate with the Mobile Analytics service.
hasUserContextIf
false, user identities will be automatically recorded using the device on which the app is installed. If you want to define user identities yourself usingAnalytics.userIdentity, set this parameter totrue.collectLocationDetermines whether Analytics should automatically monitor the user’s current location. Before location can be retrieved, you must first request permission from the user with
CLLocationManagerrequestWhenInUseAuthorization().deviceEventsDevice events that will be recorded automatically by the
Analyticsclass. -
Log the user’s current location once.
Important
Before calling this method, make sure that you have requested permission to use location services from the user (usingCLLocationManagerrequestWhenInUseAuthorization()), and set thecollectLocationparameter totruein theAnalytics.initialize(appName:apiKey:hasUserContext:collectLocation:deviceEvents:)method.Declaration
Swift
public static func logLocation() -
Send the accumulated analytics logs to the Mobile Analytics service.
Analytics logs can only be sent if the BMSClient was initialized with
BMSClient.sharedInstance.initialize(bluemixRegion:)from theBMSCoreframework.Declaration
Swift
public static func send(completionHandler userCallback: BMSCompletionHandler? = nil)Parameters
completionHandlerOptional callback containing the results of the send request.
-
Trigger feedback Mode
Note: Feedback Mode can only be triggered if the BMSClient was initialized with
BMSClient.sharedInstance.initialize(bluemixRegion:)from theBMSCoreframework.Declaration
Swift
public static func triggerFeedbackMode()
View on GitHub
Analytics Class Reference