Shoora
10/26/2018 - 9:10 PM

simple way to track events in Google Analytics

simple way to track events in Google Analytics

function trackGAEvent(type, category, action, label, value) {
	/*
	category: Event Category
	label: Event Label
	action: Event Action
	value: optional
	*/
	if (typeof ga !== 'undefined') {
		if (typeof value === 'undefined') {
			ga('send', type, category, action, label);	
		} else {
			ga('send', type, category, action, label, value);
		}
	}
}

// example
$(document).ready(function() {
  $('#featured-nav a').click(function(e) {
		trackGAEvent('event', 'Featured Bar Link', 'Click', this.href);
	});
});