-
-
Save cgrymala/b058b585dc320b177dff to your computer and use it in GitHub Desktop.
Analytics Event Tracking for Helpful Links
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
// Track Helpful Links clicks | |
if ( jQuery( '#umw-help-center-content' ).length > 0 ) { | |
// Make sure we're only tracking actual links, not <a> tags with no href and not <a> tags with an href of "#" | |
jQuery( '#umw-help-center-content a[href!="#"]' ).each( function() { | |
var tmpAction = null; | |
// All labels will be set to the text found within the <a> tag | |
var tmpLabel = null; | |
// Set the event action as "Online Tools" for the icon links at the bottom | |
if ( jQuery( this ).closest( '.umw-help-center-tools' ).length > 0 ) { | |
tmpAction = 'Online Tools'; | |
tmpLabel = jQuery( this ).text(); | |
// Set the event action as "Resource Links" for any of the links in the main list of links | |
} else if ( jQuery( this ).closest( '.umw-help-center-panel' ).length > 0 ) { | |
tmpAction = 'Resource Links'; | |
tmpLabel = jQuery( this ).text(); | |
// Set the event action as "Other Helpful Links" for any links that fall outside of the other two areas | |
} else { | |
tmpAction = 'Other Helpful Links'; | |
tmpLabel = jQuery( this ).text(); | |
} | |
// Add some HTML attributes to store the values of our Analytics category, action and label for each element | |
jQuery( this ) | |
.attr( 'analytics-category', 'Helpful Links' ) | |
.attr( 'analytics-action', tmpAction ) | |
.attr( 'analytics-label', tmpLabel ); | |
// Set up the event tracking for the link; when someone clicks the link, it triggers the Analytics action, then proceeds with the link's intended action after 100 milliseconds | |
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; | |
} ); | |
} ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment