3 Options for Upgrading to the Asynchronous Google Analytics Tracker Code from the old pageTracker

I ran into an issue last night when I went to upgrade to the new Google Analytics asynchronous tracking code. It turns out that the pageTracker object no longer exists as a global variable.

Instead of using pageTracker._trackEvent(...) to track events, you must instead use _gaq.push(['_trackEvent', ...]).

There are three different options I could have chosen. I ended up choosing the last option.

1. Rewrite all my old pageTracker code to use the new syntax. I.e., change pageTracker._trackEvent(...) calls to _gaq.push(['_trackEvent', ...]);

2. Recreate the pageTracker (which I never verified if this code actually worked)

3. Create a wrapper.

This is the option I went with for one simple reason. I already use a variation of this code for logging tracking events when I debug on my localhost. Here is my full version.