我正在尝试在我的 iOS 应用中安装 Google Analytics SDK 来跟踪页面浏览量和事件。遵循提供的文档后,我似乎根本无法进行跟踪,我想知道有人可以帮助我吗?以下信息可能是相关的 - 我会尽量做到描述性。
- 我的目标是 iOS 4.3 及更高版本的所有设备。
- 我已将 GANTracker.h 包含在我的 project-prefix.pch 文件中,并且构建正常
下面是我的 appdelegate.m 代码中的一个示例,它在 didFinishLaunchingWithOptions 方法中调用
/* 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]);
}
在我的应用程序视图控制器中,我想跟踪 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 我还设置了以下委托
- (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 所以那里没有失败
我还看到一条日志消息...没有可发送的信息。登录到谷歌分析我看不到访问。查看实时分析也显示没有发生任何事情。
我在这里错过了什么吗?