Skip to content

Instantly share code, notes, and snippets.

@priore
Created October 25, 2013 23:49
Show Gist options
  • Save priore/7163556 to your computer and use it in GitHub Desktop.
Save priore/7163556 to your computer and use it in GitHub Desktop.
Cocos2D and Google Analytics Category
//
// Created by Danilo Priore on 20/02/13.
// www.prioregroup.com
//
// CCLayer+GoogleAnalytics.h
#import "CCLayer.h"
@interface CCLayer (GoogleAnalytics)
@end
// CCLayer+GoogleAnalytics.m
import "CCLayer+GoogleAnalytics.h"
#import "GAI.h" // Google Analytics SDK
@implementation CCLayer (GoogleAnalytics)
// overwrite original method of CCLayer
- (void)onEnterTransitionDidFinish {
NSString *className = NSStringFromClass([self class]);
// filter only for my classes (in this case the names start with "game")
if (![[className substringToIndex:4] isEqualToString:@"Game"])
return;
#ifndef DEBUG
// track of the specified view was displayed
[[GAI sharedInstance].defaultTracker sendView:className];
#else
NSLog(@"Class Name: %@", className);
#endif
// original code of CCLayer
#ifdef __CC_PLATFORM_IOS
if( isAccelerometerEnabled_ )
[[UIAccelerometer sharedAccelerometer] setDelegate:self];
#endif
[super onEnterTransitionDidFinish];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment