From 85a7a6fb108357853ea1d5b9cc5e598f493eb165 Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Tue, 17 Jul 2012 13:06:24 -0700 Subject: Added tracking for response time. --- js/mapspecs.js | 56 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 26 deletions(-) (limited to 'js/mapspecs.js') diff --git a/js/mapspecs.js b/js/mapspecs.js index 662d47c..6d3e4af 100644 --- a/js/mapspecs.js +++ b/js/mapspecs.js @@ -33,6 +33,8 @@ var jsonmapdata = new Object; //var jsonmapdata.solutions = new Array(); var mapType; // 1 = simple, 2 = normal, ...; used for mixpanel tracking +var pressedGoTime = 0; + // function loadAllSolutions() { // for(var i in jsonmapdata.solutions) { // } @@ -180,35 +182,22 @@ function getmapdata(mapid) { solution[mapid] = '.'; updateDsp(mapid, 'dspWalls', blocks[mapid]+" walls"); - - //document.getElementById(mapid+',dspWalls').innerHTML = " "+blocks[mapid]+" walls"; - //document.getElementById(mapid+',dspWalls').innerHTML = blocks[mapid]; } function doSend(mapid) { if (solution[mapid] == undefined) { getmapdata(mapid); } + + pressedGoTime = new Date().getTime(); reqstr = "&mapcode="+mapdata[mapid].code; reqstr += "&mapid="+mapid; reqstr += "&solution="+solution[mapid]; - //document.getElementById('dispdo').innerHTML = "http://mazetd.4xg.net/do.php?r=getpath"+reqstr - ajax.requestFile = "do.php?challengeID="+challengeID+"&isChallenge="+isChallenge+"&r=getpath"+reqstr; //prepare strdata ajax.onCompletion = request_path_done; // specify function to be executed on response ajax.runAJAX(); - - var speedbox = document.getElementById(mapid+',speed'), - speed = speedbox.options[speedbox.selectedIndex].text, - mute = !checkSound(mapid); - mixpanel.track('click go', { - 'speed': speed, - 'mute': mute, - 'mapid': mapid, - 'type': mapType - }); } function requestSol(mapID) { @@ -265,19 +254,25 @@ function resetwalls(mapid) { } function request_path_done() { - //document.getElementById('mapdisplay').innerHTML = ajax.response; - //if (ajax.response == undefined) return; - - if (typeof(JSON) == 'undefined') { - text = ajax.response; - var JO = !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(text.replace(/"(\\.|[^"\\])*"/g, ''))) && eval('(' + text + ')'); - //mapdata[mapid] = eval(document.getElementById(mapid+',mapdata').innerHTML); - } else { - var JO = JSON.parse(ajax.response); - } + var JO = decryptJSON(ajax.response); mapjson[JO.mapid] = JO; + var speedbox = document.getElementById(mapid+',speed'), + speed = speedbox.options[speedbox.selectedIndex].text, + mute = !checkSound(mapid); + + nowTime = new Date().getTime(); + var responseTime = nowTime - pressedGoTime; + + mixpanel.track('click go', { + 'speed': speed, + 'mute': mute, + 'mapid': JO.mapid, + 'type': mapType, + 'response time': responseTime + }); + if (JO.scores) updateDsp(JO.mapid, 'dspScore', JO.scores); @@ -300,10 +295,11 @@ function request_path_done() { ajax.runAJAX();// Do it! } +// Used at the start // Force score update. function updateScoresReq(mapid, type) { //Get score update. - ajax.requestFile = "do.php?checkachieve=true&r=getscores&mapid="+mapid; //prepare strdata + ajax.requestFile = "do.php?r=getscores&mapid="+mapid; //prepare strdata ajax.onCompletion = updateScoresGet; // Specify function to be executed on response. ajax.runAJAX();// Do it! mapType = type; @@ -313,6 +309,14 @@ function updateScoresGet() { updateDsp(JO.mapid, 'dspScore', JO.scores); } +function reqScoresDone() { + + var JO = decryptJSON(ajax.response); + updateDsp(JO.mapid, 'dspScore', JO.scores); +} +//function addscorepage + + function decryptJSON(text) { if (typeof(JSON) == 'undefined') { var JO = !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(text.replace(/"(\\.|[^"\\])*"/g, ''))) && eval('(' + text + ')'); -- cgit v1.2.3