This is the Image of analytics data I am tracking the performance of my web application using google's User Timing API. I have the following code in my javascript file which measures the performance of the request and send collective data to Google.
MyObject.analytics = function ( params, options ) {
var matchVal, group, startDate, trxId, startTime, totalTime, timingLbl,timingVble, order
gaTracking = {
"api/v1/cart?action1=add" : {
"timingCategory" : "Orders",
"timingVar" : "Cart",
"timingLabel" : "Add To Cart"
},
"api/v1/cart?action1=add&pagetype=deals" : {
"timingCategory" : "Orders",
"timingVar" : "Cart",
"timingLabel" : "Add To Cart Flex Deal"
},
"api/v1/cart" : {
"timingCategory" : "Orders",
"timingVar" : "Cart",
"timingLabel" : "Loading Cart Items"
},
"api/v1/cart?action1=complete" : {
"timingCategory" : "Orders",
"timingVar" : "Cart",
"timingLabel" : "Submit Order"
}
};
if(!!options.pageType) {
options.url += '&pagetype=' + options.pageType;
}
matchVal = _.filter(gaTracking, function (val, key) {
var bool = (key === options.url.toLowerCase()) ? true : false;
if(bool) {
group = val;
return true;
}
});
if(!!matchVal.length) {
return $.ajax( $.extend({
beforeSend: function ( xhr ) {
startDate = new Date();
startTime = new Date().getTime();
}
}, params, options ) ).done (function (data, textStatus, jqXHR) {
try {
order = Wave.Order.get();
if(group.timingVar === "Cart" && !!data[0] && !!data[0].CART && !!data[0].CART.TRX_ID) {
trxId = data[0].CART.TRX_ID;
timingVble = group.timingVar + '-' + trxId;
}
else if( !!order.TRX_ID ) { // This condition is check for filters because filters XML doesn't have TRX_ID
trxId = order.TRX_ID;
timingVble = group.timingVar + '-' + trxId;
}
else { timingVble = group.timingVar; }
//timingVble = startDate + '-' + timingVble;
timingLbl = (!!data[0].SEARCHTYPE) ? startDate + '-' + data[0].SEARCHTYPE : startDate + '-' + group.timingLabel;
totalTime = new Date().getTime() - startTime;
// for troubleshooting
var groupTest = { timingCategory: group.timingCategory, timingVar: timingVble, timingLabel: timingLbl};
console.log("Sending.. ", groupTest);
ga('send', 'timing', group.timingCategory, timingVble, totalTime, timingLbl);
}
catch (e) {
if ('console' in window && !!console.log) {
console.log('Google Analytics: ', e);
}
}
});
}
else {
return $.ajax( $.extend( params, options ) );
}
}
My logic determines selective AJAX request from an object and measures the performance for that request and send collective data to Analytics.
My code only tracks for certain users. For example out of 300 sales reps using the system it only records this data for 170 sales reps. Why is it not reporting for rest of the users.