8

想知道是否有人可以帮助我,我正在尝试在我的 IOS 项目上设置 Google Analytics。我只需要一个非常简单的实现来显示视图被加载的次数。我遵循了谷歌文档(https://developers.google.com/analytics/devguides/collection/ios/v3/)但是我的仪表板中没有任何更新

我有一个属性设置报告没有用户

我的 appdelegate 如下

#import <UIKit/UIKit.h>
#import "GAI.h"

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property(nonatomic, strong) id<GAITracker> tracker;

@end

我的 .m 包含 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

[GAI sharedInstance].trackUncaughtExceptions = YES;

// Optional: set Google Analytics dispatch interval to e.g. 20 seconds.
[GAI sharedInstance].dispatchInterval = 20;

// Optional: set Logger to VERBOSE for debug information.
[[[GAI sharedInstance] logger] setLogLevel:kGAILogLevelVerbose];

// Initialize tracker. which i have set up at the top of my .mn
   self.tracker =  [[GAI sharedInstance] trackerWithTrackingId:kTrackingId];

return YES;
}

还有我试图记录进口指标的页面#import“GAI.h”#import“GAIDictionaryBuilder.h”

并包含以下方法

-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];


id tracker = [[GAI sharedInstance] defaultTracker];

// This screen name value will remain set on the tracker and sent with
// hits until it is set to a new value or to nil.
[tracker set:@"&cd"
       value:@"Home Screen"];

// manual screen tracking
[tracker send:[[GAIDictionaryBuilder createAppView] build]];
}

我没有看到任何错误,我得到了一个初始控制台日志

NFO:GoogleAnalytics 3.02-[GAIReachabilityCheckerreachabilityFlagsChanged:](GAIReachabilityChecker.m:159):可达性标志更新:0X000002

但我在仪表板上什么也没有

我还尝试了( https://developers.google.com/analytics/devguides/collection/ios/v3/screens )上所述的 Auto 方法,但是这抱怨没有屏幕名称存在

快把我逼疯了!任何帮助,将不胜感激!

更新

使用 SDK 中包含的示例,我能够获得向 google 注册的初始负载 - 请注意,这与 google 文档不同:

应用委托

 NSDictionary *appDefaults = @{kAllowTracking: @(YES)};
[[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
// User must be able to opt out of tracking
[GAI sharedInstance].optOut =
![[NSUserDefaults standardUserDefaults] boolForKey:kAllowTracking];
// Initialize Google Analytics with a 120-second dispatch interval. There is a
// tradeoff between battery usage and timely dispatch.
[GAI sharedInstance].dispatchInterval = 120;
[GAI sharedInstance].trackUncaughtExceptions = YES;
self.tracker = [[GAI sharedInstance] trackerWithName:@"ios app name"
                                          trackingId:kTrackingId];

我根据谷歌文档对初始视图控制器使用了自动屏幕跟踪,但这仅适用于初始加载的视图控制器,使用相同方法的后续视图不会注册。

另外我现在的问题是 APPdelegate 方法似乎只在“应用程序 didFinishLaunchingWithOptions”中工作,这只有在应用程序每次退出时才有效,将相同的代码放在“applicationWillEnterForeground”中不起作用 - 太令人沮丧了 - 也试过了

    self.tracker = [[GAI sharedInstance] defaultTracker];
[self.tracker set:kGAISessionControl
       value:@"start"];

这似乎也没有效果

4

1 回答 1

0

我认为设置页面名称时会发生错误:

[tracker set:@"&cd" value:@"Home Screen"];

您需要设置 kGAIScreenName 才能使其工作。我的意思是,不是 @"&cd" 而是 kGAIScreenName :

// This screen name value will remain set on the tracker and sent with
// hits until it is set to a new value or to nil.
[tracker set:kGAIScreenName value:@"Home Screen"];

[tracker send:[[GAIDictionaryBuilder createAppView] build]];

我希望这有帮助

于 2014-10-28T10:59:16.167 回答