Google Analytics and hash/anchor doesn't work

旧街凉风 提交于 2019-12-11 03:37:38

问题


I hope you can help me.

I have a gallery in Javascript. Each picture has a specific hash.

www.example.com/gallery.html#title_1

My stats are on Google Analytics but hash doesn't exist even when I tried this in the respective code :

_gaq.push(['_trackPageview', location.pathname + location.search  + location.hash]);

or this :

_gaq.push(['_setAllowAnchor', true]);

Any idea to solve this problem ?

Thanks for your answers.


回答1:


_setAllowAnchor is for a completely different use case.

The right way to do it is as you said:

_gaq.push(['_trackPageview', location.pathname + location.search  + location.hash]);

But you need to execute this after the hash has changed. I think you are executing this when the page loads. When the hash changes the page doesn't reload so you need to run this function call explicitly again.



来源:https://stackoverflow.com/questions/12538115/google-analytics-and-hash-anchor-doesnt-work

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