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