Shoora
10/3/2018 - 4:28 PM

General event tracking for Google Universal Analytics

General event tracking for Google Universal Analytics

$('body').on('click', 'a, img, button', function(e) {
  var $el = $(e.target);

  if($el.data('event-count')) {
    $el.data('event-count', ($el.data('event-count') + 1));
  } else {
    $el.data('event-count', 1);
  }

  var category = e.target.nodeName;
  var action   = e.type;
  var label    = $el.data('event-label');
  var value    = $el.data('event-count');

  ga('send', 'event', category, action, label, value);

  return true;
});