문제

I have some HTML links which I can't easily modify, but I need to put some tracking code in. An example of the code is:

onClick="_gaq.push(['_trackEvent', 'Click-on', 'Compare', 'Main', 11, false]);"

So, say my link has the class "compare", how do I convert his code into a function/event listener so I don't have to modify my links HTML?

Thanks

Dave

도움이 되었습니까?

해결책

Not sure i understood the question, but if you need to capture the class and assign an event to it, you can use jQuery like this (you have to add the jQuery script to your head tag first):

<script src=”//code.jquery.com/jquery-1.7.2.js”></script>

<script type="text/javascript">
                jQuery(document).ready(function () {
                jQuery('.compare').click( function() {
                                _gaq.push(['_trackEvent', 'Click-on', 'Compare','Main']);
                });           

});
</script>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top