Google 애널리틱스 목표 추적을 사용하지 않는 것에 대해 많은 의문점이 있음을 알고 있습니다. 나는 나의 질문을 게시하기 전에 숙제를하고 그들 중 많은 것을 읽었다. https://developers.google.com/analytics/devguides/collection/analyticsjs/eventsGoogle 애널리틱스 목표 추적 안됨
나는 모두를 통해 코드를 구현하려
<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-xxxxxxxxxxx-x', 'mywebsite.com');
ga('send', 'pageview');
</script>
analytics.js 스 버전을 사용하고 있습니다 :
여기 이것은 내가 내 코드를 작성하는 데 사용되는 문서입니다 ... 내 문제입니다 순수한 자바 스크립트와 jQuery가 있지만 둘 다 작동하지 않는 것 같습니다.
링크를 추적 할 수있는 :
<a href="/contact-us-fivefive/" id="cta-footer-btn">Get In Touch Today</a>
의 jQuery 방법 :
<script>
var downloadLink = document.getElementById('cta-footer-btn');
addListener(downloadLink, 'click', function() {
ga('send', 'event', 'CTA_footer', 'contact_footer');
});
/**
* Utility to wrap the different behaviors between W3C-compliant browsers
* and IE when adding event handlers.
*
* @param {Object} element Object on which to attach the event listener.
* @param {string} type A string representing the event type to listen for
* (e.g. load, click, etc.).
* @param {function()} callback The function that receives the notification.
*/
function addListener(element, type, callback) {
if (element.addEventListener) element.addEventListener(type, callback);
else if (element.attachEvent) element.attachEvent('on' + type, callback);
}
</script>
을 둘 것 :
<script type="text/javascript" src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#cta-footer-btn').on('click', function() {
ga('send', 'event', 'CTA_footer', 'contact_footer');
});
});
</script>
가 나는 또한 JS 순수한 접근 방식은 제시되지 시도 다음은 내 코드입니다 링크 클릭 수를 추적하십시오.
이것이 작동하지 않는 이유나 제안은 크게 감사하겠습니다.
감사합니다.
초기 페이지가로드 된 후 언젠가 # cta-footer-btn이 변경되는 경우 (내용은 아니지만 ID가있는 새 요소가 생성 된 경우), 함수를 클릭에 다시 바인딩해야합니다 id가있는 요소의 이벤트이거나 새 요소에 대해 작동하지 않습니다. – artfuldev
모두 잘되고 잘 작동합니다. 대단히 감사합니다. 겐신! :) – BustedSanta