我有一个页面,使用此脚本将用户重定向到三个不同的页面:
<html>
<body>
</body>
<script src="jquery.js"></script>
<script>
$(document).ready(function (){
var redirected = false;
if(navigator.userAgent.toLowerCase().indexOf("android") > -1){
redirected = true;
console.log("hello andorid");
window.location.href = 'http://android.web.site.com';
}
if(navigator.userAgent.toLowerCase().indexOf("iphone") > -1){
redirected = true;
console.log("hello iphone");
window.location.href = "http://iphone.web.site.com";
}
if(navigator.userAgent.toLowerCase().indexOf("ipad") > -1){
redirected = true;
console.log("hello ipad");
window.location.href = "http://ipad.web.site.com";
}
if(navigator.userAgent.toLowerCase().indexOf("ipod") > -1){
redirected = true;
console.log("hello iphone");
window.location.href = "http://ipod.web.site";
}
else if(redirected==false){
console.log("hello windows");
window.location.href = "app.html";
}
});
</script>
</html>
因此它会检查用户是否使用手机。现在,客户想要跟踪有多少用户点击该页面,以及有多少用户登陆“app.html”页面。
我正在考虑在 <body>
中设置 Google 分析脚本标签。那是对的吗?我是否需要在重定向脚本上设置超时,以便 GA 有时间正确启动?
我对分析很陌生,我看过这个页面:https://support.google.com/analytics/answer/1009614?hl=en但我不知道这是否适合我。
感谢您的帮助。
最佳答案
这是一个很好的设置。您可以对每个 if 使用“if $(document).ready(function ()”,以确保在重定向之前将查询发送到 GA。这应该不需要添加烦人的延迟。希望它有所帮助!
关于javascript - 使用 Google Analytics 重定向页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30452760/