Eduardo Iglesias
Eduardo Iglesias

Reputation: 1066

Google Analytics with Cocos2d

I'm trying to implement Google Analytics on my game with cocos2d. But how can I do it. because I am trying to allocate GAItrackedViewController manually. and I can't

  GAITrackedViewController *track = [[GAITrackedViewController alloc] init];

track.tracker = [[GAI sharedInstance] trackerWithTrackingId:@"UA-XXX-X"];;
track.screenName = @"Menu";

Any ideas?

Thanks!

Upvotes: 1

Views: 858

Answers (1)

Bivis
Bivis

Reputation: 1407

You don't need to create an instance of GAITrackedViewController (and is recommended to don't create).

The [[GAI sharedInstance] trackerWithTrackingId] will create an tracker or get an already initialized tracker.

So, the correct way is:

id<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:@"UA-XXXX-X"];;
[tracker set:kGAIScreenName value:@"Menu"];

PS 1: You can set the Tracking id on your AppDelegate, and then use [[GAI sharedInstance] defaultTracker] later. The tracker instance is persisted in the library.

PS 2: In cocos2d, you can't use GAITrackedViewController, because it only have the Director's View Controller. You need to use it manually with GAITracker.

Upvotes: 2

Related Questions