Skip to content

Instantly share code, notes, and snippets.

@vittoriom
Created March 26, 2014 18:26
Show Gist options
  • Save vittoriom/9789960 to your computer and use it in GitHub Desktop.
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)
- (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