Created
March 26, 2014 18:26
-
-
Save vittoriom/9789960 to your computer and use it in GitHub Desktop.
using VMDInstrumenter to track screen views with Google Analytics in a clean way (for example in a category of the UIViewController)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)setupAnalytics | |
{ | |
VMDInstrumenter *shared = [VMDInstrumenter sharedInstance]; | |
[shared instrumentSelector:@selector(viewDidAppear:) | |
forInstancesOfClass:[VMBaseViewController class] | |
passingTest:^BOOL(VMBaseViewController *instance) { | |
//You can put whatever test you want here | |
return [instance conformsToProtocol:@protocol(VMTrackableScreen)]; | |
} withBeforeBlock:nil | |
afterBlock:^(VMBaseViewController *instance) { | |
//The instance parameter is id, so you can replace it with whatever you want | |
id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker]; | |
[tracker set:kGAIScreenName value:NSStringFromClass([instance class])]; | |
[tracker send:[[GAIDictionaryBuilder createAppView] build]]; | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment