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/

相关文章:

java - 每个用户的 PHP 图像路径不同

javascript - 如何制作:hover appearance remain after click/focus in search bar

google-analytics - 如何通过管理API获取自定义数据源的自定义维度?

google-analytics - 事件跟踪不起作用

javascript - HTML 文档格式化,根据模式删除 <br>

javascript - 外部JS如何实际加载到html中?

javascript - 光滑的 slider 视频复制

javascript - 让 Sprockets 在不在 Rails/Rack 应用程序中时缩小 CSS/JS

javascript - 使用 render_template 重新渲染不起作用

google-analytics - 跟踪要购买的Google广告