<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"><channel><title>Morten Bock</title><link>http://www.mortenbock.dk/</link><description>A feed of new content on my website</description><item><author>Morten Bock</author><category>english</category><category>statistik</category><category>google-analytics</category><category>javascript</category><category>linktracking</category><description>
&lt;p&gt;I wanted to try and find a way to track all of the outgoing
links on my blog, without haven to modify the html of the link.
What I found was that using javascript listeners would probably be
the best solution. Actually this technique can be used for a lot of
stuff, but this is what I did:&lt;!--more--&gt;&lt;/p&gt;

&lt;pre&gt;
&amp;lt;script type="text/javascript"&amp;gt;
// Cross-browser implementation of element.addEventListener()
function addListener(element, type, expression, bubbling) {
    bubbling = bubbling || false;

    if (window.addEventListener) { // Standard
        element.addEventListener(type, expression, bubbling);
        return true;
    } else if (window.attachEvent) { // IE
        element.attachEvent('on' + type, expression);
        return true;
    } else return false;
}

//This is what i want to do whenever someone clicks on the page
function itHappened(evt) {

    //Get the clicket element
    var tg = (window.event) ? evt.srcElement : evt.target;
    //If it is an A element
    if (tg.nodeName == 'A') {
        //And it is not an internal link
        if (tg.href.indexOf(location.host) == -1) {
            //Replace all odd characters, so that it works with Analytics Niavgation analysis
            var url = tg.href.replace(/[^a-z|A-Z]/g, "_");

            var txt = tg.innerHTML.replace(/[^a-z|A-Z]/g, "_");
            var str = '/outgoinglink/-' + txt + '-' + url;
            try {
                //Track it
                urchinTracker(str);
            }
            catch (err) {
                //alert('error: ' + err);
            }
        }
    }
}
//Add the click listener to the document
addListener(document, 'click', itHappened);&amp;lt;/script&amp;gt;
&lt;/pre&gt;

&lt;p&gt;I hope you can use it. Any comments or advice is very welcome
:-)&lt;/p&gt;
</description><guid isPermaLink="false">1199</guid><link>http://www.mortenbock.dk/blog/2007/04/15/google-analytics-outgoing-links.aspx</link><pubDate>Sun, 15 Apr 2007 23:00:10 +0100</pubDate><title>Tracking all outgoing links with Google Analytics</title></item></channel></rss>
