2

BLUF:Google Analytics iOS v2 beta 4 错过了跟踪我的第一个UIViewController在后续成功点击时加载的内容UIViewControllers(使用 子类化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;
}

主视图控制器.m

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

我不会在 working 上手动调用 dispatch UIViewController,并且我尝试过调用和不调用 non-working。但这是一个谜。如果我不手动调用它,则不会生成日志。当我手动调用调度时,我收到以下信息:

GoogleAnalytics 2.0b4 -[GAIDispatcher initialDispatch:retryNumber:] (GAIDispatcher.m:481) 调试:没有待处理的命中。

提前致谢!

4

3 回答 3

7

事实证明,你真的应该确保如果你覆盖任何方法,你应该确保在它们上调用 super ...

我已经编写了自己的viewDidAppear方法,但没有调用[super viewDidAppear:animated];. 我想这就是 GoogleAnalytics 发挥魔力的地方。希望这将帮助其他人要这样做。

于 2013-02-02T17:36:51.567 回答
2

在我的案例中,我确实调用了超级方法,但它在某些页面上不起作用。我只是改变了顺序,让 GA 在超级方法之前,它现在确实有效。

- (void)viewDidAppear:(BOOL)animated {
    self.screenName = @"mainMenu";
    [super viewDidAppear:animated];
}
于 2013-11-15T08:51:48.957 回答
0
Contrary to Shu Zhang answer: super should be called first and then you should add other code: 

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.screenName = @"YourViewControllerName";
    //your implementation here
}

- (void) viewDidAppear:(BOOL)animated {

    [super viewDidAppear:animated];
    ///your implementation here...
}
于 2014-06-23T08:48:55.393 回答