Search code examples
ios6google-analytics

iOS Google Analytics missing first UIViewController


BLUF: Google Analytics iOS v2 beta 4 misses tracking my first UIViewController that is loaded while hitting successfully on subsequent UIViewControllers (subclassed with GAITrackedViewController)

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.

    // 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 = 0;
    // Optional: set debug to YES for extra debugging information.
    [GAI sharedInstance].debug = YES;
    // Create tracker instance.
    [[GAI sharedInstance] trackerWithTrackingId:@"UA-########-1"];    // id<GAITracker> tracker = 

    return YES;
}

MainViewController.m

- (void)viewDidLoad
{
    NSLog(@"viewDidLoad");
    [super viewDidLoad];
    self.trackedViewName = @"First Screen";
    //[[GAI sharedInstance] dispatch];
    ...
}

I do not call dispatch manually on the working UIViewController's, and I have tried both calling and not calling on the non-working. But it is a mystery. No logs are generated if I don't call it manually. When I do call dispatch manually I receive the following:

GoogleAnalytics 2.0b4 -[GAIDispatcher initiateDispatch:retryNumber:] (GAIDispatcher.m:481) DEBUG: No pending hits.

Thanks in advance!


Solution

  • Turns out that you should really make sure that if you override any methods, you should make sure to call super on them as well...

    I had written my own viewDidAppear method but had not called [super viewDidAppear:animated];. I guess that is where GoogleAnalytics does their magic. Hopefully this will help someone else not do this as well.