Skip to content

Instantly share code, notes, and snippets.

@3n
Created April 30, 2010 21:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save 3n/385810 to your computer and use it in GitHub Desktop.
Save 3n/385810 to your computer and use it in GitHub Desktop.
// definition of trackEvent method on a global object
$3N = {
trackEvent : function(category, action, label, value){
if (typeof(pageTracker) == "object") pageTracker._trackEvent(category, action, label, value);
else if(typeof(_gaq) == "object") _gaq.push(['_trackEvent', category, action, label, value]);
}
};
// example of using trackEvent in my onerror helper (which you may also want to use)
window.onerror = function(msg, url, linenumber){
var handle_error = function(msg, url, linenumber) {
$3N.trackEvent(
"Error",
msg,
navigator.userAgent,
linenumber
);
};
if ($3N.dom_ready)
handle_error(msg, url, linenumber);
else
window.addEvent('domready', handle_error.bind(window, [msg, url, linenumber]));
};
window.addEvent('domready', function() { $3N.dom_ready = true; });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment