简体   繁体   English

使用适用于iOS v2的Google AnalyticsSDK跟踪屏幕层次结构

[英]Tracking Screen Hierarchy with Google Analytics SDK for iOS v2

I'm in the process of adding Google Analytics SDK for iOS v2.0 to an app. 我正在将适用于iOS v2.0的Google AnalyticsSDK添加到应用中。

I've used v1 of the SDK before and I'm fairly sure I used to be able to send a single tracking string like this: 我之前使用过SDK的v1,我很确定我以前能够像这样发送一个跟踪字符串:

[[GANTracker sharedTracker] trackPageview:@"/Home Screen/Contents Screen/Chapter X/Section X/Page X"
                               withError:&error]

or 要么

[[GANTracker sharedTracker] trackPageview:@"/Home Screen/Credits Screen"
                               withError:&error]

When this tracked page was submitted to Google, I could then see a nice break down of the hierarchy of the app in Analytics like this: 当此跟踪页面提交给Google时,我可以看到Google Analytics中应用层次结构的细分,如下所示:

  • Home Screen 主屏幕
    • Contents Screen 内容屏幕
      • Chapter 1 第1章
        • Section 1 第1节
          • Page 1 第1页
          • Page 2 第2页
          • etc 等等
        • Section 2 第2节
        • etc 等等
      • Chapter 2 第2章
      • Chapter 3 第3章
      • etc 等等
    • Credits Screen 积分屏幕

Now the problem is this, when we send this same formatted string to Google using the iOS SDK v2 like so: 现在的问题是,当我们使用iOS SDK v2将这个相同格式的字符串发送给Google时,如下所示:

[tracker sendView:@"/Home Screen/Contents Screen/Chapter X/Section X/Page X"];

we just get a single Screen view in Analytics with an extremely long name and not split up at all: 我们只是在Analytics中获得一个具有极长名称的屏幕视图,而不是完全分开:

  • /Home Screen/Contents Screen/Chapter X/Section X/Page X /主屏幕/内容屏幕/第X章/第X节/第X页

How do we go about splitting our screens out into a hierarchical view as we did in v1? 我们如何像在v1中那样将屏幕拆分为分层视图?

The reason for using the sendView method was so that we could tap into data such as how long users spent in each chapter or section or page and so give us a good idea of the most used areas of the app. 使用sendView方法的原因是我们可以利用数据,例如用户在每个章节或部分或页面中花费的时间,从而让我们对应用程序中最常用的区域有所了解。

We could do this with Events but I'm sure the Screen tracking should be able to do what we want? 我们可以通过事件做到这一点但我确定屏幕跟踪应该能够做我们想要的吗?

It may just be that I'm approaching this the wrong way. 可能只是我正以错误的方式接近这一点。 Any light on this would be greatly received! 任何关于此的亮点都将受到极大的欢迎!

Many thanks, Justyn 非常感谢Justyn

The way Google want you to track this kind of data is via Custom Dimensions. Google希望您跟踪此类数据的方式是通过Custom Dimensions。

So for the above example, you would need to create new custom dimensions for Book, Chapter and Page Number within Google Analytics. 因此,对于上面的示例,您需要在Google Analytics中为Book,Chapter和Page Number创建新的自定义维度。 Here is a good article explaining how to set that up: Configure Google Analytics Custom Dimensions 这是一篇很好的文章,解释了如何进行设置: 配置Google Analytics自定义维度

Once set up on the server, you can then reference them from the client by their index and just pass in the value you want to set. 一旦在服务器上设置,您就可以通过索引从客户端引用它们,并传递您想要设置的值。 You would set the values of the custom dimensions before calling [tracker sendView:@"Screen Name"] . 在调用[tracker sendView:@"Screen Name"]之前,您可以设置自定义尺寸的值。 Something like this: 像这样的东西:

// Get the tracker object.
id tracker = [[GAI sharedInstance].defaultTracker;

// Set the dimension value for index 1. (Book Dimension)
[tracker setCustom:1 dimension:@"Book Name"];

// Set the dimension value for index 2. (Chapter Dimension)
[tracker setCustom:2 dimension:@"Chapter Name"];

// Set the dimension value for index 3. (Page Number)
[tracker setCustom:3 dimension:@"Page Number"];

// Dimension value is associated and sent with this hit.
[tracker sendView:@"Book Reader"];

You can have up to 20 custom dimensions set which should be plenty. 您最多可以设置20个自定义尺寸。

There is a good example for the iOS SDK v2.0 on Google's docs Google的文档中有一个很好的iOS SDK v2.0示例

Please be aware that Google have recently released Google Analytics SDK for iOS v3.0 Beta which you might want to use instead. 请注意,Google最近发布了适用于iOS v3.0 Beta的Google AnalyticsSDK ,您可能希望使用它。 Some of the method names have changed. 一些方法名称已更改。

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

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