Google Analytics not registering clicks

时光总嘲笑我的痴心妄想 提交于 2020-01-25 13:17:46

问题


I have a website that has some Google Analytics (GA) code and I wanted to track the downloads made to one file on my site, I googled for a while and found that if I added this code:

onClick="javascript: pageTracker._trackPageview('/descarga_programa_Mono');"

I could track the downloads by just looking at the "descarga_programa_Mono" that would appear on the GA dashboard, however I am not getting any results =/ is there something I'm missing?

My GA code is the newest one as far as I know the one that starts with:

var _gaq = _gaq || [];

and it's before the onClick script that I'm trying to use.


回答1:


Just to complement, if you want to make an virtual pageview in a specific button, you can do this way:

<a href="Link to Facebook"
onclick="_gaq.push(['_trackPageview', '/click/facebook/button', 'location.href']);">
<img src="myButtonName"></a>
//Using location.href, you will know in wich page the user was when he was redirected.

Any questions, just ask.




回答2:


By using onclick (all lowercase) the browser already understands you are using JavaScript. So that javascript: on your code is unnecessary. That would be necessary on the href attribute of an a tag.

That pageTracker object you have found is related to the SYNCHRONOUS ga version. NOT the one you are using. Use _gaq.push() instead as Bruno Brandão pointed out (although, on his example, there shouldnt be slashes around location.href).

The position (head or before body end) of the ga script does not matter as it is loaded and ran before the user can click something, independently.



来源:https://stackoverflow.com/questions/4600519/google-analytics-not-registering-clicks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!