Recording elapsed time of an AJAX call like a page view


#1

I’m trying to record the elapsed time of AJAX calls. I would like them to appear in my Pages list as the URL that I specify. I don’t see anything being recorded, but the call to trackPageView seems to run successfully.

The call to my ajaxRecordTime() method is made after the AJAX call returns from the server.

I’ve verified that the elapsed time, key (used for page URL and Document Title), and visitorId are all correct when I assign them to the Piwik object.

I don’t see any errors when trackPageView() is called, but I don’t see any entries in either my Piwik reports or even in the database.

So, what am I missing here?

Thanks.


function ajaxRecordTime() {

	var end = new Date().getTime();

	var key = window.sessionStorage.getItem("quickEntryRecorder_Key");
	var start = window.sessionStorage.getItem("quickEntryRecorder_StartTime");
	clearAjaxRecorder();

	if (key == null) {
		return;
	}

	if (start == null) {
		return;
	}

	var elapsedTime = end - start;

	if( typeof Piwik != "undefined" ) {

		var visitorId = '';
		if (typeof piwikVisitorId != "undefined") {
			visitorId = piwikVisitorId;
		}

		var piwikObj = Piwik.getTracker('https://monitor.ecbxyz.com/index.php', 55);
		piwikObj.setGenerationTimeMs(elapsedTime);
		piwikObj.setCustomUrl(key);
		piwikObj.setDocumentTitle(key);
		piwikObj.setUserId(visitorId);
		piwikObj.trackPageView();
	}
}