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. @import Firebase;
    
    // AnalyticsManager.h
    @interface AnalyticsManager () <VOAnalyticsManagerProtocol>
    
    @end
    
    // AnalyticsManager.m
    @implementation AnalyticsManager
    
    - (instancetype)init {
        self = [super init];
        if (self) {
            [self setup];
        }
        return self;
    }
    
    - (void)setup {
        NSString *firebaseConfigFilePath = [[NSBundle mainBundle] pathForResource:@"GoogleService-Info-Alpha" ofType:@"plist"];
        FIROptions *options = [[FIROptions alloc] initWithContentsOfFile:firebaseConfigFilePath];
        [FIRApp configureWithOptions:options];
    }
    
    #pragma mark <VOAnalyticsManagerProtocol>
    
    - (void)trackEvent:(NSString *)eventName withParams:(NSDictionary *)params {
        [FIRAnalytics logEventWithName:eventName parameters:params];
    }
    
    - (void)trackScreen:(NSString *)screenName screenClass:(Class)screenClass {
        [FIRAnalytics setScreenName:screenName screenClass:NSStringFromClass(screenClass)];
    }
    
    @end
    
  2. AnalyticsManager *analtyicsManager = [AnalyticsManager new];
    VouchrConfig *vouchrConfig = [VouchrConfig configWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"]];
    self.vouchrEngineSDK = [VouchrEngine vouchrEngineWithConfig:vouchrConfig builder:^(VouchrEngineBuilder *builder) {
        builder.analyticsManager = analyticsManager;
        // other setup goes here
    }];