SEOgadget - Richard Baxter's SEO, Ubuntu and geek stuff blog

How to count your outbound click stats with onclick in Google Analytics

11 July 2008

How to count your outbound click stats with onclick in Google Analytics

This evening I’ve set up my side bar “Find me on” links to track outbound clicks using a javascript onclick event. I’ve set this up mainly out of a curiousity to find out how much of my traffic exits via my Wordpress sidebar, and of course an interest in how this type of outbound link tracking works!

My post builds on a great article (and plugin) from Joost De Valk. His article, Checking your outbound click stats is a fantastic run through of how to use the Google Analytics “content drilldown” report to work out where you’re sending traffic (providing you’re tracking the clicks). If you’ve correctly installed his plugin, your comments, downloads, comment author link, article links and blogroll link clicks are all tracked automatically. Those outbound clicks should look like this:

content performance screen in Google Analytics

But what if, like me, you’ve created a bespoke sidebar, that isn’t quite dynamic enough to talk to a plugin like this? Basically, I’ve hard coded my sidebar links and I’d like to be able to track what exit clicks they’re generating.

Tracking your (hardcoded) sidebar link outbound clicks with a javascript onclick event

I’m going to use my “Find me on” links on the right hand side of this blog as the example. In short, I have worked through the HTML in this code and replaced the ordinary link anchor (<a href=) with the onclick event that will trigger the Google Analytics outbound link click tracking:

code example - ordinary html anchor image link

The first snippet of code is my Linkedin profile link. It’s an ordinary bit of code for an image that carries an outbound link in the HTML anchor.

Below is our next snippet. By using firebug in inspect mode, I grabbed the default onclick code from an outbound link from one of my recent articles and carefully replaced the href= url to the one I want to track. You will notice (If you look at an onclick in another article post on this blog) that I have changed the code “/outbound/article/” to “/outbound/sidebar”. This change will separate out click data coming from my sidebar - and will appear neatly in the content drilldown report above.

code example: java onclick outbound link click tracking

Finally, I need to update the first code snippet with this new onlick event. All that needs to be done here is replace the old HTML anchor link with this entire line of code:

Onclick tracking snippet intergrated with old HTML link anchor

This image link will now track just like the rest of the outbound links on my site. Take a look by inspecting the code in my sidebar with firebug. Enjoy! :-)

Add to Mixx!

7 Comments currently posted.

Joost de Valk says:

Good stuff! Guess you don’t mind if I reference this from my plugin page?

richardbaxterseo says:

Hi Joost, thanks for dropping by! I’d be honoured if you referenced this post from your plugin page!

OPENGIGA says:

cool stuffs and I like it. It will work for me …thanks.

richardbaxterseo says:

Hi there - really like your blog, I’ll add your feed right now. Great design, too.

Jaan Kanellis says:

Would this effect the SEO credit you get for outbound links?

richardbaxterseo says:

Hi Jaan,

That’s the great thing about onclick - as most crawlers don’t execute javascript, all they see is the <a href= part of the link. So, to answer your question, yes. I wrote a little more about this here - which includes an experiment I’m running to show that Google does not index this kind of onclick event. As of today, Google has still not indexed the tracking url encapsulated in in the “seogadget homepage” link.

Hope all this is useful - if you like the other post, give it a Sphinn! :-)

Sphinn Weekly - Week 2 | The Sphinn Blog says:

[...] as Google Analytics onclick tracking does not result in the spider following them. Direct Link: SEOGadget.co.uk Hat Tip: [...]

Post a comment on this entry: