views:

33

answers:

1

I am having issues setting up Google Analytics for my iPhone Application. I have a website that I have sucesfully been using Google Analytics on, and so I am pretty familiar with how it works.

I set up a new fake domain with the following formation: myapp.mysite.com. I got the UA ID that was made and used that as shown below.

In my iPhone application's "didfinishlaunching" method, I have the following code:

[[GANTracker sharedTracker] startTrackerWithAccountID:@"UA-XXXXXXXX-X"
                                       dispatchPeriod:kGANDispatchPeriodSec
                                             delegate:nil];
NSError *error;
if (![[GANTracker sharedTracker] trackEvent:@"test" action:@"my_action" label:@"my_label" value:-1 withError:&error]) {
        NSLog(@"error ocurred");
}

where UA-XXXXXXXX-X is filled in with my ID.

I install the application on my phone, run the app for over 20 minutes, and google analytics still states that "tracking is not installed."

What is wrong here?

Thanks!

A: 

Here are a few things to try:

First, try adding

BOOL success = [[GANTracker sharedTracker] dispatch];

to the end of your code and testing the value of success.

Second, I don't see kGANDispatchPeriodSec defined in GANTracker.h. Is this a const that you're creating? Pass in a 0 as the dispatchPeriod instead so dispatches are sent immediately instead of batched. (You'll want to change this before you submit your app.)

Finally, implement GANTrackerDelegate on your class and see what's happening in the trackerDispatchDidComplete:eventsDispatched:eventsFailedDispatch call. This will tell you if your dispatch calls are failing, but unfortunately won't tell you why.

See this link about adopting a protocol on your class. In your .m file, add the following:

#pragma mark GANTrackerDelegate

- (void)trackerDispatchDidComplete:(GANTracker *)tracker
                  eventsDispatched:(NSUInteger)eventsDispatched
              eventsFailedDispatch:(NSUInteger)eventsFailedDispatch {
    NSLog(@"events dispatched: %d, events failed: %d", eventsDispatched, eventsFailedDispatch);
}
Robot K
Thank you very much for your response. Firstly, I forgot to mention, but yes, kGANDispatchPeriodSec is a const variable that is set to -1. Also, I added the success code and turns out the value for "success" is coming out as YES. Something is still wrong. How example do I implement the GANTrackerDelegate?
Robert Eisinger
I made this mistake at first to. Setting the `dispatchPeriod` to -1 means the dispatch will never happen until you call `dispatch` manually, so your analytics calls were never getting sent.
Robot K
Okay, I've changed it to positive 1. It still doesn't work. Argh. What else could be wrong?
Robert Eisinger
I've updated the answer to include help for implementing the delegate.
Robot K
Oh, okay, great. I'll take a look. And also, in google analytics it says:
Robert Eisinger
Tracking Not Installed (Last checked: Oct 8, 2010 11:51:52 AM )
Robert Eisinger
How do I get it to update now? It hasn't checked for a long time!
Robert Eisinger
I think you just have to wait. Google Analytics isn't anything close to real time.
Robot K
Oh wait, I put the wrong time zone so actually 11:51:52 was a few minutes ago. Yeah this still isn't working. The fail method you wrote above isn't printing anything to the log. Any other ideas?
Robert Eisinger
It's not getting called. In your `startTrackerWithAccountID` call, pass in `self` as the `delegate` parameter.
Robot K
How do I specify that my app delegate is the GANTrackerDelegate? I tried
Robert Eisinger
@interface MyAppDelegate : NSObject <UIApplicationDelegate, GANTrackerDelegate> {in my .h file for the app delegate.but this didn't work. It cannot find GANTrackerDelegate
Robert Eisinger
Add `#include "GANTracker.h"` to your .h file.
Robot K
thanks, lol!Okay now I have output: events dispatched: 2, events failed: 0
Robert Eisinger
Any last ideas?
Robert Eisinger
The client side of things is working in that we know events are getting successfully dispatched. I suspect you just need to be patient, but there may be something about the GA site that's not set up correctly.
Robot K
okay, I'll be patient and check back in a few days. Thanks for all your help!
Robert Eisinger