gpt4 book ai didi

objective-c - iOS - GANTracker 没有什么可调度的

转载 作者:可可西里 更新时间:2023-11-01 06:16:24 25 4
gpt4 key购买 nike

我正在尝试在我的 iOS 应用程序中安装 Google Analytics SDK 以跟踪页面浏览量和事件。按照提供的文档进行操作后,我似乎根本无法进行跟踪,想知道有人可以帮助我吗?以下信息可能是相关的——我会尽量描述清楚。

  • 我的目标是所有 iOS 4.3 及更高版本的设备。
  • 我在我的 project-prefix.pch 文件中包含了 GANTracker.h,它构建正常

下面是在 didFinishLaunchingWithOptions 方法中调用的我的 appdelegate.m 代码中的示例

/*  Google Analytics tracking code  */

[[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]);

}

在我的应用 View Controller 中,我想跟踪 pageViews 并按照以下方式进行操作:

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSError *trackError;
NSString *pageUrlString = [[NSString stringWithFormat:@"/aboutsection"] stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
if(![[GANTracker sharedTracker] trackPageview:pageUrlString withError:&trackError])
{
//Handle error here
NSLog(@"There was an error tracking this pageview\n Description: %@\n", [trackError localizedDescription]);
NSLog(@"Failure reason: %@\n", [trackError localizedFailureReason]);
NSLog(@"May we suggest: %@\n", [trackError localizedRecoverySuggestion]);
}
}

回到我的 appdelegate.m 我还设置了以下委托(delegate)

- (void)trackerDispatchDidComplete:(GANTracker *)tracker eventsDispatched:(NSUInteger)hitsDispatched eventsFailedDispatch:(NSUInteger)hitsFailedDispatch
{
NSLog(@"Google analytics dispatch\n Succeeded?:\n %i, \n Failed?: %i", hitsDispatched, hitsFailedDispatch);
}

此记录类似于 Succeeded?: 5 Failed?: 0 所以不会出现故障

我还看到一条日志消息...没有要发送的内容。登录到 Google Analytics,我没有看到任何访问。查看实时分析也没有任何反应。

我是不是漏掉了什么?

最佳答案

它只有在我尝试了这些步骤时才有效:

1- 在 appdelegate .h 类 #import "GAI.h"

2- 在函数“didFinishLaunchingWithOptions”中的 appdelegate 添加此代码

 // 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 = 20;
// Optional: set debug to YES for extra debugging information.
[GAI sharedInstance].debug = NO;
// Create tracker instance.
[[GAI sharedInstance] trackerWithTrackingId:"your tracking application id from google analytics"];

3- 在任何 uiviewcontroller 类中。 h #import "GAI.h"

4- at .h 将这部分“:uiviewcontroller”替换为“:GAITrackedViewController”

5- at .m add in view 确实加载了这一行

[[[GAI sharedInstance] defaultTracker] trackView:"your view title"];
  • 注意第 5 点,必须通过这种方式实现我认为 GA 库在任何其他方式和文档中也存在问题。我尝试并搜索了很多有关此问题的信息,偶然发现它只能通过这种方式工作,而且这是在 GA 屏幕上显示效果的最快方式。

  • 另外注意:您必须在 google analytics 创建您的移动应用程序,注意应用程序的 ID 以将其添加到正确的 IOS 应用程序

关于objective-c - iOS - GANTracker 没有什么可调度的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12990954/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com