1/** 2 * Statistics script 3 */ 4var plugin_statistics = { 5 id: null, 6 7 /** 8 * initialize the script 9 * 10 * @param id string - urlencoded page id 11 */ 12 init: function(id){ 13 plugin_statistics.id = id; 14 var now = new Date(); 15 16 // load visitor cookie 17 var uid = DokuCookie.getValue('plgstats'); 18 if(!uid){ 19 uid = now.getTime()+'-'+Math.floor(Math.random()*32000); 20 DokuCookie.setValue('plgstats',uid); 21 if(!DokuCookie.getCookie(DokuCookie.name)){ 22 uid = ''; 23 } 24 } 25 26 // log the visit 27 var img = new Image(); 28 img.src = DOKU_BASE+'lib/plugins/statistics/log.php'+ 29 '?rnd='+now.getTime()+ 30 '&p='+id+ 31 '&r='+encodeURIComponent(document.referrer)+ 32 '&sx='+screen.width+ 33 '&sy='+screen.height+ 34 '&vx='+window.innerWidth+ 35 '&vy='+window.innerHeight+ 36 '&uid='+uid+ 37 '&js=1'; 38 39 // attach event 40 addInitEvent(function(){ 41 var links = getElementsByClass('urlextern',null,'a'); 42 for(var i=0; i<links.length; i++){ 43 addEvent(links[i],'click',function(e){plugin_statistics.logExternal(e)}); 44 } 45 }); 46 }, 47 48 /** 49 * Log clicks to external URLs 50 */ 51 logExternal: function(e){ 52 var now = new Date(); 53 var img = new Image(); 54 img.src = DOKU_BASE+'lib/plugins/statistics/log.php'+ 55 '?rnd='+now.getTime()+ 56 '&ol='+encodeURIComponent(e.target.href)+ 57 '&p='+plugin_statistics.id; 58 plugin_statistics.pause(500); 59 return true; 60 }, 61 62 /** 63 * Pause the script execution for the given time 64 */ 65 pause: function(ms){ 66 var now = new Date(); 67 var exitTime = now.getTime()+ms; 68 while(true){ 69 now = new Date(); 70 if(now.getTime()>exitTime){ 71 return; 72 } 73 } 74 } 75} 76