Skip to content

Instantly share code, notes, and snippets.

@phette23
Created June 21, 2013 14:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save phette23/5831653 to your computer and use it in GitHub Desktop.
Save phette23/5831653 to your computer and use it in GitHub Desktop.
(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