简体   繁体   English

适用于iOS的Google Analytics API v3的会话控制?

[英]Session control with Google Analytics API v3 for iOS?

I just replaced GA implementation with API v3, and found this useful session managing feature: https://developers.google.com/analytics/devguides/collection/ios/v3/sessions 我刚刚用API v3替换了GA实现,并发现了这个有用的会话管理功能: https//developers.google.com/analytics/devguides/collection/ios/v3/sessions

Since I implemented, every session is measured 00:00:00. 自从我实施以来,每个会话的测量时间为00:00:00。

Did anybody managed to use this? 有没有人设法使用它? Or something is messed in my client code. 或者在我的客户端代码中出现了一些问题。


(the time interval based session calculations gives inaccurate data for my needs) (基于时间间隔的会话计算为我的需求提供了不准确的数据)

I was having the same problem and the issue was that once the start session value was applied it was applied to all future analytic events. 我遇到了同样的问题,问题是一旦应用了启动会话值,它就会应用于所有未来的分析事件。 This would mean that every event you send would start a new session and as a result would make all your sessions 0:00:00. 这意味着您发送的每个事件都将启动一个新会话,因此会使您的所有会话都在0:00:00。

Note: This solution was given to my by another stack overflow but I can't seem to find it now. 注意:这个解决方案是通过另一个堆栈溢出给我的,但我现在似乎无法找到它。 I am guessing it wasn't an iOS implementation of google analytics. 我猜它不是谷歌分析的iOS实现。

The solution that worked for me was to set the session variable to nil after calling start so that start is not set for all future analytic hits. 对我有用的解决方案是在调用start之后将会话变量设置为nil,以便不为所有将来的分析命中设置start。

{
    // Start the session, only once.
    [tracker set:kGAISessionControl
            value:@"start"];

    // Set this after the session start has been sent. Only needs to be set once but you must    be sure that two starts are not sent in a row or you will end up with 0:00:00 sessions.
    [tracker set:kGAISessionControl
           value:nil]; 
}

...

{
    // Call when the session ends.
    [tracker set:kGAISessionControl
           value:@"end"];
}

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

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