priore

Cocos2D and Google Analytics Category

Feb 21st, 2013
1,063
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  Created by Danilo Priore on 20/02/13.
  3. //  www.prioregroup.com
  4. //
  5.  
  6. // CCLayer+GoogleAnalytics.h
  7. #import "CCLayer.h"
  8.  
  9. @interface CCLayer (GoogleAnalytics)
  10. @end
  11.  
  12. // CCLayer+GoogleAnalytics.m
  13. import "CCLayer+GoogleAnalytics.h"
  14. #import "GAI.h" // Google Analytics SDK
  15.  
  16. @implementation CCLayer (GoogleAnalytics)
  17.  
  18. // overwrite original method of CCLayer
  19. - (void)onEnterTransitionDidFinish {
  20.    
  21.     NSString *className = NSStringFromClass([self class]);
  22.    
  23.     // filter only for my classes (in this case the names start with "game")
  24.     if (![[className substringToIndex:4] isEqualToString:@"Game"])
  25.         return;
  26.  
  27. #ifndef DEBUG
  28.     // track of the specified view was displayed
  29.     [[GAI sharedInstance].defaultTracker sendView:className];
  30. #else
  31.     NSLog(@"Class Name: %@", className);
  32. #endif
  33.    
  34. // original code of CCLayer
  35. #ifdef __CC_PLATFORM_IOS
  36.     if( isAccelerometerEnabled_ )
  37.         [[UIAccelerometer sharedAccelerometer] setDelegate:self];
  38. #endif
  39.         [super onEnterTransitionDidFinish];
  40. }
  41. @end
Add Comment
Please, Sign In to add comment