Objective-C Tips & Trick - Prioregroup.com
[Objective-C] Cocos2D and Google Analytics Category
       
back

//
//  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






Copyright © 1996-2018 Centro Studi Informatica di Danilo Priore. All rights reserved. P.I.10149810581.
prioregroup.com