2
<script type="text/javascript">
    leaveSiteStart = new Date;
    function leftSite() {
        var leaveSiteEnd = (new Date - leaveSiteStart);
        var roundleaveSiteEnd = Math.round(leaveSiteEnd, 1);
        _gaq.push(['pageTrackerTime._trackEvent', 'Category', 'Action', document.getElementById('Name').value]);
    }
    window.onbeforeunload = leftSite;
</script>

我已经使用此代码来执行用户在关闭浏览器或退出页面之前在页面上花费的持续时间。

但它未能捕捉到事件......代码有什么问题吗?

4

2 回答 2

0

Because _gaq is an asynchronous call, the browser won't wait until the call is completed, so try to do some synchronous call.

In jQuery ajax you can do sync task by setting async flag to false, check if there is same way to do that.

于 2012-04-06T12:44:11.287 回答
0

在现代浏览器中,捕捉用户离开基本上是不可能的。回到FF4出来的时候,他们打破了使用定时while循环来暂停退出的方式。

于 2012-04-06T12:26:04.360 回答