Shoora
9/27/2019 - 9:21 AM

Google Analytics Event Helper

Google Analytics Event Helper

//ga click helper
$('[data-tracking]').on('click', function(){
    var track_string = $(this).data('tracking').toLowerCase();
    if(!track_string){return false;}

    var track_arr = track_string.split(",");
    if(track_arr.length < 2){return false;}

    var category = track_arr[0];
    var action = track_arr[1];
    var label = track_arr[2];
    var value = track_arr[3];

	track(category,action,label,value);
});

//ga send helper
function track(category, action, label, value){
	ga('send', {
	    'hitType': 'event',
	    'eventCategory': category || "",
	    'eventAction': action || "",
	    'eventLabel': label || "",
	    'eventValue': value || ""
	});
}