From f0786bbec1e320dbc007cb5340024c47154f9038 Mon Sep 17 00:00:00 2001 From: Piotr Mitros Date: Fri, 13 Jan 2012 23:44:59 -0500 Subject: [PATCH] Page close event logged --- js/video_player.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/js/video_player.js b/js/video_player.js index f898b6e469..1e5b843147 100644 --- a/js/video_player.js +++ b/js/video_player.js @@ -1,5 +1,19 @@ // Things to abstract out to another file +var close_event_logged = false; + +function log_close() { + close_event_logged = "waiting"; + log_event('page_close', {}); + // Google Chrome will close without letting the event go through. + // This causes the page close to be delayed until we've hit the + // server. + while(close_event_logged != "done") { + } +} + +window.onbeforeunload = log_close; + function getCookie(name) { var cookieValue = null; if (document.cookie && document.cookie != '') { @@ -199,15 +213,6 @@ function videoDestroy() { } function log_event(e, d) { - //$("#eventlog").append("
"); - //$("#eventlog").append(JSON.stringify(e)); - - // TODO: Decide if we want seperate tracking server. - // If so, we need to resolve: - // * AJAX from different domain (XMLHttpRequest cannot load http://localhost:7000/userlog. Origin http://localhost:8000 is not allowed by Access-Control-Allow-Origin.) - // * Verifying sessions/authentication - - /*window['console'].log(JSON.stringify(e));*/ $.get("/event", { "event_type" : e, @@ -215,6 +220,9 @@ function log_event(e, d) { "page" : document.URL }, function(data) { + if (close_event_logged == "waiting") { + close_event_logged == "done"; + } }); }