javascript - 使用 Google Analytics 重定向页面

标签 javascript html google-analytics redirect

我有一个页面,使用此脚本将用户重定向到三个不同的页面:

<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/

相关文章:

javascript - 没有 jQuery 的委托(delegate)事件处理程序

html - 如何使用 CSS 设置 html/form 元素的样式?

javascript - Google Analytics ga.js 如何访问本地 JS 数组 _gaq?

javascript - Bootstrap 4 旋转木马 : Individual data-interval on each slide

php - 从 PHP 获取数据时出现 Angular 未处理的错误

google-analytics - 可能的Google Analytics(分析)错误-流量来源总访问次数与其他报告中的总访问次数不匹配

javascript - Google Analytics - 跟踪用户调查问卷分数

javascript - 是否可以将函数传递给 casper.evaluate()?

javascript - jQuery 动画scrollTop 上升然后返回

javascript - 如何正确处理 jQuery UI slider ?