Track Download Links Using jQuery and Google Analytics

Once you’ve got Google Analytics working, you can use jQuery to easily track other links on your site, such as download links.

First add the following anywhere after you load jQuery:

<script type="text/javascript">
$(document).ready(function() {
    $('.track_link').click(function() {
        pageTracker._trackPageview($(this).attr('href'));
        return true;
    });
});
</script>

Then just add class="track_link" to any links you wish to track. For example:

<a href="/download/my_file.zip" class="track_link">Download my_file.zip</a>

Remember to separate CSS class names with spaces if you already have some:

<a href="/download/my_file.zip" class="my_other_css_class track_link">Download my_file.zip</a>

Comments are closed.