使用谷歌分析处理哈希#的网址 [英] handle urls with hash # with google analytics

查看:92
本文介绍了使用谷歌分析处理哈希#的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用javascript客户端mvc(本例中为angular.js)的js单页web应用程序。

我将Google分析添加到网站,但从我目前看到的(至少在实时)谷歌并没有考虑到哈希后的部分uri



这是我有一个像 mydomain.com.ar /#/ ideas / 1 这样的网址,但对于谷歌分析来说,它看起来就像 mydomain.com.ar /

有什么想法?

解决方案

您需要解析#之后的参数,并通过使用_trackPageview发送数据,以便在您的网页上查看它们。



以下是如何操作,

var params = {},
queryString = location.hash.substring(1),
regex = /([^& =] +)=([^&] *)/ g,
m;
while(m = regex.exec(queryString)){
params [decodeURIComponent(m [1])] = decodeURIComponent(m [2]);
}
_gaq.push(['_ trackPageview',queryString]);


I'm developing a js single-page web application using a javascript client side mvc (angular.js in this case)

I added google analytic to the site, but from what I could see so far (at least in realtime) google doesn't take into account the part of the uri after the hash

that is I have a url like mydomain.com.ar/#/ideas/1 but for google analytics it looks just like mydomain.com.ar/

any idea?

解决方案

You need to parse the parameters after # and send the data by using _trackPageview in order to see them on your pages report.

and here is how to do it,

 var params = {},
     queryString = location.hash.substring(1), 
     regex = /([^&=]+)=([^&]*)/g, 
     m; 
 while (m = regex.exec(queryString)) { 
     params[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
 }
 _gaq.push(['_trackPageview', queryString]);

这篇关于使用谷歌分析处理哈希#的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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