Google IOS分析V3未在仪表板上注册

时间:2021-07-11 13:41:59

Wonder if anyone can help me, I am trying to set up Google Analytics on my IOS project. I just need a very simple implementation to show the amount of times a view is being loaded. I followed the google docs (https://developers.google.com/analytics/devguides/collection/ios/v3/) however nothing updated in my dashboard

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

I have a property set up which is reporting no users

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

My appdelegate is as follows

我的appdelegate如下

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

@interface AppDelegate : UIResponder <UIApplicationDelegate>

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

@end

my .m contains - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

我的.m包含 - (BOOL)应用程序:(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;
}

And the page that I am trying to record metrics on imports #import "GAI.h" #import "GAIDictionaryBuilder.h"

我试图在导入上记录指标的页面#import“GAI.h”#import“GAIDictionaryBuilder.h”

and contains the following method

并包含以下方法

-(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]];
}

I am not seeing any errors, I get an initial console log of

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

NFO: GoogleAnalytics 3.02 -[GAIReachabilityChecker reachabilityFlagsChanged:] (GAIReachabilityChecker.m:159): Reachability flags update: 0X000002

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

But I just get nothing in the dash board

但我在仪表板上什么都没得到

I also tried the Auto method stated on (https://developers.google.com/analytics/devguides/collection/ios/v3/screens) however this complained of no screen name being present

我还尝试了(https://developers.google.com/analytics/devguides/collection/ios/v3/screens)上所述的自动方法,但是这种方法没有出现屏幕名称

It's driving me nuts! Any help would be appreciated!

这让我疯了!任何帮助,将不胜感激!

UPDATE

Using the example included in the SDK, I was able to get the initial load to register with google - note this is different from the google documentation :

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

Appdelegate

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

I used the auto screen tracking for the initial view controller as per google docs, this however only works on the initial loaded view controller, subsequent views using the same method do not register.

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

Also my problem now is that the APPdelegate method only seems to work in "application didFinishLaunchingWithOptions" which will only work if the app quits each time, putting the same code in 'applicationWillEnterForeground' doesn't work - so frustrating - also tried

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

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

which seems to have no effect either

这似乎也没有任何影响

1 个解决方案

#1


0  

I think your error happens when setting the pagename:

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

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

[跟踪器设置:@“&cd”值:@“主屏幕”];

You need to set the kGAIScreenName in order to make it work. I mean, not @"&cd" but kGAIScreenName :

您需要设置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]];

I hope this helps

我希望这有帮助

#1


0  

I think your error happens when setting the pagename:

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

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

[跟踪器设置:@“&cd”值:@“主屏幕”];

You need to set the kGAIScreenName in order to make it work. I mean, not @"&cd" but kGAIScreenName :

您需要设置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]];

I hope this helps

我希望这有帮助