简体   繁体   English

iOS Google Analytics自定义维度

[英]iOS Google Analytics Custom Dimensions

I've been reading the Custom Dimensions documentation for iOS and found the following example: 我一直在阅读iOSCustom Dimensions文档,并找到了以下示例:

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

But when the dimension is created in control panel, the proposed code is: 但是当在控制面板中创建维度时,建议的代码是:

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

I've been also reading the documentation for Android and found this example: 我也一直在阅读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()
);

My questions: 我的问题:

  • Which is the correct way to set dimensions in iOS? 在iOS中设置尺寸的正确方法是什么?
  • In case of the first one (documentation one), why in iOS we need to set the value both in tracker and builder? 如果是第一个(文档一),为什么在iOS中我们需要在跟踪器和构建器中设置值?
  • Why in iOS the dimension value in tracker ("Premium user") is set to a different value in builder ("premium")? 为什么在iOS中,跟踪器中的维度值(“高级用户”)在构建器中设置为不同的值(“高级”)?
  • Would it be correct to set the same value in tracker and in builder? 在跟踪器和构建器中设置相同的值是否正确?
  • In that case, why setting it twice? 在那种情况下,为什么要设置两次? I've tried to set it just in builder and then it chrashes with error this class is not key value coding-compliant for the key &cd1 . 我试图在构建器中设置它,然后它因错误而崩溃, 这个类不是键和cd1的键值编码兼容 Setting it in tracker will not repport the value ( GA for iOS and custom dimensions ). 在跟踪器中设置它将不支持该值( iOS和自定义维度的GA )。

The code could be: 代码可以是:

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

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

There is a good tutorial how to use custom dimensions both iOS and Android and how to set custom reports. 有一个很好的教程如何使用iOS和Android的自定义维度以及如何设置自定义报告。

In the case of the first one there are two different ways. 在第一种情况下,有两种不同的方式。 They are independent from each other. 它们彼此独立。

First: 第一:

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

Second: 第二:

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

If you want track custom dimensions or custom metric, then you have to create them on the GA adminpage . 如果您想要跟踪自定义维度或自定义指标,则必须在GA管理页面上创建它们。 Here choose custom definitions. 在这里选择自定义。 After that create a custom report on the customization tab, which will represent your measurements. 之后,在自定义选项卡上创建自定义报告,该报告将代表您的测量结果。

Important that you have to wait maybe one or two days after the google analytics registration until measurements will appear in your custom reports. 重要的是,您必须等待谷歌分析注册后一两天,直到测量结果出现在您的自定义报告中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM