[ Index ]
 

Code source de phpMyVisites 2.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/plugins/clickheat/libs/js/ -> clickheat.js (source)

   1  /**
   2  ClickHeat : Suivi et analyse des clics / Tracking and clicks analysis
   3  
   4  @author Yvan Taviaud - LabsMedia - www.labsmedia.com/clickheat/
   5  @since 27/10/2006
   6  @update 01/03/2007 - Yvan Taviaud : correctif Firefox (Károly Marton)
   7  @update 23/03/2007 - Yvan Taviaud : protection de 2 secondes entre chaque clic, et X clics maximum par page
   8  @update 18/05/2007 - Yvan Taviaud : suppression de clickHeatPage, ajout de clickHeatGroup et clickHeatSite
   9  @update 27/08/2007 - Yvan Taviaud : changement du système de débug
  10  @update 28/09/2007 - Yvan Taviaud : ajout de quelques messages de débug
  11  
  12  Tested under :
  13  Windows 2000 - IE 6.0
  14  Linux - Firefox 2.0.0.1, Konqueror 3.5.5, IE 7
  15  */
  16  
  17  /** Main function */
  18  function catchClickHeat(e)
  19  {
  20      /** Use a try{} to avoid showing errors to users */
  21      try
  22      {
  23          showClickHeatDebug('Gathering click data...');
  24          if (clickHeatQuota == 0)
  25          {
  26              showClickHeatDebug('Click not logged: quota reached');
  27              return true;
  28          }
  29          if (clickHeatGroup == '')
  30          {
  31              showClickHeatDebug('Click not logged: group name empty (clickHeatGroup)');
  32              return true;
  33          }
  34          /** Look for the real event */
  35          if (e == undefined)
  36          {
  37              e = window.event;
  38              c = e.button;
  39              element = e.srcElement;
  40          }
  41          else
  42          {
  43              c = e.which;
  44              element = null;
  45          }
  46          if (c == 0)
  47          {
  48              showClickHeatDebug('Click not logged: no button pressed');
  49              return true;
  50          }
  51          /** Filter for same iframe (focus on iframe => popup ad => close ad => new focus on same iframe) */
  52          if (element != null && element.tagName.toLowerCase() == 'iframe')
  53          {
  54              if (element.sourceIndex == clickHeatLastIframe)
  55              {
  56                  showClickHeatDebug('Click not logged: same iframe (happens when a click on iframe occured opening a popup and popup is closed)');
  57                  return true;
  58              }
  59              clickHeatLastIframe = element.sourceIndex;
  60          }
  61          else
  62          {
  63              clickHeatLastIframe = -1;
  64          }
  65          var x = e.clientX;
  66          var y = e.clientY;
  67          var w = clickHeatDocument.clientWidth != undefined ? clickHeatDocument.clientWidth : window.innerWidth;
  68          var h = clickHeatDocument.clientHeight != undefined ? clickHeatDocument.clientHeight : window.innerHeight;
  69          var scrollx = window.pageXOffset == undefined ? clickHeatDocument.scrollLeft : window.pageXOffset;
  70          var scrolly = window.pageYOffset == undefined ? clickHeatDocument.scrollTop : window.pageYOffset;
  71          /** Is the click in the viewing area? Not on scrollbars. Still the problem exists for FF on the horizontal scrollbar */
  72          if (x > w || y > h)
  73          {
  74              showClickHeatDebug('Click not logged: out of document (should be a click on scrollbars)');
  75              return true;
  76          }
  77          /** Check if last click was at least 1 second ago */
  78          clickTime = new Date();
  79          if (clickTime.getTime() - clickHeatTime < 1000)
  80          {
  81              showClickHeatDebug('Click not logged: at least 1 second between clicks');
  82              return true;
  83          }
  84          clickHeatTime = clickTime.getTime();
  85          if (clickHeatQuota > 0)
  86          {
  87              clickHeatQuota = clickHeatQuota - 1;
  88          }
  89          params = 's=' + clickHeatSite + '&g=' + clickHeatGroup + '&x=' + (x + scrollx) + '&y=' + (y + scrolly) + '&w=' + w + '&b=' + clickHeatBrowser + '&c=' + c + '&random=' + Date();
  90          showClickHeatDebug('Ready to send click data...');
  91          /** Local request? Try an ajax call */
  92          var sent = false;
  93          if (clickHeatServer.substring(0, 4) != 'http')
  94          {
  95              var xmlhttp = false;
  96              try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  97              catch (e)
  98              {
  99                  try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");    }
 100                  catch (oc) { xmlhttp = null; }
 101              }
 102              if (!xmlhttp && typeof XMLHttpRequest != undefined) xmlhttp = new XMLHttpRequest();
 103              if (xmlhttp)
 104              {
 105                  if (clickHeatDebug == true)
 106                  {
 107                      xmlhttp.onreadystatechange = function()
 108                      {
 109                          if (xmlhttp.readyState == 4)
 110                          {
 111                              if (xmlhttp.status == 200)
 112                              {
 113                                  showClickHeatDebug('Click recorded at ' + clickHeatServer + ' with the following parameters:<br />x = ' + (x + scrollx) + ' (' + x + 'px from left + ' + scrollx + 'px of horizontal scrolling)<br />y = ' + (y + scrolly) + ' (' + y + 'px from top + ' + scrolly + 'px of vertical scrolling)<br />width = ' + w + '<br />browser = ' + clickHeatBrowser + '<br />click = ' + c + '<br />site = ' + clickHeatSite + '<br />group = ' + clickHeatGroup + '<br /><br />Server answer: ' + xmlhttp.responseText);
 114                              }
 115                              else if (xmlhttp.status == 404)
 116                              {
 117                                  showClickHeatDebug('click.php was not found at: ' + (clickHeatServer != '' ? clickHeatServer : '/clickheat/click.php') + ' please set clickHeatServer value');
 118                              }
 119                              else
 120                              {
 121                                  showClickHeatDebug('click.php returned a status code ' + xmlhttp.status + ' with the following error: ' + xmlhttp.responseText);
 122                              }
 123                          }
 124                      }
 125                  }
 126                  xmlhttp.open('GET', clickHeatServer + '?' + params, true);
 127                  xmlhttp.setRequestHeader('Connection', 'close');
 128                  xmlhttp.send(null);
 129                  sent = true;
 130              }
 131          }
 132          if (sent == false)
 133          {
 134              /** This test is needed, as it includes the call to click.php in the iframe */
 135              if (clickHeatDebug == true)
 136              {
 137                  showClickHeatDebug('Click recorded at ' + clickHeatServer + ' with the following parameters:<br />x = ' + (x + scrollx) + ' (' + x + 'px from left + ' + scrollx + 'px of horizontal scrolling)<br />y = ' + (y + scrolly) + ' (' + y + 'px from top + ' + scrolly + 'px of vertical scrolling)<br />width = ' + w + '<br />browser = ' + clickHeatBrowser + '<br />click = ' + c + '<br />site = ' + clickHeatSite + '<br />group = ' + clickHeatGroup + '<br /><br />Server answer:<br />' + '<iframe src="' + clickHeatServer + '?' + params + '" width="400" height="30"></iframe>');
 138              }
 139              else
 140              {
 141                  var clickHeatImg = new Image();
 142                  clickHeatImg.src = clickHeatServer + '?' + params;
 143              }
 144          }
 145      }
 146      catch(e)
 147      {
 148          showClickHeatDebug('An error occurred while processing click (Javascript error): ' + e.message);
 149      }
 150      return true;
 151  }
 152  
 153  var clickHeatGroup = '';
 154  var clickHeatSite = '';
 155  var clickHeatServer = '';
 156  var clickHeatLastIframe = -1;
 157  var clickHeatTime = 0;
 158  var clickHeatQuota = -1;
 159  var clickHeatBrowser = '';
 160  var clickHeatDocument = '';
 161  var clickHeatDebug = (window.location.href.search(/debugclickheat/) != -1);
 162  function initClickHeat()
 163  {
 164      /** Debug Window */
 165      if (clickHeatDebug == true)
 166      {
 167          document.body.innerHTML = document.body.innerHTML + '<div id="clickHeatDebuggerDiv" style="padding:5px; display:none; position:absolute; top:10px; left:10px; border:1px solid #888; background-color:#eee;"><strong>ClickHeat debug: <a href="#" onmouseover="document.getElementById(\'clickHeatDebuggerDiv\').style.display = \'none\'; return false">Rollover to close</a></strong><br /><br /><span id="clickHeatDebuggerSpan"></span></div>';
 168      }
 169  
 170      if (clickHeatGroup == '' || clickHeatServer == '')
 171      {
 172          showClickHeatDebug('ClickHeat NOT initialised: either clickHeatGroup or clickHeatServer is empty');
 173          return false;
 174      }
 175  
 176      /** If current website has the same domain as the script, we remove the domain so that the call is made using Ajax */
 177      domain = window.location.href.match(/http:\/\/[^/]+\//);
 178      if (domain != null && clickHeatServer.substring(0, domain[0].length) == domain[0])
 179      {
 180          clickHeatServer = clickHeatServer.substring(domain[0].length - 1, clickHeatServer.length)
 181      }
 182      /** Add onmousedown event */
 183      if (typeof document.onmousedown == 'function')
 184      {
 185          currentFunc = document.onmousedown;
 186          document.onmousedown = function(e) { catchClickHeat(e); return currentFunc(e); }
 187      }
 188      else
 189      {
 190          document.onmousedown = catchClickHeat;
 191      }
 192      /** Add onfocus event on iframes (mostly ads) - Does NOT work with Gecko-powered browsers, because onfocus doesn't exist on iframes */
 193      iFrames = document.getElementsByTagName('iframe');
 194      for (i = 0; i < iFrames.length; i++)
 195      {
 196          if (typeof iFrames[i].onfocus == 'function')
 197          {
 198              currentFunc = iFrames[i].onfocus;
 199              iFrames[i].onfocus = function(e) { catchClickHeat(e); return currentFunc(e); }
 200          }
 201          else
 202          {
 203              iFrames[i].onfocus = catchClickHeat;
 204          }
 205      }
 206      /** Preparing main variables */
 207      clickHeatDocument = document.documentElement != undefined && document.documentElement.clientHeight != 0 ? document.documentElement : document.body;
 208      /** Also the User-Agent is not the best value to use, it's the only one that gives the real browser */
 209      var b = navigator.userAgent != undefined ? navigator.userAgent.toLowerCase().replace(/-/g, '') : '';
 210      clickHeatBrowser = b.replace(/iceweasel/, 'firefox').replace(/^.*(firefox|kmeleon|safari|msie|opera).*$/, '$1');
 211      if (b == clickHeatBrowser || clickHeatBrowser == '') clickHeatBrowser = 'unknown';
 212      showClickHeatDebug('ClickHeat initialised with:<br />site = ' + clickHeatSite + '<br />group = ' + clickHeatGroup + '<br />server = ' + clickHeatServer + '<br />quota = ' + (clickHeatQuota == -1 ? 'unlimited' : clickHeatQuota) + '<br /><br />browser = ' + clickHeatBrowser);
 213  }
 214  /**
 215  * Shows a debug string
 216  **/
 217  function showClickHeatDebug(str)
 218  {
 219      if (clickHeatDebug == true)
 220      {
 221          document.getElementById('clickHeatDebuggerSpan').innerHTML = str;
 222          document.getElementById('clickHeatDebuggerDiv').style.display = 'block';
 223      }
 224  }


Généré le : Mon Nov 26 14:10:01 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics