Skip to content

Instantly share code, notes, and snippets.

@ethanhinson
Created August 30, 2013 23:03
Show Gist options
  • Save ethanhinson/6395125 to your computer and use it in GitHub Desktop.
Save ethanhinson/6395125 to your computer and use it in GitHub Desktop.
Easy cross domain tracking with jQuery
Drupal.behaviors.crossDomainTracking = {
attach: function(context, settings) {
//Catch all outgoing links for a specific domain
$('a[href*="mydomain.com"]').click(function() {
_gaq.push(['_link', this.href]);
return false;
});
// Add onSubmit _linkByPost to all <form> elements for a specific domain
$('form[action*="mydomain.com"]').attr('onSubmit','_gaq.push(["_linkByPost", this])');
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment