Session duration for long running Apps

Sep 1, 2014 at 6:07 PM
Hello.
I don't know which is the best practise for my App; it's a game companion so I offer the possibility to keep it running in foreground for hours, as an option for the user. I'd like to know how ofter this functionality is used and how long users keep the App running.
Ho could I achieve this goal? I'm new to Analytics and I'm using the EasyTracker stuff, but all sessions seems to last for short periods (also my session which I know for sure last for hours...)
As a side note: I'm using Caliburn Micro and implemented a base ViewModel with the following override, which works fine:
 protected override void OnActivate()
        {
            GoogleAnalytics.EasyTracker.GetTracker().SendView(this.GetView().GetType().Name);
            base.OnActivate();
        }
Many thanks,
Lorenzo
Coordinator
Sep 2, 2014 at 6:41 PM
By default GA will end the session if it hasn't heard from the app in 30 minutes. However, you can change the default session time in the GA web portal for your properties.

As far as best practices in your app, you might consider forcing the session to end and start every time your app suspends and resumes respectively. To do this, you can call:
EasyTracker.GetTracker()..SetEndSession(true);
upon suspend and:
EasyTracker.GetTracker()..SetEndSession(false);
upon resume.

Additionally, this is only applied to the next log sent so you would also want to send a log immediately after calling SetEndSession.
For example:
EasyTracker.GetTracker().SendEvent("app", "suspend", null, 0);
Sep 3, 2014 at 6:19 PM
It sounds good, thank you very much!
I'll try it out immediately ;)
Sep 3, 2014 at 6:33 PM
Hi again.

I've found docs about the SetStartSession but not about SetEndSession; what exactly does it do and what is the difference between passing in true or false?
Sep 3, 2014 at 7:49 PM
Mayby I found the GA reference for this; is it right? Session Control
Coordinator
Sep 3, 2014 at 7:56 PM
Yes, this link explains what happens under the hood when you call SetStart/SetEndSession on the SDK.
Sep 3, 2014 at 8:14 PM
I was just trying it out in the emulator (using VS to send suspend/resume) but the realtime in GS shows my session still active even if i call SendEndSession(true): is it the expected behaviour?

In your previous post you wrote
EasyTracker.GetTracker()..SetEndSession(true);

EasyTracker.GetTracker()..SetEndSession(false);

but no SetStartSession, so I wrote my code this way:
        protected async override void OnSuspending(object sender, SuspendingEventArgs e)
        {
            GoogleAnalytics.EasyTracker.GetTracker().SetEndSession(true);
            GoogleAnalytics.EasyTracker.GetTracker().SendEvent("app","suspend",null,0);
            base.OnSuspending(sender, e);
        }

        protected async override void OnResuming(object sender, object e)
        {
            GoogleAnalytics.EasyTracker.GetTracker().SetEndSession(false);
            base.OnResuming(sender, e);
        }
Is it right or should I have to use SendStartSession ? Actually I can't undesrtand :(
Sep 3, 2014 at 9:27 PM
Ok, from the source hopefully I understood what happens
SetStartSession and SetEndSession only set a variable which is evaluated and returns the enum SessionControl (which can be Start, End or None).
Every method call to GA check SessionControl value and the session is closed forcedly if, and only if, SetEndSession has been previously passed "true"; conversly the session is forcedly (re)open if, and only if, SetStartSession has been previously passed "true" value.

Only one thing missing: the call to SetEndSession(false) during OnResuming is necessary or just to be sure not to have unexpected values?

Thank the the patience ;)