Posts tagged ‘jQuery’

A little jQuery redundancy

It’s kind of absurd to think that one of our sites would be up while Google’s Libraries API is down, but there is a real possibility that the google domain name could be blocked in certain countries and in certain circumstances. So just to be safe, here’s a quick little snippet to make sure it’s loaded either way. Note, this assumes you have jQuery on your webserver.

1
2
3
4
5
6
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript">
if (typeof jQuery == 'undefined'){
    document.write(unescape("%3Cscript src='/js/jquery1.5.1.min.js' type='text/javascript'%3E%3C/script%3E"));
}
</script>

Add external link tracking with jQuery and Google Analytics

Quick and easy way to setup Google Analytics tracking for all links that open in a new window (typically external links that wouldn’t normally be tracked)… Note, this should be called from within $(document).ready or after all anchor tags have been added to the DOM.

1
2
3
4
5
6
$('a[target=_blank]').click(function(){
    try{
        _gaq.push(['_trackEvent', 'External Links', 'Click', $(this).attr('href')]);
    } catch(err) {}
    return true;
});