iOS中的Google Analytics(分析)(不工作)

iOS中的Google Analytics(分析)(不工作),第1张

概述我试图实现谷歌分析..你们可以帮助我吗 -(void) setGoogleAnalytics{ // Initialize tracker. self.tracker = [[GAI sharedInstance] trackerWithName:@"ipad app" trackingI 我试图实现谷歌分析..你们可以帮助我吗

-(voID) setGoogleAnalytics{    // Initialize tracker.    self.tracker = [[GAI sharedInstance] trackerWithname:@"ipad app"                                              trackingID:kTrackingID];    NSDictionary *appDefaults = @{kAllowTracking: @(YES)};    [[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];    // User must be able to opt out of tracking    [GAI sharedInstance].optOut =    ![[NSUserDefaults standardUserDefaults] boolForKey:kAllowTracking];    // 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 = 5;    // Optional: set Logger to VERBOSE for deBUG information.    [[[GAI sharedInstance] logger] setLogLevel:kGAILogLevelVerbose];    [[GAI sharedInstance] setTrackUncaughtExceptions:YES];}

并呼叫它

- (BOol)application:(UIApplication *)application dIDFinishLaunchingWithOptions:(NSDictionary *)launchOptions{            [self setGoogleAnalytics];    //    //    //}

里面我的VIEwController实现

[self dispatchEvent:@"Purchase Done"];[self trackVIEwname:NsstringFromClass([self class])]; -(voID) trackVIEwname:(Nsstring *) strClassname{        [[GAI sharedInstance] defaultTracker];        self.screenname=[Nsstring stringWithFormat:@"%@",strClassname];        [self.tracker send:[[NSDictionary alloc] initWithObjectsAndKeys:strClassname,@"VIEwname",nil]];        [[GAI sharedInstance] dispatch];    }- (voID)dispatchEvent:(Nsstring *)strbuttonText{    ID<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];    [tracker send:[[GAIDictionaryBuilder createEventWithcategory:@"ui_action"     // Event category (required)                                                          action:@"button_press"  // Event action (required)                                                           label:strbuttonText          // Event label                                                           value:nil] build]];    // Event value  = [[GAI sharedInstance] defaultTracker];    [[GAI sharedInstance] dispatch];}

哪个版本的谷歌分析,我应该下载目前我已经下载谷歌GoogleAnalytiCSServicesiOS_3.01.zip(推荐),因为我不想使用测试版GoogleAnalyticsiOS_2.0beta4.zip

解决方法 UPDATE – 适用于iOS v3的Google Analytics(分析)SDK

所以我使用v3,没有任何问题:

我在AppDelegate中实现了它。在.h文件中:

#import "GAI.h"@property (nonatomic,assign) ID<GAITracker> tracker; // I'm not using ARC (assign)

.M:

#import "GAIDictionaryBuilder.h"#import "GaifIElds.h"// Google Analytics[GAI sharedInstance].trackUncaughtExceptions = YES;[GAI sharedInstance].dispatchInterval = 0;tracker = [[GAI sharedInstance] trackerWithTrackingID:@"yourGAID"];

并写一个这样的方法:

- (voID) sendGoogleAnalyticsVIEw:(Nsstring*)vIEwname{    [tracker set:kGAIScreenname value:vIEwname];    [tracker send:[[GAIDictionaryBuilder createAppVIEw] build]];    [[GAI sharedInstance] dispatch]; // this will force track your vIEws.}

老回答:

在这个链接下面看到这个答案,如果你这样做,就像我在这个答案中所说的一样,它必须工作

Another stack-overflow answered question about google-analytics

并使用以下方法:

[GAI sharedInstance].optOut = YES;[GAI sharedInstance].dispatchInterval = 0;[GAI sharedInstance].trackUncaughtExceptions = YES;    tracker = [[GAI sharedInstance] trackerWithTrackingID:@"YOUR TRACKERID"];[tracker sendVIEw:@"Your VIEw name"];[tracker sendEventWithcategory:@"YOUR category" withAction:@"YOUR ACTION" withLabel:nil withValue:nil];

从this link下载GoogleAnalyticsiOS_2.0beta4.zip,这将包含您需要的这些类,它将会很好的工作。小心,谷歌分析有一个交货时间,向您显示关于实时的信息。而且实时数据不会仅在一天后才会显示

编辑3.0:

我发现一些可能对你有用的东西:

We have just come across this issue and this is slightly out of date
so here is an updated answer. The issue we were having after following
the instructions on the Google Analytics website,they instruct you to
add the following files GAI.h,GAIDictionaryBuilder.h,GAILogger.h,
GAITrackedVIEwController.h,GAITracker.h and
libGoogleAnalytics_deBUG.a library. What they completely forget to
include on the website instructions is the one where you have to
include libGoogleAnalytiCSServices.a library. This is included in the
zipped download but there is no instructions to indicate to include
this in the deBUG version.

Note : In the readme.txt libGoogleAnalytiCSServices.a is just referred
to as libGoogleAnalytics.a Google have Failed to update their
documentation to include the new name or the correct instructions that
indicate this is required in deBUG.

files and librarIEs that most be included

GAI.hGAIDictionaryBuilder.hGaifIElds.hGAILogger.hGAITrackedVIEwController.hGAITracker.hlibGoogleAnalytics.a // Also kNow as libGoogleAnalytiCSServices.alibGoogleAnalytics_deBUG.a

加信息:

I’m pretty sure Google has not yet provIDed a arm64 version of their
libGoogleAnalytiCSServices.a,which is really annoying …it has
been weeks since the public the release of Xcode 5GM.

For Now,I guess only build for armv7,armv7s or remove Google
analytics until they get their head out of their pants.

这是一个iOS Getting Started Guide.实现它。

- (BOol)application:(UIApplication *)application dIDFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  // 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 = 0;  // Optional: set Logger to VERBOSE for deBUG information.  [[[GAI sharedInstance] logger] setLogLevel:kGAILogLevelVerbose];  // Initialize tracker.  ID<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingID:@"UA-XXXX-Y"];}

要手动发送屏幕视图,请在跟踪器上设置屏幕字段值,然后发送命中:

// May return nil if a tracker has not already been initialized with a// property ID.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:kGAIScreenname       value:@"Home Screen"];[tracker send:[[GAIDictionaryBuilder createAppVIEw] build]];

或自动屏幕测量:

automatically measure vIEws as screens using the
GAITrackedVIEwController class. Have each of your vIEw controllers
extend GAITrackedVIEwController and add a property called screenname.
This property will be used to set the screen name fIEld.

//// MyVIEwController.h// An example of using automatic screen tracking in a VIEwController.//#import "GAITrackedVIEwController.h"// Extend the provIDed GAITrackedVIEwController for automatic screen// measurement.@interface AboutVIEwController : GAITrackedVIEwController@end//// MyVIEwController.m//#import "MyVIEwController.h"#import "AppDelegate.h"@implementation MyVIEwController- (voID)vIEwDIDLoad {    [super vIEwDIDLoad];    // Set screen name.    self.screenname = @"Home Screen";}// Rest of the VIEwController implementation.@end

事件跟踪:

link

To send an event to Google Analytics,use
GAIDictionaryBuilder.createEventWithcategory:action:label:value: and
send the hit,as in this example:

// May return nil if a tracker has not already been initialized with a property// ID.ID<GAITracker> = [[GAI sharedInstance] defaultTracker];[tracker send:[[GAIDictionaryBuilder createEventWithcategory:@"ui_action"     // Event category (required)                                                      action:@"button_press"  // Event action (required)                                                       label:@"play"          // Event label                                                       value:nil] build]];    // Event value
总结

以上是内存溢出为你收集整理的iOS中的Google Analytics(分析)(不工作)全部内容,希望文章能够帮你解决iOS中的Google Analytics(分析)(不工作)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/web/1086679.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存