1

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.

Key
  • 9
  • 3
  • Your question is missing "the following code" referred to in the second sentence. My guess is that you are affected by the cap on timing hits (I'm pretty sure that affects user timings, too) that limits timing hits to the greater of 10,000 or 1% (https://developers.google.com/analytics/devguides/collection/ios/v3/limits-quotas#universal_properties) – Eike Pierstorff Mar 23 '16 at 15:39
  • Some adblockers and antivirus/firewalls will block google api requests. I've also had users in China that cannot access google at all. Just something to consider. – DavidA Mar 24 '16 at 18:15
  • @EikePierstorff I think that's the reason. How do I check on analytics hits per user. I saw the documentation and I believe its not recording extra hits. However I have to prove that to my client. Any suggestions? – Key Mar 28 '16 at 13:10
  • @DavidA That could be the case with some users. My all users are basically from United States. – Key Mar 28 '16 at 13:14
  • I have uploaded the image of analytics data in the first line. – Key Mar 28 '16 at 13:44

0 Answers0