Reputation: 3320
How can I keep a user's "session" active in google analytics? Such as for pages that hardly ever refresh (online games, virtual worlds).
Would just having the google analytics javascript run every few minutes work? What would be a good way to accomplish this?
The goal is for google to report a correct average time on site, and not loading a page for a while seems to tell google the session has ended.
Upvotes: 2
Views: 1508
Reputation: 2214
Session time in GA is tracked by the last pageview executed by visitor, so in order to get a correct pageview you may execute a virtual pageview every n seconds (simple js timer) or any other event you want (scroll for paticular area of your page, button click, etc.).
Take a look at this tutorial for details: http://services.google.com/analytics/breeze/en/v5/et_vpsv22_ad1_2/
This will give you more accurate data with visit length, but keep in mind, that those virtual pageviews would display as all other pageviews in your reports, so i order not to mess up the data you would want to create a separate profile by duplicating your existing one and filter out those virtual pageviews in the main one.
Alternatively, you can try to use event tracking (it works practically the same from the implemention point of view).
Upvotes: 1
Reputation:
You can use _setSessionCookieTimeout() :
_setSessionCookieTimeout()
_setSessionCookieTimeout(cookieTimeoutMillis)
Sets the new session cookie timeout in milliseconds. By default, session timeout is set to 30 minutes. Session timeout is used to compute visits, since a visit ends after 30 minutes of browser inactivity or upon browser exit. If you want to change the definition of a "session" for your particular needs, you can pass in the number of milliseconds to define a new value. This will impact the Visits reports in every section where the number of visits are calculated, and where visits are used in computing other values. For example, the number of visits will increase if you shorten the session timeout, and will decrease if you increase the session timeout. You can change the expiration timeout to 0 to indicate that this cookie should be deleted when the browser is closed.
_gaq.push(['_setSessionCookieTimeout', 1800000]);
Upvotes: 1