Adding Analytics

The VouchrSDK allows tracking of analytics events via the <VOAnalyticsManagerProtocol>. The VouchrSDK doesn’t track any events itself, instead delegating back anytime an internal event is logged. See (Analytics Events)[TODO: add url here] for a full list of events that are sent to the VOAnalyticsManagerProtocol.

To receive analytic events, do the following:

  1. Have a class implement the VOAnalyticsManagerProtocol.
  2. Set the analyticsManager in VouchrEngine to your class.

Example Implementation with Google Analytics (Firebase)

  1. // AnalyticsManager.swift
    import VouchrSDK
    import Firebase
    
    class AnalyticsManager: NSObject, VOAnalyticsManagerProtocol {
    
        override init() {
            super.init();
            setup()
        }
    
        func setup() {
            let firebaseConfigFilePath:String = Bundle.main.path(forResource: "GoogleService-Info-Alpha", ofType: "plist")!
            let options:FirebaseOptions = FirebaseOptions(contentsOfFile: firebaseConfigFilePath)!
            FirebaseApp.configure(options: options)
        }
    
        // MARK VOAnalyticsManagerProtocol
    
        func trackEvent(_ event: String!, withParams params: [AnyHashable : Any]!) {
            Analytics.logEvent(event, parameters: params as? [String : Any])
        }
    
        func trackScreen(_ screenName: String!, screenClass: AnyClass!) {
            Analytics.setScreenName(screenName, screenClass: NSStringFromClass(screenClass))
        }
    
    }
    
  2. let analyticsManager = AnalyticsManager()
    self.vouchrSDK = VouchrEngine(config: vouchrConfig, builder: { (builder) in
        builder.analyticsManager = analyticsManager
        // other setup goes here
    })