OCAnalyticsManager_iOS
#OCAnalyticsManager Module
The OCAnalyticsManager is a wrapper over a third party analytics library which can be used to track events in the host app.
##Features
- Can be initialized in simple step
- Events can be created and tracked robustly.
- No need to worry about the underlying analytics library.
##Installation
Add the module's source files to your Xcode project.
##Usage
- To initialize the analytics module use this in the app launch event
OCAnalyticsManager.shared.initialize(logType: .debug,
lifeCycleContext: [:],
appID: "com.analytics.example",
application: UIApplication.shared)
- Follow the below approach to create & send events
/// Example events: Onboarding module events
enum OnBoardingEvent: OCAnalyticsEventProtocol {
// Events
case login
case home
case logout(reason: String)
/// Name of the event
var name: String {
switch self {
case .login:
"Login"
case .home:
"Home"
case .logout:
"Logout"
}
}
/// Type of the event
var type: OCAnalyticsEventType {
switch self {
case .home:
return .state
case .login, .logout:
return .action
}
}
/// Event data
var data: [String: Any] {
switch self {
case .login, .home:
["": ""]
case .logout(let reason):
["reason": reason]
}
}
}
struct ClientAppExample {
/// Setup example
func setUpAnalytics() {
// This needs to be done on the app launch event
OCAnalyticsManager.shared.initialize(logType: .debug,
lifeCycleContext: [:],
appID: "com.analytics.example",
application: UIApplication.shared)
}
/// Track event example
func trackEvent() {
// Example 1
OCAnalyticsManager.shared.trackEvent(OnBoardingEvent.login)
// Example 2
OCAnalyticsManager.shared.trackEvent(OnBoardingEvent.home)
// Example 3
OCAnalyticsManager.shared.trackEvent(OnBoardingEvent.logout(reason: "Session timed out"))
}
}