I was looking for a way to track a AJAX requests using Google Analytics. I found a lot of articles about it. However, All of them were providing similar solution like this SO Question. But this is not working for me and after a month nothing has been tracked with Google Analytics.
What is more wondering to me is that this code simply do nothing. No Ajax or any other request will send to Google. So how it could work ? I really expect that do send request or reload an iframe at least. But it seems that really is not doing anything.
First I'm doing like this:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
_gaq.push(['_setDomainName', 'domain.com']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
And then in other place:
$.ajax({
'url' : 'ajax.php',
success: function(){
_gaq.push(["_trackPageview", "/search/"+keyword+"/"]);
}
});
I am doing something wrong ?