// Wrap it so if GA is not initialised it doesn't go 'undefined'!
function analytics_custom_event_tracker(name, event, label)
{
if (typeof ga === 'function')
{
return ga('send', 'event', name, event, label);
}
}
// Attach it to a standard JavaScript event listener
var clickMe = document.getElementById('click-me');
clickMe.addEventListener('change', function () {
// your code goodness
analytics_custom_event_tracker('Dans Event Listener', 'click', clickMe.value);
// Sending the value of element to Google Analytics on a click event with the name 'Dans Event Listener'
}, false);
// Attach it to a standard jQuery event listener
$('#click-me').on({
click: function () {
// the rest of your magic
analytics_custom_event_tracker('Dans Event Listener', 'click', $(this).val()));
// Sending the value of element to Google Analytics on a click event with the name 'Dans Event Listener'
}
});