2014-12-05 45 views
9

我一直在阅读Custom Dimensions documentation for iOS,发现下面的例子:iOS版谷歌Analytics(分析)自定义尺寸

// May return nil if a tracker has not yet been initialized with a property ID. 
id tracker = [[GAI sharedInstance] defaultTracker]; 

// Set the custom dimension value on the tracker using its index. 
[tracker set:[GAIFields customDimensionForIndex:1] 
     value:@"Premium user"] 

[tracker set:kGAIScreenName 
     value:@"Home screen"]; 

// Send the custom dimension value with a screen view. 
// Note that the value only needs to be sent once, so it is set on the Map, 
// not the tracker. 
[tracker send:[[[GAIDictionaryBuilder createAppView] set:@"premium" 
                forKey:[GAIFields customDimensionForIndex:1]] build]]; 

但在控制面板中创建的尺寸时,所提出的代码是:

NSString *dimensionValue = @"SOME_DIMENSION_VALUE"; 
[tracker set:[GAIFields customDimensionForIndex:1] value:dimensionValue]; 

我也一直在阅读documentation for Android,发现这个例子:

// Get tracker. 
Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(TrackerName.APP_TRACKER); 
t.setScreen("Home Screen"); 

// Send the custom dimension value with a screen view. 
// Note that the value only needs to be sent once. 
t.send(new HitBuilders.AppViewBuilder() 
    .setCustomDimension(1, "premiumUser") 
    .build() 
); 

我的问题:

  • 这是设置尺寸的iOS正确的方法是什么?
  • 如果是第一个(文档之一),为什么在iOS中我们需要在跟踪器和构建器中设置值?
  • 为什么在iOS中,跟踪器(“高级用户”)中的维度值在生成器(“高级”)中设置为不同的值?
  • 在跟踪器和构建器中设置相同的值是否正确?
  • 在这种情况下,为什么要设置两次?我试图设置它只是在建设者,然后它崩溃与错误这个类是不符合密钥编码的密钥& cd1。将其设置为跟踪器不会支持该值(GA for iOS and custom dimensions)。

的代码可能是:

[tracker set:[GAIFields customDimensionForIndex:1] 
     value:@"custom dimension value"] 

[tracker send:[[[GAIDictionaryBuilder createAppView] set:@"custom dimension value" 
                forKey:[GAIFields customDimensionForIndex:1]] 
+0

使用构建器时遇到确切的崩溃。你有没有达到任何解决方案?如果它很重要,我使用Swift。 – Sam 2015-01-22 21:39:13

+0

设置两次:在[tracker set:]'和[tracker send:]'中,如最后一个代码所示。但仍然没有回应这个问题... – Miquel 2015-01-23 06:38:26

回答

3

有一个good tutorial如何使用自定义尺寸iOS和Android和如何设置自定义报表。

在第一种情况下,有两种不同的方式。他们彼此独立。

第一:

id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker]; 
[tracker set:[GAIFields customDimensionForIndex:index] value:@"value"]; 
tracker send:[[GAIDictionaryBuilder createScreenView] build]]; 

二:

id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker]; 
[tracker send:[[[GAIDictionaryBuilder createScreenView] set:@"value" 
                forKey:[GAIFields customDimensionForIndex:index]] build]]; 

如果你想跟踪自定义维度或自订指标,那么你必须在GA adminpage创建它们。这里选择自定义定义。之后,在定制选项卡上创建自定义报告,这将代表您的测量结果。

重要的是,您必须等待谷歌分析注册后的一两天,直到测量结果出现在您的自定义报告中。

相关问题