0

I use code from google analytic home page with remote ga.js. All works cool beside one thing: Avg. Time on Page. I close page in browser but my session leaves active. I want to stop session from JS handy. I try search but nothing. How can i do it ?

UPDATE

You miss me. I know that moment when say to GA that session is closed. My app plays in UIWebView on iOs. So I want to send termination when app is exited. It's so simple. Isn't ?

Thanks

Anton Gaenko
  • 8,929
  • 6
  • 44
  • 39

3 Answers3

1

JavaScript does not know the difference between a page close and a page refresh and a page navigation away. Plus there is no reliable way with JavaScript to send the information to the server when the unload event is called.

epascarello
  • 204,599
  • 20
  • 195
  • 236
  • i know it. I want send a message to GA server to terminate current session. Fe, _gaq.push(['_stop']). – Anton Gaenko Apr 09 '12 at 13:50
  • JavaScript can not do it, it has no clue if the browser is closing. – epascarello Apr 09 '12 at 14:32
  • That's not entirely true @epascarello, it has a clue its just not consistent in all browsers and situations. http://stackoverflow.com/questions/6622461/how-to-capture-browser-close-event-in-javascript – shanabus Apr 09 '12 at 14:35
  • @shanabus onbeforeunload fires for any event that causes the page to leave, refresh, exit. You can not tell the difference. You can send a ping to the server from here, but it is a race condition with the page closing and the call going out. I know this, I code this in my application with my custom logging framework. – epascarello Apr 09 '12 at 16:11
1

Use javascript to delete the _utmb cookie:

Cookies Set By Google Analytics

function del_cookie(name) {
   document.cookie = name + '=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
} 

del_cookie("_utmb");
0

You are looking for the true time on site/page Have a look to the strategy proposed by Savio

Open SEO
  • 1,682
  • 14
  • 16