iossessiongoogle-analyticssdk

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

Since I implemented, every session is measured 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)


Solution

  • 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.

    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.

    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 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"];
    }