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! :-)

Trackbacks are closed, but you can post a comment

How do you rate this post?

1 Star2 Stars3 Stars4 Stars5 Stars (7 votes, average: 4.00 out of 5)
Loading ... Loading ...

More to say? Help SEOgadget by reviewing the site on Google - Thank you!

seperator

15 Comments

  1. July 14, 2008 at 10:38 am | Permalink

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

  2. July 14, 2008 at 10:59 am | Permalink

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

  3. July 15, 2008 at 6:53 pm | Permalink

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

  4. July 15, 2008 at 10:48 pm | Permalink

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

  5. July 15, 2008 at 11:30 pm | Permalink

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

  6. July 16, 2008 at 8:20 am | Permalink

    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! :-)

  7. October 2, 2008 at 6:19 pm | Permalink

    How to track links such as domain.com/wp-contents/upload in google analytics for WP site.

    I had posted an image link from my site reasonpad.com(link: http://reasonpad.com/wp-content/uploads/2008/10/septembermadnessb.jpg) to reddit and its in the front page. But Google Analytics is not tracking the visits to the link. I have downloaded the Google Analytics to my WP dashboard but did not help.

    Pls help.

    P{aul

  8. October 15, 2008 at 7:09 am | Permalink

    very useful articles…..I think seo off site more important and power full for geeting free traffic than seo on site, I already implemented for my web……so I am focus on off site optimisation…thanks

  9. October 15, 2008 at 7:10 am | Permalink

    Great post. Blogs are a very natural way to attract links. I’d love to see a post on how to get your company to blog. Particularly if you are dealing with a large, conservative company.

  10. October 20, 2008 at 10:24 am | Permalink

    Yes,a good idea.Because my webpage visit counter.

  11. April 7, 2009 at 1:12 pm | Permalink

    This is interesting idea, Now i am writing my advertisement script and count view and clicks. Super idea, thanks you too much for you my friends.

  12. April 26, 2009 at 9:03 pm | Permalink

    Great post. I was previously running urchin tracker and with the new Google Analytics code, it seemed to make sense to switch to Yoast.

    With your custom coding above, how long does it take to start reporting?

    Thanks!

  13. May 1, 2009 at 3:59 pm | Permalink

    @Darren – the reporting starts as soon as the code is in the page. Hope that helps!

  14. May 19, 2009 at 2:54 am | Permalink

    I spent hours trying to re-invent the wheel, – this is just what I was looking for. Thank you people for your hard work and for sharing this.
    GM

  15. May 21, 2009 at 9:35 pm | Permalink

    This is very useful, thanks for creating this post. I was about to start coding my own tracking and i am happy I found this info.
    Nikolai

One Trackback

  1. By Sphinn Weekly - Week 2 | The Sphinn Blog on July 21, 2008 at 11:02 pm

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

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*