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:
- Your link will redirect before Google finishes the logging call to their server.
- _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.
- _trackEvent has a callback so we are piggy-backing on it to log _trackPageview
- You can set the _trackEvent to whatever, I am just using what makes sense to me here
- 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!