Google Analytics: How do I manually track clicks on outbound links?

So if you found this page then you are in luck, because you probably landed on this page first:

http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55527

And if you tried what is written on there, you know that it DOES NOT work. I still can’t figure out why Google offers that as their official advice when it clearly does not work. Here is why:

  1. Your link will redirect before Google finishes the logging call to their server.
  2. _trackPageview does not offer any callbacks, so there is no way to detect completion

Here is how I fixed the problem using jQuery, but you can do this with any JavaScript you want.

  1. _trackEvent has a callback so we are piggy-backing on it to log _trackPageview
  2. You can set the _trackEvent to whatever, I am just using what makes sense to me here
  3. Degrades nicely in case the user does not have JavaScript enabled.

Anyways — Enjoy, I hope this helps someone out there. If I am wrong, or if you know a better way to do this, please let me know!