zwetan / as3-universal-analytics

Google Universal Analytics for AS3
Mozilla Public License 2.0
73 stars 11 forks source link

support for sessions #4

Open zwetan opened 9 years ago

zwetan commented 9 years ago

see Session Control parameter

few things

see How a session is defined in Analytics

zwetan commented 9 years ago

see wiki doc https://github.com/zwetan/as3-universal-analytics/wiki/TrackingDetailsAndTricks#session-management

maybe a helper for manual session

tracker.setOneTime( Tracker.SESSION_CONTROL, SessionControl.START );
tracker.screenview( "Home Screen" );

and a util class for automatic session management

private function onCreationComplete():void
{
    var na:NativeApplication = NativeApplication.nativeApplication;
    na.idleThreshold = 2 * 60; // In seconds -- the default is 5 minutes.
    na.addEventListener( Event.USER_IDLE, onUserIdle );
    na.addEventListener( Event.USER_PRESENT, onUserPresent );
)

private function onUserIdle( event:Event ):void
{
    tracker.setOneTime( Tracker.SESSION_CONTROL, SessionControl.END );
    tracker.event( "activity", "idle" );
}

private function onUserPresent( event:Event ):void
{
    tracker.setOneTime( Tracker.SESSION_CONTROL, SessionControl.START );
    tracker.event( "activity", "present" );
}
zwetan commented 9 years ago

also from doc

By default, Google Analytics will group hits that are received within 30 minutes of one another into the same session. This period is configurable at the property level.

we should add a session timeout in the config, default 30mn allow the user to override it

and so add a global timer which follow the logic of How a session is defined in Analytics

the timer need to be connected to the tracker and/or the sender so each time a hit is send we can reset the timer to 30mn (or other user defined time)

thje way to break the old session and start a new one should be as described

What happens if during a session to my site, Bob leaves open a page while he takes a 31-minute lunch break, then returns to continue browsing the site?

eg. use a Tracker.SESSION_CONTROL, SessionControl.START