Skip to content

Instantly share code, notes, and snippets.

@cgrymala
Created July 31, 2013 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cgrymala/afa6fc4e51d1685d2f57 to your computer and use it in GitHub Desktop.
Save cgrymala/afa6fc4e51d1685d2f57 to your computer and use it in GitHub Desktop.
UMW Analytics Event Tracking and Configuration
jQuery( function() {
if( typeof( _gaq ) === 'undefined' ) {
return;
}
_gaq.push(['pageTracker._setAllowAnchor',true]);
// Add cross-domain tracking to all internal links
jQuery('a').filter( function() {
return this.hostname != location.hostname && this.hostname in umw_internal_sites;
} ).attr( 'analytics-cross-domain', 'yes' ).click( function() {
if ( jQuery( this ).attr( 'target' ) ) {
window.open( jQuery(this).attr('href'), jQuery( this ).attr( 'target' ) );
} else {
_gaq.push(['_link', jQuery(this).attr('href'), true]);
}
return false;
} );
// Track Helpful Links clicks
if ( jQuery( '#umw-help-center-content' ).length > 0 ) {
jQuery( '#umw-help-center-content a[href!="#"]' ).each( function() {
var tmpAction = null;
var tmpLabel = null;
if ( jQuery( this ).closest( '.umw-help-center-tools' ).length > 0 ) {
tmpAction = 'Online Tools';
tmpLabel = jQuery( this ).text();
} else if ( jQuery( this ).closest( '.umw-help-center-panel' ).length > 0 ) {
tmpAction = 'Resource Links';
tmpLabel = jQuery( this ).text();
} else {
tmpAction = 'Other Helpful Links';
tmpLabel = jQuery( this ).text();
}
jQuery( this )
.attr( 'analytics-category', 'Helpful Links' )
.attr( 'analytics-action', tmpAction )
.attr( 'analytics-label', tmpLabel );
jQuery( this ).one( 'click', function() {
_gat._getTrackerByName()._trackEvent(
jQuery( this ).attr( 'analytics-category' ),
jQuery( this ).attr( 'analytics-action' ),
jQuery( this ).attr( 'analytics-label' ),
1,
true
);
setTimeout( 'document.location="' + jQuery( this ).attr( 'href' ) + '"', 100 );
return false;
} );
} );
}
// Track Footer Links clicks
if ( jQuery( '#footer' ).length > 0 ) {
jQuery( '#footer a[href!="#"]' ).each( function() {
var tmpAction = null;
var tmpLabel = null;
if ( jQuery( this ).closest( '.umw-viewbook' ).length > 0 ) {
tmpAction = 'Viewbook Link';
tmpLabel = jQuery( this ).closest( '.international-viewbook' ).length > 0 ? 'International Viewbook' : 'Standard Viewbook';
} else if ( jQuery( this ).closest( '#umw-footer-nav' ).length > 0 ) {
tmpAction = 'Mega Footer Navigation';
tmpLabel = jQuery( this ).text();
} else {
tmpAction = 'Global Footer Links';
tmpLabel = jQuery( this ).text();
}
jQuery( this )
.attr( 'analytics-category', 'Footer Links' )
.attr( 'analytics-action', tmpAction )
.attr( 'analytics-label', tmpLabel );
jQuery( this ).one( 'click', function() {
_gat._getTrackerByName()._trackEvent(
jQuery( this ).attr( 'analytics-category' ),
jQuery( this ).attr( 'analytics-action' ),
jQuery( this ).attr( 'analytics-label' ),
1,
true
);
setTimeout( 'document.location="' + jQuery( this ).attr( 'href' ) + '"', 100 );
return false;
} );
} );
}
// Track Header Links clicks
if ( jQuery( '#header #umw-subnav' ).length > 0 ) {
jQuery( '#header #umw-subnav a[href!="#"]' ).each( function() {
var tmpAction = 'Top-Level Header Navigation';
var tmpLabel = jQuery( this ).text();
jQuery( this )
.attr( 'analytics-category', 'Header Links' )
.attr( 'analytics-action', tmpAction )
.attr( 'analytics-label', tmpLabel );
jQuery( this ).one( 'click', function() {
_gat._getTrackerByName()._trackEvent(
jQuery( this ).attr( 'analytics-category' ),
jQuery( this ).attr( 'analytics-action' ),
jQuery( this ).attr( 'analytics-label' ),
1,
true
);
setTimeout( 'document.location="' + jQuery( this ).attr( 'href' ) + '"', 100 );
return false;
} );
} );
}
// Track other home page clicks
if ( jQuery( 'body.network-www.site-root.home' ).length > 0 ) {
jQuery( '#home-middle a[href!="#"]' ).each( function() {
var tmpAction = jQuery( this ).closest( '.widget' ).find( '.widgettitle' ).text();
var tmpLabel = jQuery( this ).text();
if ( tmpLabel == '' && jQuery( this ).find( 'img' ).length > 0 ) {
if ( jQuery( this ).closest( '.post' ).length > 0 ) {
tmpLabel = jQuery( this ).closest( '.post' ).find( 'h2' ).text();
} else {
tmpLabel = jQuery( this ).find( 'img' ).attr( 'alt' );
}
}
jQuery( this )
.attr( 'analytics-category', 'Home Page Links' )
.attr( 'analytics-action', tmpAction )
.attr( 'analytics-label', tmpLabel );
jQuery( this ).one( 'click', function() {
_gat._getTrackerByName()._trackEvent(
jQuery( this ).attr( 'analytics-category' ),
jQuery( this ).attr( 'analytics-action' ),
jQuery( this ).attr( 'analytics-label' ),
1,
true
);
setTimeout( 'document.location="' + jQuery( this ).attr( 'href' ) + '"', 100 );
return false;
} );
} );
}
// Track Common App clicks
jQuery( 'a[href*="commonapp.org"]' ).one( 'click', function() {
_gat._getTrackerByName()._trackEvent( 'Applications', 'CommonApp' );
setTimeout( 'document.location="' + jQuery(this).attr('href') + '"', 100 );
return false;
} );
} );
document.body.onload = function() {
jQuery( '.slides .slide' ).each( function() {
var tmpAction = jQuery( this ).find( 'h1' ).text();
var tmpLabel = 'Slide #' + jQuery( this ).index();
jQuery( this )
.attr( 'analytics-category', 'Home Page Slideshow' )
.attr( 'analytics-action', tmpAction )
.attr( 'analytics-label', tmpLabel );
jQuery( this ).find( 'a' ).one( 'click', function() {
_gat._getTrackerByName()._trackEvent(
jQuery( this ).closest( '.slide' ).attr( 'analytics-category' ),
jQuery( this ).closest( '.slide' ).attr( 'analytics-action' ),
jQuery( this ).closest( '.slide' ).attr( 'analytics-label' ),
1,
true
);
setTimeout( 'document.location="' + jQuery( this ).attr( 'href' ) + '"', 100 );
return false;
} );
} );
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment