简体   繁体   English

如何跟踪用户在Google Analytics屏幕上花费的时间

[英]how to track that how much time user spent on a screen Google Analytics

I am trying to use Google Analytics in my iOS app. 我正在尝试在我的iOS应用中使用Google Analytics。 I have tracked the events and screens. 我跟踪了事件和屏幕。 I want to track the time user spent on specific screens. 我想跟踪用户在特定屏幕上花费的时间。 How I can achieve this? 我怎么能做到这一点?

When it comes to Google Analytics I like to be creative. 谈到谷歌分析,我喜欢有创意。 Here's my possible solution: 这是我可能的解决方案:

- (void)viewDidAppear
{
 _startingTime = [NSDate date];

- (void)viewWillDisappear:(BOOL)animated {
 _endingTime = [NSDate date];
 NSTimeInterval distanceBetweenDates = [_startingTime timeIntervalSinceDate:_endingTime];
 NSInteger minutesBetweenDates = distanceBetweenDates / 60;

Then, you might use Screens to send the data to your reports. 然后,您可以使用“ 屏幕”将数据发送到报告。

id tracker = [[GAI sharedInstance] defaultTracker];

[tracker set:kGAIScreenName
       value:@"Home Screen %d", minutesBetweenDates];

[tracker send:[[GAIDictionaryBuilder createScreenView] build]];

For more precision on the time interval you might be interested in this method . 为了在时间间隔上获得更高的精度,您可能对此方法感兴趣。

Alternatively, you may use Events to achieve the same objective. 或者,您可以使用事件来实现相同的目标。

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

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