Automatically tracking outbound links in Google Analytics

Google Analytics supports a nifty feature called “Events”, which is designed to allow you to track non-pageview type events. This is particularly helpful if you have an AJAX type interface on which you want to gather statistics, but another use I’ve found handy is to track clicks on external links to other sites. If you’re using the asyncronous version of the tags (if not, why not), then you should have some code that uses the window._gaq variable. In order to track events aside from the initial page view, you simply need to call the following each time you want to record an event:

window._gaq.push(['_trackEvent','Event Category', 'Event Value']);

Using your favourite javascript library (mine are jQuery and Mootools), it’s easy to hook this up to automatically fire Google event tracking for any external hyperlinks on the site. We simply look for all a tags with href attributes that begin with “http://”. Then, if the href doesn’t contain our current hostname, then we assume it’s an external link. Obviously the logic could be adjusted for your particular needs!

Here’s the mootools version:

document.getElements('a[href^="http://"]').addEvent('click',function(link) {
  var href =;
  if(href.indexOf( < 0) {     window._gaq.push(['_trackEvent','Outbound Links', href]);   } });

Or for the jQuery fans amongst you, just swap the first line for:

$('a[href^="http://"]').bind('click',function(link) {

Now, after 24 hours or so, if you check out the "Event Tracking" page under "Content" in Google Analytics, you'll see an outbound link category listing all the external links clicked on the site (assuming Javascript is turned on, of course).

Side note: previous versions recommended by Google included a window.timeout before allowing the redirect to take place - in order to ensure the request to Google to record the click goes out first - as far as I can establish, this is no longer necessary.

Side note 2: By tracking outbound clicks this will affect your bounce rate figures. Essentially an event counts as another activity, so if a visitor lands on one page, and then clicks an external link, that will not count as a "bounce". Whether this is a fair reflection of bounces or not depends on your viewpoint - but something to bear in mind. Unfortunately there's currently no way to log an event that doesn't affect the bounce rate.

Google “panda” update – impact on small publishers

An open letter to Google.

I’ve been doing online publishing since 1999, across various successful websites, and have never knowingly been affected by any of your previous algorithm changes – sticking to the motto of great content, and optimizing for our user experience had so far done us well.

However, the Google “panda” algorithm changes being made over the last few weeks seem to have be far more wide reaching than any previously. I’m totally behind the goals you’ve stated to reduce the number of spam sites and content farms, but I’m sure I speak for a large number of publishers that we feel let down in the way this has been handled.

We are now consistently seeing exactly the kind of sites you claimed to want to punish, ripping off our content and ranking for our articles, while our original content is nowhere to be seen. I have talked to your PR team, contacted your search team, and all been given a standard response. We’ve posted in forums, filed reconsideration requests, and reported the people ripping our content off as spam. All with no effect.

I’ve no doubt that it was well within the technical realms of Google to establish which large, well established, high quality editorial sites would benefit and suffer – and so can only assume that a decision was made to press ahead regardless. While the really big publishers will no doubt survive, at the same time you are no doubt making or breaking thousands of small businesses across the web, who like it or not are dependent on traffic from Google, and yet have made every effort to produce genuine high quality original content for their audience.

Posting to Facebook Page using C# SDK from offline app

If you want to post to a facebook page using the Facebook Graph API and the Facebook C# SDK, from an “offline” app, there’s a few steps you should be aware of.

First, you need to get an access token that your windows service or app can permanently use. You can get this by visiting the following url (all on one line), replacing [ApiKey] with your applications Facebook API key.[ApiKey]&connect_display=popup&v=1.0

In the parameters of the URL you get redirected to, this will give you an access key. Note however, that this only gives you an access key to post to your own profile page. Next, you need to get a separate access key to post to the specific page you want to access. To do this, go to[YourUserId]/accounts?access_token=[AccessTokenFromAbove]

You can find your user id in the URL when you click on your profile image. On this page, you will then see a list of page IDs and corresponding access tokens for each facebook page. Using the appropriate pair,you can then use code like this:

var app = new Facebook.FacebookApp(_accessToken);
var parameters = new Dictionary
    { "message",  promotionInfo.TagLine },
    { "name" ,  promotionInfo.Title },
    { "description" ,  promotionInfo.Description },
    { "picture", promotionInfo.ImageUrl.ToString() },
    { "caption" ,  promotionInfo.TargetUrl.Host },
    { "link" ,  promotionInfo.TargetUrl.ToString() },
    { "type" , "link" },
app.Post(_targetId + "/feed", parameters);

And you’re done!

Search Engine Optimisation (SEO) Checklist

Search engine optimisation is pretty much part and parcel of creating websites these days. Getting the basics right don’t require a large amount of work, but can make all the difference. Many of these also improve the general usability and accessibility of your site too – so you get three major benefits rolled into one.

The points below are just a few basics I’ve picked up along the way; roughly in order of my own priority, relating specifically to technical changes you can make on your own site, regardless of any incoming links, frequency of page updates, or link building you may do; I’m not claiming this is a comprehensive list BY to, keyword, you, to, “Find, navigational, a,in,I’ve, high, possible. descriptions

These are often displayed in search engines if the keywords have matched a page title rather than its content – so they’re worth including even for this – and they still seem to be used for picking up relevant keywords too. Once again, the same points apply as in #1 – don’t just re-use the same standard page description across the entire site.

7. Deep linking

This is harking back to point #2. If you publish articles, press releases, or the like on your site, and it mentions a product, or another article on the site, then make sure it links to it! This increases the number of contextually relevant links and possible keywords that a search engine might associate your pages with, even if these links are just internal.

8. Use URL rewriting

There are loads of URL rewriting techniques out there. Sensible use of URLs increase the usability of your site, and also allows the search engines to pick up on keywords in your URL too. In order of improvement: (worst case) (at least give the page a meaningful name!) (search engines still don’t like query strings all that much)

The final example is logical, “hackable” (the user can guess that /products/chips/ will take them back to a sensible page), and keyword rich. Note that the URL of this blog entry follows these lines too!

9. Unknowns…

Things I’m not 100% sure about.

– Keywords meta tag. I’ve deliberately not mentioned this here, as I’ve seen no sign that these are being used any more.
– Order of content on the page. I always try to ensure that the main body of the content appears as high up the page as possible. This has accessibility benefits (so a screen reader doesn’t read the same set of navigation at the start every time a page loads), but I’m not sure how much weight a search engine places on this order, or how large the page has to be for this to make a difference.

I’d be interested to hear if anyone has suggestions of other must-do’s that I’ve missed.