﻿  onload = function(){
  var tracker = 'UA-17536582-1';
  var domain = 'pushchairs-prams.org.uk';
  var code = "var _gaq = _gaq||[];_gaq.push(['_setAccount', '" + tracker + "'],['_setDomainName', '" + domain + "'],['_trackPageview']);(function() {var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);})();";
  var newScript = document.createElement('script');
  newScript.type = 'text/javascript';
  newScript.innerHTML = code;
  document.body.insertBefore(newScript, document.body.firstChild);
  var allA = document.getElementsByTagName('a');
  var domainRegex = new RegExp ( "http:\/\/" + domain.replace(".","\\.") , "i");
  if ( typeof(allA) != "undefined") {
    for (i = 0; i < allA.length; i++) {
      var newAttr = null;
      var newAttrText = null;
      var oldAttr = null;
      var href = allA[i].href;
      if (!href.match(domainRegex)) {
        newAttrText = href.replace(/http:\/\//i,"");
        if (newAttrText.length > 0) {
          if (allA[i].getAttribute("onclick") != null) {
            oldAttr = allA[i].getAttribute("onclick") + ";";
          }
          newAttr = document.createAttribute("onclick");
          if (oldAttr == null) newAttr.nodeValue = "_gaq.push(['_trackPageview', 'out/" + newAttrText + "'])";
          else newAttr.nodeValue = oldAttr + "_gaq.push(['_trackPageview', 'out/" + newAttrText + "'])";
          allA[i].setAttributeNode(newAttr);
        }
      }
    }
  }
}
