Created
June 21, 2013 14:44
-
-
Save phette23/5831653 to your computer and use it in GitHub Desktop.
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
(function ( $ ) { | |
// run after document is loaded so ga.js is available | |
$( document ).ready( setTracking ); | |
function setTracking () { | |
// class is specific to databases subject list | |
$( '.view-clone-of-databases-subject-list a' ).click( databaseTracking ); | |
} | |
function databaseTracking ( event ) { | |
var $this = $( this ), | |
destination = $this[ 0 ].href, | |
resource = destination | |
.replace( /(https?:\/\/info\.chesapeake\.edu\/lrc\/databases\/|https?:\/\/info\.chesapeake\.edu\/lrc\/library\/academic-databases\/)/i, "") | |
.replace( /-/g, ' '), | |
highlighted = $this.hasClass( 'ejp-highli' ) ? 1 : 0, | |
// move up from <a> to div.views-row, then back to <h2> section header | |
section = $this.parent().parent().parent().prevAll( 'h2' ).eq( 0 ).text(); | |
// console.log( [ '_trackEvent', 'database', resource, section, highlighted ] ); | |
_gaq.push( [ '_trackEvent', 'database', resource, section, highlighted ] ); | |
// delay navigation to ensure event is recorded | |
setTimeout( function () { | |
// open in new window if ctrl or cmd clicked | |
if ( event.metaKey || event.ctrlKey ) { | |
window.open( destination, '_blank', 'menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes' ); | |
} else { | |
window.location = destination; | |
} | |
}, 200 ); | |
event.preventDefault(); | |
} | |
}( jQuery )); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment