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.
我一直在寻找一种使用Google Analytics跟踪AJAX请求的方法。我发现了很多关于它的文章。但是,所有这些都提供了类似这样的SO问题的解决方案。但这对我不起作用,一个月后,谷歌分析没有跟踪任何内容。
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.
更让我感到疑惑的是,这段代码根本无所作为。没有Ajax或任何其他请求将发送给谷歌。那么它如何运作?我真的希望至少发送请求或重新加载iframe。但似乎真的没有做任何事情。
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 ?
我做错了什么?
1 个解决方案
#1
0
This guideline helped me to solve the problem.
https://support.google.com/analytics/answer/1012264
该指南帮助我解决了这个问题。 https://support.google.com/analytics/answer/1012264
#1
0
This guideline helped me to solve the problem.
https://support.google.com/analytics/answer/1012264
该指南帮助我解决了这个问题。 https://support.google.com/analytics/answer/1012264