This is the Image of analytics data 我正在使用Google的用户时间API跟踪我的网络应用程序的性能。我的javascript文件中包含以下代码,用于衡量请求的性能并将集合数据发送给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 ) );
}
}
我的逻辑确定来自对象的选择性AJAX请求,并测量该请求的性能并将集合数据发送到Google Analytics。
我的代码仅跟踪某些用户。例如,在使用该系统的300名销售代表中,它仅记录170名销售代表的这些数据。为什么不向其他用户报告。