Someone wrote: Download the source code here:
Redtgames.com
- 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.
Add the SDK to your cocos2d-x project.
In your AppController.mm file add the following code inside didFinishLaunchingWithOptions method including the existing code:
- (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:
id tracker = [[GAI sharedInstance] defaultTracker];
[tracker set:kGAIScreenName value:screenName];
[tracker send:[[GAIDictionaryBuilder createScreenView] build]];
}
//Initialise vc
{
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;
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.
void setScreenName(std::string screenName);
//Just pass the screen name
void callSetScreenName(std::string screenName){
setScreenName(screenName);
}
Thats it! Your Google Analytics account will show how many players are visiting your current layer. Below is a sample captured from my own device when I was testing my app before submitting to the app store.
Someone wrote: Download the source code here:
Redtgames.com