[英]Insert variable into onClick event Google Analytics virtual pageview
I'm using js to get the URL of the current page which contains a hash mark because of AJAXs updates to the page 我正在使用js来获取当前页面的URL,该页面包含一个哈希标记,这是因为该页面的AJAX更新了
var hash = location.href;
A URL looks like http://www.example.com/#project1
URL看起来像
http://www.example.com/#project1
What I need is this Google virtual pageview code to display the hash variable path only where it says hash here
我需要的是此Google虚拟综合浏览量代码,以仅在
hash here
显示哈希的位置显示哈希变量路径
onClick="_gaq.push(['_trackPageview', 'hash here']);"
to look like onClick="_gaq.push(['_trackPageview', '/#project1']);"
看起来像
onClick="_gaq.push(['_trackPageview', '/#project1']);"
Thanks 谢谢
I think you're looking for location.hash
... 我认为您正在寻找
location.hash
...
function track() {
_gaq.push(['_trackPageview', location.hash]);
}
Do this: 做这个:
onClick="pushGA();"
function pushGA() {
_gaq.push(['_trackPageview', (window.location.path + window.location.hash)]);
}
Or: 要么:
onClick="pushGA();"
function pushGA(path) {
_gaq.push(['_trackPageview', ('/#'+window.location.hash)]);
}
Or: 要么:
onClick="pushGA('/#project');"
function pushGA(path) {
_gaq.push(['_trackPageview', path]);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.