Google Analytics和散列/定位符不起作用 [英] Google Analytics and hash/anchor doesn't work

查看:144
本文介绍了Google Analytics和散列/定位符不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望你能帮助我。

我有一个使用Javascript的画廊。
每张图片都有特定的散列。



www.example.com/gallery.html#title_1



我的统计信息位于Google Analytics(分析)中,但即使在各自的代码中尝试了这一点,哈希也不存在:

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

或此:

  _gaq.push(['_ setAllowAnchor',true]); 

解决这个问题的想法是什么?



感谢您的回答。

解决方案

_setAllowAnchor 是一个完全不同的用例。



正确的做法如您所说:

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

但是你需要在散列发生变化后执行它。我认为你正在执行这个页面加载时。当散列改变时页面不会重新加载,所以你需要再次显式运行这个函数。


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.

解决方案

_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.

这篇关于Google Analytics和散列/定位符不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆