Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

like image 818
Geri Borbás Avatar asked Sep 17 '13 16:09

Geri Borbás


People also ask

How do I track sessions in Google Analytics?

Where can I find sessions in Google Analytics? To find out how many sessions your site had in the last 30 days, go to the Audience tab in the left hand column of Google Analytics, then click on Overview, then Sessions.

Is there a session ID in Google Analytics?

Both the session ID and session number are associated with each event in a session automatically via gtag. js and the Google Analytics for Firebase SDK. However, the identifier is not included automatically in events from Measurement Protocol or Data Import.

Is session the same as visit for Google Analytics?

Sessions in Google Analytics are defined as the total number of visits to your site — including both new and repeat visits. So that same person who visited your site 100 times on the same device is counted as one user, but 100 sessions.


1 Answers

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"];
}
like image 86
Rob Avatar answered Oct 20 '22 10:10

Rob