In a previous blog post, I went over how to track on-page events using Google Analytics. That post included a helper function called ga_event() that wrapped Google Analytics' method:
If you use GA, you're likely aware that they've switched tracking codes to Universal Analytics. The above code no longer works in Universal Analytics.
Thank goodness for ga_event()
The original function:
The new function, with Universal analytics support:
What the new bit of code does
In Drupal (or in regular PHP), the calluserfunc_array() function lets you pass an array as the arguments for the function being called through it. This is useful for the Drupal hook system, for things like access function overrides, and for general abstracting.
The conditional still means that the function does nothing if neither type of analytics is available. The second condition just does a basic check to ensure the Google Analytics function is available to call.
A rule of thumb
APIs change. Rather than relying on objects existing from external scripts, it is often advisable to abstract away such calls.