-
-
Save cgrymala/6dac4610fb80dc77eabb to your computer and use it in GitHub Desktop.
Ensure proper cross-domain Analytics tracking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add 'external' CSS class to all external links | |
jQuery('a').filter( function() { | |
// Only take action when a link leads to a different domain than the one we're currently on, | |
// and that domain is in the list of internal sites | |
return this.hostname != location.hostname && this.hostname in umw_internal_sites; | |
} ).attr( 'analytics-cross-domain', 'yes' ).click( function() { | |
// If the link is supposed to open in a new window, let it do so | |
if ( jQuery( this ).attr( 'target' ) ) { | |
window.open( jQuery(this).attr('href'), jQuery( this ).attr( 'target' ) ); | |
// Otherwise, tell Analytics that this is a link to somewhere else on our site | |
} else { | |
_gaq.push(['_link', jQuery(this).attr('href'), true]); | |
} | |
// Stop the link from actually doing its job, since the script above will handle that | |
return false; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment