I am trying to use GA user timings to track the duration of ajax events in our website. I have a centralized ajaxCall function that encapsulates the jQuery ajax call method. This seemed like an ideal place to put the timing for the calls since almost all of our ajax calls go through this method.
The problem that I'm having is that GA does not seem to be registering the timing hits.
Here's the code I'm using for my ajaxCall method:
function ajaxCall(url, data, fnSuccess, dataType, fnFailure)
{
if (!fnFailure)
{
fnFailure = function(jqXhr)
{
var lastDitchHtml = window.getCriticalErrorDialog("An error occurred during the ajax call.");
window.showCeebox(lastDitchHtml, 120, 350);
};
}
var a = $('<a>', { href : url })[0];
var startTime = getTimestampMilliseconds();
$.ajax({
cache : false,
async : false,
url : url,
type : 'POST',
dataType : dataType,
data : data,
success : fnSuccess,
error : fnFailure
});
var endTime = getTimestampMilliseconds();
var duration = endTime - startTime;
window.ga('send', 'timing', 'AjaxCall', a.pathname, duration);
}
Here is the code for the getTimestampMilliseconds method:
function getTimestampMilliseconds()
{
if (window.performance)
{
return window.performance.now();
}
else
{
return new Date().getTime();
}
}
I have tried the alternate syntax for the send using a javascript object for the options as follows:
window.ga('send', {
hitType : 'timing',
timingCategory : 'AjaxCall',
timingVar : a.pathname,
timingValue : duration});
and
window.ga('send', {
'hitType' : 'timing',
'timingCategory' : 'AjaxCall',
'timingVar' : a.pathname,
'timingValue' : duration});
I have verified that the beacon is getting sent to GA through the Chrome Google Analytics Debugger add-in and Fiddler. Fiddler shows that the request to GA returns a small image and a 200 OK result.
I have waited a full 24 hours for the results to show up and nothing.
I have verfied that pageviews and events track just fine, just not timing requests.
Any help would be greatly appreciated.
You've turned on the User-ID feature in your view settings but haven't configured it. User-ID tracking needs an additional code implementation and if it's not done, your Google Analytics view will contain no data.
Many of your reports and explorations can take 24-48 hours to process data from your website or app. You can use the Realtime and DebugView reports to confirm that you're collecting data from your website or app successfully.
Another reason why your Google Analytics is not working is that it might be conflicting with another script on your webpage. If you have other scripts running on your website, make sure they don't use the same variables as Google Analytics.
Processing latency is 24-48 hours. Standard accounts that send more than 200,000 sessions per day to Analytics will result in the reports being refreshed only once a day. This can delay updates to reports and metrics for up to two days.
Further investigation by one of my colleagues found the answer.
The getTimeStampMilliseconds function I wrote was returning a value with a fractional part (e.g., 450.98761), which apparently the Google API doesn't like. Complicating this was the fact that Google didn't return any kind of error code at all, leading us to think everything was ok.
Changing the code to pass only whole number of milliseconds in the timing call fixed the problem.
I struggled with the same issue for a few hours before I realized that my date range in Google Analytics page was ending a day before yesterday.
After changing it to today's date, all me recent test timings were displayed. I assumed that it was set to show recent timings by default and didn't check it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With