简体   繁体   English

iOS上的Google Analytics在调度时返回NO,没有调试输出

[英]Google Analytics on iOS returning NO on dispatch, no debug output

In trying to implement the Google Analytics SDK for iOS, I've run into two brick walls. 在尝试实施适用于iOS的Google AnalyticsSDK时,我遇到了两个问题。

The first one is that after executing this code in application:DidFinishLaunchingWithOptions: 第一个是在application:DidFinishLaunchingWithOptions:执行此代码之后application:DidFinishLaunchingWithOptions:

[[GANTracker sharedTracker] startTrackerWithAccountID:@"UA-XXXXXXX-YY"
                                       dispatchPeriod:10
                                             delegate:self];
[[GANTracker sharedTracker] setDebug:YES];

.. and then trying to track anything or call dispatch , no debug messages are logged whatsoever. ..然后尝试跟踪任何内容或调用dispatch ,不会记录任何调试消息。 I've added NSLog lines before and after tracking calls and the code is definitely being reached. 我在跟踪调用之前和之后都添加了NSLog行,并且代码肯定已经到达。

Secondly, when I do try and do a manual dispatch, it returns NO . 其次,当我尝试做手动调度时,它返回NO All the other issues I've seen online are where dispatch returns YES but it's somehow not going through properly. 我在网上看到的所有其他问题都是dispatch返回YES但它不知何故无法正常通过。 What does one do if dispatch actually returns NO ? 如果dispatch实际上返回NO怎么办?

I've tried adding an NSError * reference to the track methods and those actually succeed (no error, function returns YES ). 我已经尝试向track方法添加一个NSError *引用,并且实际上成功了(没有错误,函数返回YES )。 But the events are definitely not being periodically dispatched, since we're seeing nothing on the GA account more than 24 hours later. 但事件绝对没有定期发送,因为我们在超过24小时后在GA帐户上看不到任何内容。

EDIT: I've also got NSLog calls in both of the delegate methods ( hitDispatched: and trackerDispatchDidComplete:eventsDispatched:eventsFailedDispatch: ), and neither of those are being called either. 编辑:我也在两个委托方法( hitDispatched:trackerDispatchDidComplete:eventsDispatched:eventsFailedDispatch:获得了NSLog调用,并且这两个方法都没有被调用。

i think you should check this to delegate method of GANTracker 我认为你应该检查这个委托GANTracker的方法

- (void)trackerDispatchDidComplete:(GANTracker *)tracker
              eventsDispatched:(NSUInteger)hitsDispatched
          eventsFailedDispatch:(NSUInteger)hitsFailedDispatch{

//print or check number of events failed or success

}
//Delegate is set to 'nil' instead of class instance which implements the delegate methods.    
[[GANTracker sharedTracker] startTrackerWithAccountID:@"UA-XXXXXXX-YY"
                                   dispatchPeriod:10
                                         delegate:nil];

In your case, assuming that UIApplicationDelegate may be implementing GANTrackerDelegate , the message call should set delegate as ' self ' . 在您的情况下,假设UIApplicationDelegate可能正在实现GANTrackerDelegate ,则消息调用应将委托设置为“self”

Cheers!! 干杯!!
Amar. 阿马尔。

可能是调度依赖于调用线程的运行循环 - 你是否有可能从一个辅助线程运行它,一个在调度假设给你回电时可能不存在的线程?

You've not enabled dryRun have you? 你还没有启用dryRun吗? Double check with: 仔细检查:

[[GANTracker sharedTracker] setDryRun:NO];

Also try dispatchSynchronous, it'll block as it's sending but might help with if things aren't on the same threads: 也尝试dispatchSynchronous,它会在发送时阻塞但如果事情不在同一个线程上可能有帮助:

[[GANTracker sharedTracker] dispatchSynchronous];

Just've checked it from scratch, dispatch perfectly worked meaning 只是从头开始检查,发出完美的工作意义

a) your device is somehow different (i still have unsolved crashes on the particular iPad's 3 from Apple tester's unresolved, so it wouldn't be a huge surprise) a)你的设备有些不同(我仍然没有解决特定的iPad 3上来自Apple测试仪未解决的问题,所以这不会是一个巨大的惊喜)

b) your code is somehow different - and that's much easier for you to fix. b)你的代码有些不同 - 这对你来说更容易修复。


For the a) there's no advice but to test it against all the devices you might get, for the b) i could only say what worked for me: 对于a)没有任何建议,只能针对你可能获得的所有设备进行测试,因为b)我只能说对我有用的东西:

  • downloaded 1.4 SDK here 在这里下载了1.4 SDK
  • got Google sample projects with git clone https://code.google.com/p/google-mobile-dev.analytics-end-to-end/ 通过git clone https://code.google.com/p/google-mobile-dev.analytics-end-to-end/获得Google示例项目git clone https://code.google.com/p/google-mobile-dev.analytics-end-to-end/
  • configured final/AnalyticsSample to launch, changed the source slightly 配置final / AnalyticsSample以启动,稍微更改了源

(trackEvent::::: were called from sample, app was restarted manually as there's zero time period requiring dispatch call) (trackEvent :::::从样本调用,app手动重启,因为零时间段需要调度调用)

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [[GANTracker sharedTracker] startTrackerWithAccountID:kGANAccountId
                                         dispatchPeriod:0
                                               delegate:self];

    NSLog(@"Dispatch%@", [[GANTracker sharedTracker] dispatch] ? @"ed Successfully": @" Failed");

  [self.window addSubview:tabBarController.view];
  [self.window makeKeyAndVisible];

  return YES;
}

That's it, log says Dispatched Successfully , worth trying i guess. 就是这样,日志说Dispatched Successfully ,值得我试试。

cough 咳嗽

I'd misspelled the #define to start the tracker object in my app delegate. 我拼错了#define来启动我的app委托中的跟踪器对象。 Other files were spelled correctly, hence the logging statements showing up, but when I tried to log just before the tracker was started it didn't show. 其他文件拼写正确,因此日志记录语句显示,但当我在跟踪器启动之前尝试记录时,它没有显示。

Oops. 哎呀。 Well, at least there's a decent troubleshooting post for Google Analytics on SO now! 好吧,至少现在有一个关于SO Analytics的Google Analytics问题!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM