Question

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

Was it helpful?

Solution

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top