是否有可能跟踪像谷歌分析页面哈希链接? [英] Is it possible to track hash links like pages with google analytics?

查看:102
本文介绍了是否有可能跟踪像谷歌分析页面哈希链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



例如,我想要index.php /#1,index.php /#2,和index.php /#3都显示为个别页面点击次数和个人页面花费时间。



如果没有简单的方法来做这件事,我该如何使用jquery将一个轨道事件添加到onclick事件中?我仍然可以通过这种方式获得页面信息的准确时间吗?

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

您可以将该代码绑定到每次在应用程序中进行哈希更改,或者可以使用通用hashchange插件,它使用HTML5 onhashchange,以及一些向后兼容的hacks for旧的浏览器,并将此代码绑定到该事件,以便每次散列更改时都会触发。



使用该插件,您的代码可能如下所示:

  $ (window).hashchange(function(){
_gaq.push(['_trackPageview',location.pathname + location.search + location.hash]);

})



2014年更新:

在新的Universal Analytics中,您可以这样做:

  ga('send ','pageview',{
'page':location.pathname + location.search + location.hash
});

如果您使用Google Analytics(分析)和Google跟踪代码管理器,就可以这么做:




  • 转至您的宏

  • 将URL宏更新为Fragment $ b

Is it possible to track hash links like pages with google analytics?

For example, I want index.php/#1, index.php/#2, and index.php/#3 to all show up as individual page hits with individual time spent on page.

If there is no simple way of doing this, how can I add a track event to an onclick event with jquery? Can I still receive accurate time on "page" information this way?

解决方案

Generically, your code could look like this

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

You could either bind that code to every time you have a hash change within your application, or you could use a generic hashchange plugin, that uses the HTML5 onhashchange, and some backwards compatible hacks for older browsers, and bind this code to that event, so that it fires every time your hash changes.

Using that plugin, your code could look like:

$(window).hashchange( function(){
    _gaq.push(['_trackPageview',location.pathname + location.search  + location.hash]);

})


UPDATE 2014:

This is how you'd do this in the new Universal Analytics:

ga('send', 'pageview', {
 'page': location.pathname + location.search  + location.hash
});

This is how you'd do it if you're using Google Analytics withing Google Tag Manager:

  • Go to your macros
  • Updated the URL Macro to "Fragment"

这篇关于是否有可能跟踪像谷歌分析页面哈希链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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