Created
June 11, 2014 10:26
-
-
Save swmcc/eb21878d013fe5f632e9 to your computer and use it in GitHub Desktop.
GA Click Handler
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
// attach GA click handler | |
// note: the GA code is stored in a 'data-ga' element | |
// instead of inserting onclicks directly into the markup. | |
// <a data-ga="Event, Action, Label" | |
// id="mode-switch-devices" | |
// class="ajax" | |
// title="" | |
// href=""></a> | |
$('a').click(function(){ | |
if (typeof $(this).data('ga') === "undefined") { | |
if (logging == true) { | |
// Take attributes of the element and fire through instead | |
// of logging | |
console.warn('no data-ga for clicked element: ', $(this)); | |
} | |
} else { | |
var gaArray = $(this).data('ga').replace(/\s/g,'').split(','); | |
//console.log(gaArray); | |
_gaq.push(['_trackEvent', gaArray[0], gaArray[1], gaArray[2]]); | |
if (logging == true) { | |
console.log('fired GA: ', ['_trackEvent', gaArray[0], gaArray[1], gaArray[2]]); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment