2014-03-03 3 views
1

난 그냥 [전자 헤드] 토륨 다음 '유니버설'웹 로그 분석 코드를 추가 한 [1] 표준을 설정하는 방법을 찾을 수없는, 보편적 인 아웃 바운드 추적 이벤트 :트랙 아웃 바운드 링크가

<!-- Google Analytics --> 
<script> 
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ 
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), 
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) 
})(window,document,'script','//www.google-analytics.com/analytics.js','ga'); 

ga('create', 'UA-xxxx-Y', 'auto'); 
ga('send', 'pageview'); 

</script> 
<!-- End Google Analytics --> 

이것은 무엇을 제안되었다된다

var trackOutboundLink = function(url) { 

     _gaq.push(['_trackEvent', 'Outbound', 'Click', this.href]); 
     setTimeout('document.location = "' + this.href + '"', 100); 
     return false; 
} 

이 보편적 아웃 바운드 이벤트를 추적 할 수 있습니까? 모든 이벤트를 추적하고 어디에 배치해야합니까 - 헤드 또는 바디 닫기 태그 이전에?

개별 범용 이벤트를 추적하는 올바른 구문입니까?

onclick="trackOutboundLink('/WEBSITE/www.something.com') 

답변

0

범용 웹 로그 분석 이벤트 추적 ga('send', 'event', 'button', 'click', 'nav buttons', 4);

이 변경되었습니다.

new event tracking code입니다 :

ga('send', 'event', 'category', 'action', 'opt_label', opt_value); // value is a number 

그래서 코드를 다시 작성할 그 결과는 다음과 같습니다

var trackOutboundLink = function(url) { 

     ga('send', 'event','Outbound', 'Click', this.href); 
     setTimeout('document.location = "' + this.href + '"', 100); 
     return false; 
} 

그럼 당신은 onclick=와 함께 링크에 첨부 또는 자바 스크립트 이벤트 리스너를 만들 수 있습니다 . 나는 보통 HTML과 JS를 혼합하여 폼에 머물러 있기 때문에 보통 이벤트 리스너를 사용한다.

+0

네가 나열한 기능을 복사했는데 조금 이상해 보였다. 나는이 jsfiddle http://jsfiddle.net/nicomiceli/CRSBc/에서 코드를 다시 작성하고 console.log를 주석 처리합니다. 디버거 용으로 추가했습니다. (그냥 jquery를 사이트에 가지고 있는지 확인하십시오.) – NicoM

1

자료 : 정확하게 추적하지 않기 때문에 https://github.com/tomfuertes/jquery-universal-analytics/blob/master/src/jquery.universal-analytics.js

$(document).on('mousedown', 'a', function() { 
    if ((this.protocol === 'http:' || this.protocol === 'https:') && this.hostname.indexOf(document.location.hostname) === -1) { 
    ga('send', 'event', 'Outbound', this.hostname, this.pathname); 
    } 
}); 
+0

이것은 jQuery를 요구 사항으로 받아 들일 수 있다고 가정 할 때 트릭을 멋지게 보이고 & 받아 들여야합니다. –

0

당신은 .on('MouseDown')를 사용하지 않습니다. 더 느린 연결에서 여전히 클릭 이벤트를 놓치고 사용자가 마우스를 놓고 드래그하면 가짜 클릭을보고합니다.

NikZilla provides an answer here.on('click')과 jquery 및 Universal Analytics hitCallback function을 사용하십시오. 나는 모든 아웃 바운드 링크 as referenced in another answer을 추적하는 기능과 결합했습니다.

<script> 
$(document).on('click', 'a', function (e) { 
    if ((this.protocol === 'http:' || this.protocol === 'https:') && this.hostname.indexOf(document.location.hostname) === -1) { 
    var obj = $(this); 
    e.preventDefault(); 
    ga('send', 'event', 'Outbound', this.hostname, this.pathname, 0, { 
         'hitCallback': function() { 
          obj.off(e); 
          obj[0].click(); 
          } 
        }); 
    } 

}); 

</script>