Trending
Opinion: How will Project 2025 impact game developers?
The Heritage Foundation's manifesto for the possible next administration could do great harm to many, including large portions of the game development community.
Featured Blog | This community-written post highlights the best of what the game industry has to offer. Read more like it on the Game Developer Blogs or learn how to Submit Your Own Blog Post
Since releasing my first game as an indie developer, I have been struggling to find out what people are thinking about the game. A few questions hits my mind:
Download the source code here:
http://www.redtgames.com/blog/integrating-google-analytics-to-cocos2d-x-game
What is their behavior in each and every stage.
Are they finding it hard or difficult to play.
Any specific stage they are stuck at and not able to finish (annoyed).
How many times they are losing or wining in a stage
Are they even able to finish the complete game.
Are they visiting your store and do they know that there is an in app purchase available
To me these data are valuable and they give me an opportunity to improve the game and have a better chance at selling it. Without these information it is like flying a plane in the blind and depending on your luck. We are not big companies, we are either sole developers or team of few enthusiastic entrepreneurs who want to create some awesome games :). We all know how hard this is. Even if we end up creating a reasonable game, competition against big companies are unsustainable. BUT, we can try, lets try.
There may be few frameworks to achieve this, I have decided to go with Google analytics. Lets get started.
Get an account for Google analytics HERE
Download the iOS SDK from HERE
Add the SDK to your cocos2d-x project.
<img alt="Google analytics SDK for XCode" height="255" data-cke-saved-href="http://i2.wp.com/redtgames.com/images/analytics_xcode.jpg?w=550"; href="http://i2.wp.com/redtgames.com/images/analytics_xcode.jpg?w=550"; p="" scale="2" data-cke-saved-src="http://i2.wp.com/redtgames.com/images/analytics_xcode.jpg?zoom=2&w=550"; src="http://i2.wp.com/redtgames.com/images/analytics_xcode.jpg?zoom=2&w=550"; src-orig="
In your AppController.mm file add the following code inside didFinishLaunchingWithOptions method including the existing code:
#import "GAI.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSDictionary *appDefaults = @{kAllowTracking: @(YES)};
[[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
// User must be able to opt out of tracking
[GAI sharedInstance].optOut = ![[NSUserDefaults standardUserDefaults] boolForKey:kAllowTracking];
// Optional: automatically send uncaught exceptions to Google Analytics.
[GAI sharedInstance].trackUncaughtExceptions = YES;
// Optional: set Google Analytics dispatch interval to e.g. 20 seconds.
[GAI sharedInstance].dispatchInterval = 20;
// Optional: set Logger to VERBOSE for debug information.
[[[GAI sharedInstance] logger] setLogLevel:kGAILogLevelVerbose];
// Initialize tracker. Replace with your tracking ID.
[[GAI sharedInstance] trackerWithTrackingId:@"UA-XXXXXXXX-1"];//you get this key from your analytics account
return YES;
}
In your RootViewController.mm add the following method:
-(void)setCurrentSceneWith:(NSString *)screenName{
id tracker = [[GAI sharedInstance] defaultTracker];
[tracker set:kGAIScreenName value:screenName];
[tracker send:[[GAIDictionaryBuilder createScreenView] build]];
}
//Initialise vc
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]))
{
vc = self;
}
return self;
}
Now the trick is to create an cocos2d-x wrapper class so that you can call this objective c method. In yourRootViewController.mm add a C++ method which will call the above objective c method:
static RootViewController * vc;
void setScreenName(std::string screenName){
NSString* name = [NSString stringWithCString:screenName.c_str() encoding:[NSString defaultCStringEncoding]];
[vc setCurrentSceneWith:name];
}
Add a new class named analyticsInterface.cpp (or whatever you want to call it) in your project.
//This is same name as set in the above code in the RootViewController.mm class.
void setScreenName(std::string screenName);
//Just pass the screen name
void callSetScreenName(std::string screenName){
setScreenName(screenName);
}
From your GameLayer.cpp simply call the above method and pass the current screen name:
#include "analyticsInterface.h"
bool GameLayer::init(){
if(Layer::init()){
setScreenName("Stage 1");
}
}
Read more about:
Featured BlogsYou May Also Like