McDermottroe.com

Archive for March, 2009

Sheepvision

Friday, March 20th, 2009

Full marks to whoever decided to use sheep as a tool for advertising televisions. Just goes to show, ewe shouldn’t feel sheepish about bringing up left field ideas. :)

Google Analytics, jQuery and external links

Tuesday, March 10th, 2009

Want to add Google Analytics tracking to all the non-HTML resources on your site? How about the outbound links to other websites? If you’re like me, you’ve considered it and then rejected it for being too annoying to add the tracking code manually.

Time for jQuery to come to the rescue. By adding the tracking code automatically to the links that need it you can avoid the hassle of editing all of your existing pages.

$(document).ready(
    function () {
        $("a").click(
            function () {
                var protocol = this.protocol;
                var link = $(this).attr("href");
                if (link.substring(0, protocol.length) == protocol) {
                    pageTracker._trackPageview('/exit/' + escape(link));
                } else {
                    link = this.pathname;
                    if  (
                            (link.substring(link.length - 1) != "/") &&
                            (link.substring(link.length - 4) != ".php")
                        )
                    {
                        pageTracker._trackPageview(link);
                    }
                }
            }
        );
    }
);

The following caveats apply:

  1. You need to use the newer version of the Google Analytics tracking code (ga.js, not urchin.js)
  2. It assumes that all links pointing to a URL ending in / or .php have tracking code installed. If you have other readily identifiable URLs that you want to exclude then exclude them in the obvious place above.

Spot anything that looks wrong? Does this not work on your browser of choice? Let me know.

Blogging

Tuesday, March 10th, 2009

According to Larry Wall, there are three great virtues of a programmer: laziness, impatience and hubris. I seem to have a surplus of the first and so have resisted blogging for a long time. Maybe my impatience and hubris have overtaken the laziness.

This may be the first of many blog posts or I may give up after a few. Either way, enjoy it while it lasts.