2012-10-12 2 views

답변

0

@ user1494396에서 만료; 과 같이 정규식에서 페이지 이름을 전달하기 위해 비동기 추적 코드를 리팩토링 :

(function (window) { 
    function cleanQs() { 
     if (!window.location.search) { 
      return window.location.pathname; 
     } 
     var locSearchArr = window.location.search.match(/[^\=\&\?]+=[^\=\&\?]+/g); 
     var locPathName = window.location.pathname; 
     if (locSearchArr && locSearchArr.length > 0) { 
      locPathName += "?" + locSearchArr.join("&"); 
     } 
     return locPathName; 
    } 

    var _gaq = window._gaq || (window._gaq = []); 
    window._gaq.push(['_setAccount', 'UA-XXXXX-X']); 
    window._gaq.push(['_trackPageview', cleanQs()]); 
})(this); 

(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'; 
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); 
})(); 

참조 : 코드

  • JSFiddle Demo of this code
  • 의 기초에 대한 추가 정보를 원하시면

    0

    "http://www.domain.com/index.asp?a=test&b=test&c=&d=test".match(/[^\=\&\?]+=[^\=\&\?]+/g)는 [ "B = 시험 ','D = 시험 ','A = 시험"]의 배열을 반환한다.

    관련 문제