I am trying to install the Google Analytics SDK in an iOS app to track page views and events. Following the documentation provided, I don't seem to be able to track the work at all, and I wonder if anyone can help me? The following information may be relevant - I will try to be as descriptive as I can.
- I configure all devices with iOS 4.3 and higher.
- I included GANTracker.h in the project-prefix.pch file and it builds ok
Below is a sample from my appdelegate.m code that is called in the didFinishLaunchingWithOptions method
[[GANTracker sharedTracker] setSampleRate:100]; [[GANTracker sharedTracker]setDebug:NO]; [[GANTracker sharedTracker] setDryRun:NO]; [[GANTracker sharedTracker] startTrackerWithAccountID:@"UA-111111-1" dispatchPeriod:kGANDispatchPeriodSec delegate:self]; NSLog(@"Dispatch%@", [[GANTracker sharedTracker] dispatch] ? @"ed Successfully": @" Failed"); NSError *error; if (![[GANTracker sharedTracker] setCustomVariableAtIndex:1 name:@"iPhone" value:@"iv1" withError:&error]) { NSLog(@"There was an error setting this custom variable\n Description: %@\n", [error localizedDescription]); NSLog(@"Failure reason: %@\n", [error localizedFailureReason]); NSLog(@"May we suggest: %@\n", [error localizedRecoverySuggestion]); } if (![[GANTracker sharedTracker] trackEvent:@"Loading" action:@"App Finished Launching" label:@"appDidFinishLaunchingWithOptions" value:-1 withError:&error]) { NSLog(@"There was an error in tracking events\n Description: %@\n", [error localizedDescription]); NSLog(@"Failure reason: %@\n", [error localizedFailureReason]); NSLog(@"May we suggest: %@\n", [error localizedRecoverySuggestion]); } NSString *pageUrlString = [[NSString stringWithFormat:@"http://ios.organisation.tld/appentrypoint"] stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]; if(![[GANTracker sharedTracker] trackPageview:pageUrlString withError:&error]) { NSLog(@"There was an error in tracking initial app entry\n Description: %@\n", [error localizedDescription]); NSLog(@"Failure reason: %@\n", [error localizedFailureReason]); NSLog(@"May we suggest: %@\n", [error localizedRecoverySuggestion]); }
In my application view dispatchers, I want to track the pageView and do this:
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; NSError *trackError; NSString *pageUrlString = [[NSString stringWithFormat:@"/aboutsection"] stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]; if(![[GANTracker sharedTracker] trackPageview:pageUrlString withError:&trackError]) {
Going back to my appdelegate.m I also have the following set of delegates
- (void)trackerDispatchDidComplete:(GANTracker *)tracker eventsDispatched:(NSUInteger)hitsDispatched eventsFailedDispatch:(NSUInteger)hitsFailedDispatch { NSLog(@"Google analytics dispatch\n Succeeded?:\n %i, \n Failed?: %i", hitsDispatched, hitsFailedDispatch); }
Does this lead to something like Successful ?: 5 Failed: 0, so failures don't appear there
I also see a log message ... do not send anything. Sign in to Google Analytics. I do not see any visits. Real-time analytics analysis also shows that nothing is happening.
Did I miss something?